NAME
Data::Verifier - Profile based data verification with Moose type constraints.
SYNOPSIS
Data::Verifier allows you verify data (such as web forms, which was the original idea) by leveraging the power of Moose's type constraint system.
use Data::Verifier;
my $dv = Data::Verifier->new(
filters => [ qw(trim) ]
profile => {
name => {
required => 1,
type => 'Str',
filters => [ qw(collapse) ]
}
age => {
type => 'Int';
},
sign => {
required => 1,
type => 'Str'
}
}
);
my $results = $dv->verify({
name => 'Cory', age => 'foobar'
});
$results->success; # no
$results->is_invalid('name'); # no
$results->is_invalid('age'); # yes
$results->is_missing('name'); # no
$results->is_missing('sign'); # yes
$results->get_value('name'); # Filtered, valid value
$results->get_value('age'); # undefined, as it's invalid
MOTIVATION
Data::Verifier firstly intends to leverage Moose's type constraint system, which is significantly more powerful than anything I could create for the purposes of this module. Secondly it aims to keep a fairly simple interface by leveraging the aforementioned type system to keep options to a minumum.
WARNING
This module is under very active development and, while the current API will likely not be changed, features will be added rapidly.
ATTRIBUTES
filters
An optional arrayref of filter names through which all values will be passed.
profile
The profile is a hashref. Each value you'd like to verify is a key. The values specify all the options to use with the field. The available options are:
- coerce
-
If true then the value will be given an opportunity to coerce via Moose's type system.
- dependent
-
Allows a set of fields to be specifid as dependents of this one. The argument for this key is a full-fledged profile as you would give to the profile key:
my $verifier = Data::Verifier->new( profile => { password => { dependent => { password2 => { required => 1, } } } } );
In the above example
password
is not required. If it is provided then password2 must also be provided. If any depedents of a field are missing or invalid then that field is invalid. In our example if password is provided and password2 is missing then password will be invalid. - filters
-
An optional list of filters through which this specific value will be run. See the documentation for Data::Verifier::Filters to learn more. This value may be either a string or an arrayref of strings.
- max_length
-
An optional length which the value may not exceed.
- min_length
-
An optional length which the value may not be less.
- required
-
Determines if this field is required for verification.
- type
-
The name of the Moose type constraint to use with verifying this field's value.
AUTHOR
Cory G Watson, <gphat at cpan.org>
COPYRIGHT & LICENSE
Copyright 2009 Cold Hard Code, LLC
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.