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

NAME

Form::Tiny::FieldDefinition - a class representing field to be validated

SYNOPSIS

        # you usually don't have to do this by hand, see examples in Form::Tiny::Manual
        # name is the only required attribute
        my $definition = Form::Tiny::FieldDefinition->new(
                name => "something",
                ...
        );

DESCRIPTION

Main class of the Form::Tiny system - this is a role that provides most of the module's functionality.

ATTRIBUTES

Each of the attributes can be accessed by calling its name as a function on Form::Tiny::FieldDefinition object. See Form::Tiny::Manual for more in depth examples.

name

A string which should specify the hash structure path of the field.

Special characters are:

  • dot [.], which specifies nesting. Can be escaped with backslash [\]

  • star [*], which specifies any number of array elements, but only if it is the only character on level, like a.*.b

required

A field is not required by default (value 0), which means that its absence does not produce an error.

A field can also be soft required ("soft") or hard required ("hard" or 1).

Soft required field errors only if it is undefined or not present in the input data.

Hard required field also checks if the field is not an empty string.

type

A type is where you can plug in a Type::Tiny check. It has to be an instance of a class that provider validate and check methods, just like Type::Tiny. This can also be a different Form::Tiny form instance.

predicate: has_type

coerce

Coercions take place just before the validation. By default, values are not coerced. Specifying value 1 will turn on coercions from the type object.

It can also be a code reference which will be called to coerce the value.

adjust

Adjustments take place just after the validation. By default, values are not adjusted. You can specify a code reference which will be called to adjust the value (change the value after the validation).

predicate: is_adjusted

writer: set_adjustment

message

If type class error messages are not helpful enough, you can specify your own message string which will be inserted into form errors if the validation for the field fails.

predicate: has_message

data

Custom data for the field. Can be anything and will not be used by Form::Tiny system itself. It should be anything that will help user's own system use the form instance.

writer: set_data

predicate: has_data

METHODS

is_subform

Checks if the field definition's type is a form - mixes in Form::Tiny::Form role.

get_name_path

Parses and returns the name of the field as an array - a path to get the value in a hash.

hard_required

Checks if the field is hard-required (any of the two values which are allowed for this flag)

get_coerced

Coerces and returns a scalar value, according to the definition.

get_adjusted

Adjusts and returns a scalar value, according to the definition.

validate

Validates a scalar value. Arguments are $parent_form, $field_value. Returns a boolean, whether the validation passed.