Data::Validation - Filter and validate data values
Describes version v0.23.$Rev: 1 $ of Data::Validation
use Data::Validation; sub check_field { my ($self, $config, $id, $value) = @_; my $dv_obj = $self->_build_validation_obj( $config ); return $dv_obj->check_field( $id, $value ); } sub check_form { my ($self, $config, $form) = @_; my $dv_obj = $self->_build_validation_obj( $config ); my $prefix = $config->{form_name}.q(.); return $dv_obj->check_form( $prefix, $form ); } sub _build_validation_obj { my ($self, $config) = @_; return Data::Validation->new( { constraints => $config->{constraints} // {}, fields => $config->{fields} // {}, filters => $config->{filters} // {} } ); }
This module implements filters and common constraints in builtin methods and uses a factory pattern to implement an extensible list of external filters and constraints
Data values are filtered first before testing against the constraints. The filtered data values are returned if they conform to the constraints, otherwise an exception is thrown
Defines the following attributes;
constraints
Hash containing constraint attributes. Keys are the id values passed to "check_field". See Data::Validation::Constraints
id
fields
Hash containing field definitions. Keys are the id values passed to "check_field". Each field definition can contain a space separated list of filters to apply and a space separated list of constraints. Each constraint method must return true for the value to be accepted
filters
Hash containing filter attributes. Keys are the id values passed to "check_field". See Data::Validation::Filters
level
Positive integer defaults to 1. Used to select the stack frame from which to throw the check_field exception
check_field
$form = $dv->check_form( $prefix, $form );
Calls "check_field" for each of the keys in the form hash. In the calls to "check_field" the form keys have the prefix prepended to them to create the key to the fields hash
form
prefix
If one of the fields constraint names is compare, then the fields value is compared with the value for another field. The constraint attribute other_field determines which field to compare and the operator constraint attribute gives the comparison operator which defaults to eq
compare
other_field
operator
eq
All fields are checked. Multiple error objects are stored, if they occur, in the args attribute of the returned error object
args
$value = $dv->check_field( $id, $value );
Checks one value for conformance. The id is used as a key to the fields hash whose validate attribute contains the list of space separated constraint names. The value is tested against each constraint in turn. All tests must pass or the subroutine will use the EXCEPTION_CLASS class to throw an error
validate
EXCEPTION_CLASS
throw
None
OpenDNS. I have received reports that hosts configured to use OpenDNS fail the isValidHostname test. Apparently OpenDNS causes the core Perl function gethostbyname to return it's argument rather than undefined as per the documentation
isValidHostname
gethostbyname
There are no known bugs in this module. Please report problems to http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-Validation. Patches are welcome
Larry Wall - For the Perl programming language
Peter Flanigan, <pjfl@cpan.org>
<pjfl@cpan.org>
Copyright (c) 2016 Peter Flanigan. All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic
This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
To install Data::Validation, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Validation
CPAN shell
perl -MCPAN -e shell install Data::Validation
For more information on module installation, please visit the detailed CPAN module installation guide.