Data::Validator::Recursive - recursive data friendly Data::Validator
use Data::Validator::Recursive; # create a new rule my $rule = Data::Validator::Recursive->new( foo => 'Str', bar => { isa => 'Int' }, baz => { isa => 'HashRef', # default rule => [ hoge => { isa => 'Str', optional => 1 }, fuga => 'Int', ], }, ); # input data for validation $input = { foo => 'hoge', bar => 1192, baz => { hoge => 'kamakura', fuga => 1185, }, }; # do validation my $params = $rule->validate($iput) or croak $rule->error->{message};
Data::Validator::Recursive is recursive data friendly Data::Validator.
You are creates the validation rules contain NoThrow as default.
NoThrow
new($arg_name => $rule [, ... ]) : Data::Validator::Recursive
Create a validation rule.
my $rule = Data::Validator::Recursive->new( foo => 'Str', bar => { isa => 'Int' }, baz => { rule => [ hoge => { isa => 'Str', optional => 1 }, fuga => 'Int', ], }, );
$rule's attributes is Data::Validator compatible, And additional attributes as follows:
rule => $rule : Array | Hash | Data::Validator::Recursive | Data::Validator
You can defined a $rule recursively to rule.
For example:
my $rule = Data::Validator::Recursive->new( foo => { rule => [ bar => { baz => [ rule => ... ], }, ], } );
with => $extention : Str | Array
Applies $extention to this rule.
See also Data::Validator.
with(@extentions)
Applies @extention to this rule.
validate(@args) : \%hash | undef
Validates @args and returns a restricted HASH reference, But return undefined value if there found invalid parameters.
my $params = $rule->validate(@args) or croak $rule->error->{message};
has_errors() : Bool
Return true if there is an error.
$rule->validate($params); if ($rule->has_errors) { ... }
errors() : \@errors | undef
Returns last error datum or undefined value.
my $errors = $rule->errors; # $error = [ # { # name => 'xxx', # type => 'xxx', # message => 'xxx', # }, # { ... }, # ... # ]
error() : \%error | undef
Returns last first error data or undefined value.
my $error = $rule->error; # $error = $rule->errors->[0]
clear_errors : \@errors | undef
Clear last errors after return last errors or undefined value.
my $errors = $rule->clear_errors; say $rule->has_errors; # 0
Yuji Shimada <xaicron {@} GMAIL.COM>
punytan
Copyright 2013 - Yuji Shimada
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Data::Validator
To install Data::Validator::Recursive, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Validator::Recursive
CPAN shell
perl -MCPAN -e shell install Data::Validator::Recursive
For more information on module installation, please visit the detailed CPAN module installation guide.