Chloro::Field - A field in a form
version 0.06
See Chloro.
This class represents a field in a form.
This class has the following methods:
You'll probably make fields by using the field() subroutine exported by Chloro, but you can make one using this constructor.
field()
The constructor accepts the following parameters:
name
The name of the field. This is required.
human_name
A more friendly version of the name. This defaults to the same value as name. This value will be used when generating error messages for this field.
isa
This must be a Moose type constraint. You can pass a Moose::Meta::TypeConstraint object, a type name, or a type created with MooseX::Types.
Just like with Moose attributes, an unknown name is treated as a class name.
default
The default value for the field. Like Moose attributes, this can either be a non-reference value of a subroutine reference.
A subroutine reference will be called as a method on the field object, and will receive two additional arguments.
The first argument is the parameter passed to the $form->process() method.
$form->process()
The second is the prefix for the field, if it is part of a group.
required
A boolean indicating whether the field is required. Defaults to false.
secure
A boolean indicating whether the field contains sensitive data. Defaults to false.
extractor
This is an optional method on the field's form that will be used to extract this field's value.
The extractor is expected to return a two element list. The first should be the name of the field in the form, the second is the value.
validator
This is an optional method on the field's form that will be used to validate this field's value.
The name as passed to the constructor.
A more friendly name, which defaults to the same value as $field->name().
$field->name()
This returns a Moose::Meta::TypeConstraint object, based on the value passed to the constructor in the isa parameter.
The default, as passed to the constructor, if any.
Returns a boolean indicating whether the field is required.
Returns a boolean indicating whether the field contains sensitive data.
Returns the method used to extract the field's data from the user-submitted parameters. This defaults to _extract_field_value, a method provided by Chloro::Role::Form.
Returns the method used to extract the field's data from the user-submitted parameters. This defaults to _errors_for_field_value, a method provided by Chloro::Role::Form.
Given the user-submitted parameters and an optional prefix, this method returns a default value for the field. If the default is a subroutine reference, that reference will be called with the parameters passed to this method.
Returns a data structure representing the field definition. This exists primarily for testing.
This class consumes the Chloro::Role::FormComponent role.
Dave Rolsky <autarch@urth.org>
This software is Copyright (c) 2011 by Dave Rolsky.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Chloro, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Chloro
CPAN shell
perl -MCPAN -e shell install Chloro
For more information on module installation, please visit the detailed CPAN module installation guide.