Peter Flanigan > Data-Validation > Data::Validation

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

Dependencies

Annotate this POD

CPAN RT

Open  0
Report a bug
Module Version: 0.4.114   Source  

Name ^

Data::Validation - Filter and check data values

Version ^

0.4.$Rev: 114 $

Synopsis ^

   use Data::Validation;

   sub check_field {
      my ($self, $stash, $id, $value) = @_;
      my $config = { exception   => q(Exception::Class),
                     constraints => $stash->{constraints} || {},
                     fields      => $stash->{fields}      || {},
                     filters     => $stash->{filters}     || {} };
      my $dv = eval { Data::Validation->new( %{ $config } ) };

      $self->throw( $EVAL_ERROR ) if ($EVAL_ERROR);

      return $dv->check_field( $id, $value );
   }

   sub check_form  {
      my ($self, $stash, $form) = @_;
      my $config = { exception   => q(Exception::Class),
                     constraints => $stash->{constraints} || {},
                     fields      => $stash->{fields}      || {},
                     filters     => $stash->{filters}     || {} };
      my $dv = eval { Data::Validation->new( %{ $config } ) };

      $self->throw( $EVAL_ERROR ) if ($EVAL_ERROR);

      return $dv->check_form( $stash->{form_prefix}, $form );
   }

Description ^

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

Configuration and Environment ^

The following are passed to the constructor

exception

Class capable of throwing an exception. Should provide an args attribute

constraints

Hash containing constraint attributes. Keys are the $id values passed to "check_field". See Data::Validation::Constraints

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

operators

Hash containing operator code refs. The keys of the hash ref are comparison operators and their values are the anonymous code refs that compare the operands and return a boolean. Used by the compare form validation method

Subroutines/Methods ^

check_form

   $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

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

check_field

   $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 to throw an error

Diagnostics ^

None

Dependencies ^

Moose
Data::Validation::Constraints
Data::Validation::Filters
List::Util

Incompatibilities ^

There are no known incompatibilities in this module

Bugs and Limitations ^

There are no known bugs in this module. Please report problems to the address below. Patches are welcome

Author ^

Peter Flanigan, <Support at RoxSoft.co.uk>

License and Copyright ^

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