Valiant::Validator::Inclusion - Value must be one of a list
package Local::Test::Inclusion; use Moo; use Valiant::Validations; has status => (is=>'ro'); has type => (is=>'ro'); validates status => ( inclusion => +{ in => [qw/active retired/], }, ); validates type => ( inclusion => +{ in => \&available_types, }, ); sub available_types { my $self = shift; return (qw(student instructor)); } my $object = Local::Test::Inclusion->new( status => 'running', type => 'janitor', ); $object->validate; warn $object->errors->_dump; $VAR1 = { 'status' => [ 'Status is not in the list' ], 'type' => [ 'Type is not in the list' ], };
Value must be one of a list. This list can be given as an arrayref or as a reference to a method (for when you need to dynamically build the list).
This validator supports the follow shortcut forms:
validates attribute => ( inclusion => [qw/a b c/], ... );
Which is the same as:
validates attribute => ( inclusion => +{ in => [qw/a b c/], }, );
This also works for the coderef form:
validates attribute => ( inclusion => \&coderef, ... ); validates attribute => ( inclusion => +{ in => \&coderef, }, );
This validator supports all the standard shared parameters: if, unless, message, strict, allow_undef, allow_blank.
if
unless
message
strict
allow_undef
allow_blank
Valiant, Valiant::Validator, Valiant::Validator::Each.
See Valiant
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.