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 there are missing values ( failed in validation '\s-1NOT_BLANK\s0' ), this method returns true. if ( $results->has_missing ) { ... }
If there are invalid values ( failed in some validations except '\s-1NOT_BLANK\s0' ), this method returns true. if ( $results->has_invalid ) { ... }
If there are missing or invalid values, this method returns true. if ( $results->has_error ) { ... }
inverse of has_error unless ( $resuls->success ) { ... }
When you call this method with no argument, it returns keys failed '\s-1NOT_BLANK\s0' validation. my $missings = $results->missing; foreach my $missing_data ( @$missings ) { print $missing_data, "\n"; } # -- print out, for example -- # name # email
When you call this method with key-name, it returnes true if the value of the key is missing. if ( $results->missing('name') ) { print "name is empty! \n"; }
When you call this method with no argument, it returns keys that failed some validation except '\s-1NOT_BLANK\s0'. my $invalids = $results->invalid; foreach my $invalid_data ( @$invalids ) { print $invalid_data, "\n"; } # -- print out, for example -- # name # email
When you call this method with key-name, it returns names of failed validation. my $failed_validations = $results->invalid('name'); foreach my $validation ( @$failed_validations ) { print $validation, "\n"; } # -- print out, for example -- # ASCII # LENGTH
When you call this method with key-name, it returns false if the value has passed the validation. 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 '\s-1NOT_BLANK\s0' 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"; }
FormValidator::Simple
Lyo Kato <[email protected]>
This library is free software. You can redistribute it and/or modify it under the same terms as perl itself.