| FormValidator::Simple::Results - results of validation |
FormValidator::Simple::Results - results of validation
my $results = FormValidator::Simple->check( $req => [
name => [qw/NOT_BLANK ASCII/, [qw/LENGTH 0 10/] ],
email => [qw/NOT_BLANK EMAIL_LOOSE/, [qw/LENGTH 0 30/] ],
] );
if ( $results->has_error ) {
foreach my $key ( @{ $results->error() } ) {
foreach my $type ( @{ $results->erorr($key) } ) {
print "invalid: $key - $type \n";
}
}
}
This is for handling resuls of FormValidator::Simple's check.
This object behaves like Data::FormValidator's results object, but has some specific methods.
if ( $results->has_missing ) {
...
}
if ( $results->has_invalid ) {
...
}
if ( $results->has_error ) {
...
}
unless ( $resuls->success ) {
...
}
my $missings = $results->missing;
foreach my $missing_data ( @$missings ) {
print $missing_data, "\n";
}
# -- print out, for example --
# name
# email
if ( $results->missing('name') ) {
print "name is empty! \n";
}
my $invalids = $results->invalid;
foreach my $invalid_data ( @$invalids ) {
print $invalid_data, "\n";
}
# -- print out, for example --
# name
# email
my $failed_validations = $results->invalid('name');
foreach my $validation ( @$failed_validations ) {
print $validation, "\n";
}
# -- print out, for example --
# ASCII
# LENGTH
if ( $results->invalid( name => 'LENGTH' ) ) {
print "name is wrong length! \n";
}
This doesn't distinguish 'missing' and 'invalid'. You can use this like 'invalid' method, but this consider 'NOT_BLANK' same as other validations.
my $error_keys = $results->error;
my $failed_validation = $resuls->error('name');
# this includes 'NOT_BLANK'
if ( $results->error( name => 'NOT_BLANK' ) ) {
print "name is missing! \n";
}
if ( $results->error( name => 'ASCII' ) ) {
print "name should be ascii code! \n";
}
the FormValidator::Simple manpage
Lyo Kato <lyo.kato@gmail.com>
This library is free software. You can redistribute it and/or modify it under the same terms as perl itself.
| FormValidator::Simple::Results - results of validation |