Peter Flanigan > Data-Validation > Data::Validation::Constraints

Download:
data-validation/Data-Validation-0.18.1.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

Open  0
View/Report Bugs
Module Version: v0.18.1   Source  

Name ^

Data::Validation::Constraints - Test data values for conformance with constraints

Synopsis ^

   use Data::Validation::Constraints;

   %config = ( method => $method, %{ $self->constraints->{ $id } || {} } );

   $constraint_ref = Data::Validation::Constraints->new( %config );

   $constraint_ref->validate( $value );

Description ^

Tests a single data value for conformance with a constraint

Configuration and Environment ^

Uses the Moo::Role Data::Validation::Utils. Defines the following attributes:

error

A string containing the error message that is thrown if the validation fails

max_length

Used by "isValidLength". The length of the supplied value must be numerically less than this

max_value

Used by "isBetweenValues".

min_length

Used by "isValidLength".

min_value

Used by "isBetweenValues".

required

If true then null values are not allowed regardless of what other validation would be done

value

Used by the "isEqualTo" method as the other value in the comparison

Subroutines/Methods ^

validate

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

Should have been overridden in an external constraint subclass

isBetweenValues

Test to see if the supplied value is numerically greater than $self->min_value and less than $self->max_value

isEqualTo

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

isMandatory

Null values are not allowed

isMatchingRegex

Does the supplied value match $self->pattern?

isPrintable

Is the supplied value entirely composed of printable characters?

isSimpleText

Simple text is defined as matching the pattern '\A [a-zA-Z0-9_ \-\.]+ \z'

isValidHostname

Calls gethostbyname on the supplied value

isValidIdentifier

Identifiers must match the pattern '\A [a-zA-Z_] \w* \z'

isValidInteger

Tests to see if the supplied value is an integer

isValidLength

Tests to see if the length of the supplied value is greater than $self->min_length and less than $self->max_length

isValidNumber

Return true if the supplied value looks_like_number

External Constraints ^

Each of these constraint subclasses implements the required _validate method

Date

If the str2time method in the CatalystX::Usul::Class::Time module can parse the supplied value then it is deemed to be a valid date

Email

If the address method in the Email::Valid module can parse the supplied value then it is deemed to be a valid email address

Password

Currently implements a minimum password length of six characters and that the password contain at least one non alphabetic character

Path

Screen out these characters: ; & * { } and space

Postcode

Tests to see if the supplied value matches one of the approved patterns for a valid postcode

URL

Call the request method in LWP::UserAgent to test if a URL is accessible

Diagnostics ^

None

Dependencies ^

charnames
Moo
Regexp::Common
Unexpected::Types

Incompatibilities ^

There are no known incompatibilities in this module

Bugs and Limitations ^

There is no POD coverage test because the subclasses docs are in here instead

The Data::Validation::Constraints::Date module requires the module CatalystX::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

Author ^

Peter Flanigan, <pjfl@cpan.org>

License and Copyright ^

Copyright (c) 2013 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

syntax highlighting: