Form::Tiny::FieldDefinition - definition of a field to be validated
# 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', type => Str, ... );
This class keeps all the data for a field definition and contains method that handle single field validation.
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 examples.
The only required attribute for the constructor.
A string which should specify the hash structure path of the field.
Special characters are:
dot [.], which specifies nesting
star [*], which specifies any number of array elements, but only if it is the only character on level, like a.*.b
They both can be escaped by a backslash \ to lose their special meaning.
\
A field is not required by default (value 0), which means that its absence does not produce an error.
0
A field can also be soft required ('soft') or hard required ('hard' or 1).
'soft'
'hard'
1
Soft required field produce 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.
The type attribute is where you can plug in a Type::Tiny type object. It has to be an instance of a class that provider validate and check methods, just like Type::Tiny. This can also be a Form::Tiny form instance.
predicate: has_type
Hash reference for internal use only - readable and writable under the addons method. If you need additional data for a field definition that will be used in metaclasses (while extending Form::Tiny), put it here.
addons
Coercions take place just before the validation. By default, values are not coerced. Specifying value 1 will cause the field to use coercions from the type object.
It can also be a code reference which will be called to coerce the value, passing in a field value as its only argument.
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
A coderef returning the default value for the field. Will be used when the field is not present in the input at all. Making the field hard-required will make the default value be used in place of undefined / empty value as well.
This coderef will be passed form instance as the only argument and is expected to return a scalar value.
predicate: has_default
writer: set_default
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
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
Checks if the field definition's type is a form - whether it mixes in Form::Tiny::Form role.
Parses and returns the name of the field as an object of Form::Tiny::Path class.
Checks if the field is hard-required (any of the two values which are allowed for this flag)
Validates a scalar value. Arguments are $parent_form, $field_value. Returns a boolean, whether the validation passed.
$parent_form, $field_value
To install Form::Tiny, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Form::Tiny
CPAN shell
perl -MCPAN -e shell install Form::Tiny
For more information on module installation, please visit the detailed CPAN module installation guide.