NAME
Valiant::Validator::Exclusion - Value cannot be in a list
SYNOPSIS
package Local::Test::Exclusion;
use Moo;
use Valiant::Validations;
has domain => (is=>'ro');
has country => (is=>'ro');
validates domain => (
exclusion => +{
in => [qw/org co/],
},
);
validates country => (
inclusion => +{
in => \&restricted,
},
);
sub restricted {
my $self = shift;
return (qw(usa uk));
}
my $object = Local::Test::Exclusion->new(
domain => 'org',
country => 'usa',
);
$object->validate;
warn $object->errors->_dump;
$VAR1 = {
'country' => [
'Country is reserved'
],
'domain' => [
'Domain is reserved'
]
};
DESCRIPTION
Value cannot be from a list of reserved values. Value can be given as either an arrayref or a coderef (which recieves the validating object as the first argument, so you can call methods for example).
If value is invalid uses the exclusion
translation tag (which you can override as an argument).
SHORTCUT FORM
This validator supports the follow shortcut forms:
validates attribute => ( exclusion => [qw/a b c/], ... );
Which is the same as:
validates attribute => (
exclusion => +{
in => [qw/a b c/],
},
);
This also works for the coderef form:
validates attribute => ( exclusion => \&coderef, ... );
validates attribute => (
exclusion => +{
in => \&coderef,
},
);
GLOBAL PARAMETERS
This validator supports all the standard shared parameters: if
, unless
, message
, strict
, allow_undef
, allow_blank
.
SEE ALSO
Valiant, Valiant::Validator, Valiant::Validator::Each.
AUTHOR
See Valiant
COPYRIGHT & LICENSE
See Valiant