Data::Validation::Constraints - Test data values for conformance with constraints
use Data::Validation::Constraints; %config = ( method => $method, %{ $self->constraints->{ $id } || {} } ); $constraint_ref = Data::Validation::Constraints->new_from_method( %config ); $bool = $constraint_ref->validate( $value );
Tests a single data value for conformance with a constraint
Defines the following attributes:
allowed
An array reference of permitted values used by "isAllowed"
max_length
Used by "isValidLength". The length of the supplied value must be numerically less than this
max_value
Used by "isBetweenValues".
method
Name of the constraint to apply. Required
min_length
Used by "isValidLength".
min_value
pattern
Used by "isMathchingRegex" as the pattern to match the supplied value against
required
If true then undefined values are not allowed regardless of what other validation would be done
type
If isMatchingType matches against this value
isMatchingType
type_libraries
A list of type libraries to add to the registry. Defaults to; Unexpected::Types
type_registry
Lazily evaluated instance of Type::Registry to which the type_libraries have been added
value
Used by the "isEqualTo" method as the other value in the comparison
A class method which implements a factory pattern using the method attribute to select the subclass
Called by Data::Validation::check_field this method implements tests for a null input value so that individual validation methods don't have to. It calls either a built in validation method or validate which should have been overridden in a factory subclass. An exception is thrown if the data value is not acceptable
validate
Is the the value in the $self->allowed list of values
$self->allowed
Test to see if the supplied value is numerically greater than $self->min_value and less than $self->max_value
$self->min_value
$self->max_value
Test to see if the supplied value is equal to $self->value. Calls isValidNumber on both values to determine the type of comparison to perform
$self->value
isValidNumber
Tests to see if the value matches the regular expression for a hexadecimal number
Undefined and null values are not allowed
Does the supplied value match the pattern? The pattern defaults to $self->pattern
$self->pattern
Does the supplied value pass the type constraint check? The constraint defaults to $self->type
$self->type
Is the supplied value entirely composed of printable characters?
Simple text is defined as matching the pattern '\A [a-zA-Z0-9_ \-\.]+ \z'
Calls gethostbyname on the supplied value
gethostbyname
Identifiers must match the pattern '\A [a-zA-Z_] \w* \z'
Tests to see if the supplied value is an integer
Tests to see if the length of the supplied value is greater than $self->min_length and less than $self->max_length
$self->min_length
$self->max_length
Return true if the supplied value looks_like_number
looks_like_number
Text is defined as any string matching the pattern '\A [ !%&\(\)\*\+\,\-\./0-9:;=\?@A-Z\[\]_a-z\|\~]+ \z'
Matches against a the pattern '\A \d\d : \d\d (?: : \d\d )? \z'
Each of these constraint subclasses implements the required validate method
If the str2time method in the Class::Usul::Time module can parse the supplied value then it is deemed to be a valid date
str2time
If the address method in the Email::Valid module can parse the supplied value then it is deemed to be a valid email address
address
Currently implements a minimum password length of six characters and that the password contain at least one non alphabetic character
Screen out these characters: ; & * { } and space
Tests to see if the supplied value matches one of the approved patterns for a valid postcode
Call the request method in HTTP::Tiny to test if a URL is accessible
request
None
There are no known incompatibilities in this module
There is no POD coverage test because the subclasses docs are in here instead
The Data::Validation::Constraints::Date module requires the module Class::Usul::Time and this is not listed as prerequisite as it would create a circular dependency
Please report problems to the address below. Patches are welcome
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.