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

NAME

Form::Tiny::Form - main role of the Form::Tiny system

SYNOPSIS

See Form::Tiny::Manual

DESCRIPTION

This role gets automatically mixed in by importing Form::Tiny into your namespace.

ADDED INTERFACE

This section describes the interface added to your class after mixing in the Form::Tiny role.

ATTRIBUTES

Each of the attributes can be accessed by calling its name as a function on Form::Tiny object.

input

Contains the input data passed to the form.

writer: set_input

fields

Contains the validated and cleaned fields set after the validation is complete. Cannot be specified in the constructor.

valid

Contains the result of the validation - a boolean value. Gets produced lazily upon accessing it, so calling $form->valid; validates the form automatically.

clearer: clear_valid

predicate: is_validated

errors

Contains an array reference of form errors which were detected by the last performed validation. Each error is an instance of Form::Tiny::Error.

predicate: has_errors

METHODS

This section describes standalone methods available in the module - they are not directly connected to any of the attributes.

form_meta

Returns the form metaobject, an instance of Form::Tiny::Meta.

new

This is a Moose-flavored constructor for the class. It accepts a hash or hash reference of parameters, which are the attributes specified above.

field_defs

Returns an array reference of Form::Tiny::FieldDefinition instances. Can only be called in object context.

No arguments.

check

validate

These methods are here to ensure that a Form::Tiny instance can be used as a type validator itself by other form classes.

check returns a boolean value that indicates whether the validation of input data was successful.

validate does the same thing, but instead of returning a boolean it returns a list of errors that were detected, or undef if none.

Both methods take input data as the only argument.

add_error

        $form->add_error($error_string);
        $form->add_error($field_name => $error_string);
        $form->add_error($error_object);

Adds an error to the form. This should only be done during validation with customization methods listed below.

If $error_object style is used, it must be an instance of Form::Tiny::Error.