Valiant::Validator::Length - Validate the length of an attributes string value
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)', ] };
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).
This validator supports the following constraints.
Accepts numeric value or coderef. Returns error message tag too_long if the attribute length exceeds the value.
Accepts numeric value or coderef. Returns error message tag too_short if the attribute length is smaller than the value.
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.
too_short
too_long
Accepts numeric value or coderef. Returns error message tag wrong_length if the attribute value equal to the check value.
This validator supports the follow shortcut forms:
validates attribute => ( length => [1, 10], ... );
Which is the same as:
validates attribute => ( length => { in => [1, 10], }, );
This validator supports all the standard shared parameters: if, unless, message, strict, allow_undef, allow_blank.
if
unless
message
strict
allow_undef
allow_blank
John Napiorkowski email:jjnapiork@cpan.org
Valiant, Valiant::Validator, Valiant::Validator::Each.
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:
Deleting unknown formatting code V<>
To install Valiant, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Valiant
CPAN shell
perl -MCPAN -e shell install Valiant
For more information on module installation, please visit the detailed CPAN module installation guide.