| Form-Sensible documentation | view source | Contained in the Form-Sensible distribution. |
Form::Sensible::Validator - Default Validator for Form::Sensible forms
use Form::Sensible::Validator;
my $object = Form::Sensible::Validator->new();
$validator_result = $object->validate($form);
Form::Sensible::Validator performs the grunt work of validating a form. It
understands how to handle regex based field validation as well as
coderef based field validation. It also is responsible for calling
field-type specific validation. Usually this class is not manipulated
directly. Instead, $form->validate() is used, which in turn calls
the validator already associated with the form (or creates one if none is
already defined).
validate($form) Performs validation of a Form. Returns a Form::Sensible::Validator::Result object with the results of form validation for the passed form.
validate_field($field) Performs complete validation on the given field. Returns an array of
hashes containing error messaging (or an empty array on success.) Each hash
returned will contain a key of either 'error' or 'missing' and
a value containing the error message.
validate_field_with_regex($field, $regex)Internal routine to perform regex based validation of a field.
validate_field_with_coderef($field, $coderef)Internal routine to perform code based validation of a field. When called, the
$coderef is called with the field's value as the first argument, and the
field itself as the second:
$coderef->($field_value, $field);
The subroutine is expected to return 0 on successful validation, or an
appropriate error message on failed validation. This may seem somewhat
confusing, returning 0 on a valid field. It may help to think of the coderef
as being the equivalent of a is_field_invalid() routine.
The message_delegate is used to assemble error and other validation related
messages. By default the message_delegate simply loads $message and replaces
any occurance of _FIELDNAME_ with the field's name. Should return the processed
message. This is an ideal place to handle localization of messages or other
customization. If no translation can be found, you are strongly encouraged
to return the message as is (with _FIELDNAME_ converted to the actual field
name, of course.)
Jay Kuri - <jayk@cpan.org>
Ionzero LLC. http://ionzero.com/
Copyright 2009 by Jay Kuri <jayk@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Form-Sensible documentation | view source | Contained in the Form-Sensible distribution. |