NAME

Chloro::Field - A field in a form

VERSION

version 0.07

SYNOPSIS

See Chloro.

DESCRIPTION

This class represents a field in a form.

METHODS

This class has the following methods:

Chloro::Field->new()

You'll probably make fields by using the field() subroutine exported by Chloro, but you can make one using this constructor.

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.

    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.

$field->name()

The name as passed to the constructor.

$field->human_name()

A more friendly name, which defaults to the same value as $field->name().

$field->type()

This returns a Moose::Meta::TypeConstraint object, based on the value passed to the constructor in the isa parameter.

$field->default()

The default, as passed to the constructor, if any.

$field->is_required()

Returns a boolean indicating whether the field is required.

$field->is_secure()

Returns a boolean indicating whether the field contains sensitive data.

$field->extractor()

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.

$field->validator()

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.

$field->generate_default( $params, $prefix )

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.

$field->dump()

Returns a data structure representing the field definition. This exists primarily for testing.

ROLES

This class consumes the Chloro::Role::FormComponent role.

SUPPORT

Bugs may be submitted at http://rt.cpan.org/Public/Dist/Display.html?Name=Chloro or via email to bug-chloro@rt.cpan.org.

I am also usually active on IRC as 'autarch' on irc://irc.perl.org.

SOURCE

The source code repository for Chloro can be found at https://github.com/autarch/Chloro.

AUTHOR

Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2017 by Dave Rolsky.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)

The full text of the license can be found in the LICENSE file included with this distribution.