NAME

Valiant::Validator::Length - Validate the length of an attributes string value

SYNOPSIS

    package Local::Test::Length;

    use Moo;
    use Valiant::Validations;

    has name => (is=>'ro');
    has equals => (is=>'ro', required=>1, default=>5);

    validates name => (
      length => {
        maximum => 10,
        minimum => 3,
        is => sub { shift->equals }, 
      }
    );

    my $object = Local::Test::Length->new(name=>'Li');
    $object->validate; # Returns false

    warn $object->errors->_dump;

    $VAR1 = {
      'name' => [
        'Name is too short (minimum is 3 characters',
        'Name is the wrong length (should be 5 characters)',
      ]
    };

DESCRIPTION

Validates the length of a scalar, usually a string. Supports a number of constraint parameters that allow you to place various limits on this length (like many other validators the value of the constraints can be a constant or a coderef that gets the object instances as an argument). You also have parameters to override the default error for each constraint (these arguments match the tag name).

CONSTRAINTS

This validator supports the following constraints.

maximum

Accepts numeric value or coderef. Returns error message tag too_long if the attribute length exceeds the value.

minimum

Accepts numeric value or coderef. Returns error message tag too_short if the attribute length is smaller than the value.

in

Accepts an arrayref where the first item is a minimum length and the second item is a maximum lenth or coderef that returns such an arrayref. Returns error message of either too_short or too_long if the value length is outside the range specified.

is

Accepts numeric value or coderef. Returns error message tag wrong_length if the attribute value equal to the check value.

SHORTCUT FORM

This validator supports the follow shortcut forms:

    validates attribute => ( length => [1, 10], ... );

Which is the same as:

    validates attribute => (
      length => {
        in => [1, 10],
      },
    );
 

GLOBAL PARAMETERS

This validator supports all the standard shared parameters: if, unless, message, strict, allow_undef, allow_blank.

AUTHOR

John Napiorkowski email:jjnapiork@cpan.org

SEE ALSO

Valiant, Valiant::Validator, Valiant::Validator::Each.

COPYRIGHT & LICENSE

Copyright 2020, John Napiorkowski email:jjnapiork@cpan.org

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

3 POD Errors

The following errors were encountered while parsing the POD:

Around line 111:

Deleting unknown formatting code V<>

Around line 116:

Deleting unknown formatting code V<>

Around line 127:

Deleting unknown formatting code V<>