FormValidator::Simple::Results(3pm)

FormValidator::Simple::Results3pm

Results of validation

Usage

    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";
            }
        }
    }

Overview

This is for handling resuls of FormValidator::Simple's check.

This object behaves like Data::FormValidator's results object, but has some specific methods.

Check result

has_missing

If there are missing values ( failed in validation 'NOT_BLANK' ), this method returns true.

    if ( $results->has_missing ) {
        ...
    }
has_invalid

If there are invalid values ( failed in some validations except 'NOT_BLANK' ), this method returns true.

    if ( $results->has_invalid ) {
        ...
    }
has_error

If there are missing or invalid values, this method returns true.

    if ( $results->has_error ) {
        ...
    }
success

inverse of has_error

    unless ( $resuls->success ) {
        ...
    }

Analyzing results

missing

no argument

When you call this method with no argument, it returns keys failed 'NOT_BLANK' validation.

    my $missings = $results->missing;
    foreach my $missing_data ( @$missings ) {
        print $missing_data, "\n";
    }
    # -- print out, for example --
    # name
    # email
key

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";
    }

invalid

no argument

When you call this method with no argument, it returns keys that failed some validation except 'NOT_BLANK'.

    my $invalids = $results->invalid;
    foreach my $invalid_data ( @$invalids ) {
        print $invalid_data, "\n";
    }
    # -- print out, for example --
    # name
    # email
key

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
key and validation-name

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";
    }

error

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";
    }

Releases

10 releases since Debian 4.0 (Etch); the text changed 6 times.

  1. 4.0
  2. 5.0
  3. 6.0
  4. 7–8
  5. 9–10
  6. 11
  7. 12–13

Author

Lyo Kato <[email protected]>

From libformvalidator-simple-perl 0.29-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.