The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Input::Validator::Field - Field object

SYNOPSIS

    $validator->field('foo');
    $validator->field(qw/foo bar/);
    $validator->field([qw/foo bar baz/]);

DESCRIPTION

Field object. Used internally.

ATTRIBUTES

messages

Error messages.

deflate

    $field->deflate(sub { s/foo/bar/ });

Use this when you want to change value of field after validation.

error

    $field->error('Invalid input');
    my $error = $field->error;

Field error.

each

    $field->each(sub { shift->required(1) });

Each method as described in Input::Validator::Bulk. Added here for convenience.

inflate

    $field->inflate(sub { s/foo/bar/ });

Use this when you want to change value of field before validation.

multiple

    $field->multiple(1);

Field can have multiple values. Use this when you want to allow array reference as a value.

    $field->multiple(2, 5);

If you want to control how many multiple values there can be set min and max values.

    $field->multiple(10);

When max value is omitted and is not 1 (because it doesn't make sense), number of values must be equal to this value.

name

    $field->name('foo');
    my $name = $field->name;

Field's name.

required

    $field->required(1);

Whether field is required or not. See Input::Validator documentation what is an empty field.

trim

    $field->trim(1);

Whether field's value should be trimmed before validation. It is ON by default.

METHODS

callback

Shortcut

    $field->constraint(callback => sub { ... });

clear_error

    $field->clear_value;

Clears field's error.

clear_value

    $field->clear_value;

Clears field's value.

constraint

    $field->constraint(length => [1, 2]);

Adds a new field's constraint.

is_defined

    my $defined = $field->is_defined;

Checks whether field's value is defined.

is_empty

    my $empty = $field->is_empty;

Checks whether field's value is empty.

is_valid

Checks whether all field's constraints are valid.

message

Holds error message.

value

    my $value = $field->value;
    $field->value('foo')

Set or get field's value.

SEE ALSO

Input::Validator, Input::Validator::Constraint.