NAME

Valiant::Validator::Inclusion - Value must be one of a list

SYNOPSIS

    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'
                ],
    };

DESCRIPTION

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).

SHORTCUT FORM

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,
      },
    );

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