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

NAME

Chloro::ResultSet - The set of results from processing a form submission

VERSION

version 0.07

SYNOPSIS

    my $resultset = $form->process( params => $params );

    if ( $resultset->is_valid() ) {
        do_something( $resultset->results_as_hash() ):
    }
    else {
        # handle errors
    }

DESCRIPTION

This class represents the set of results from processing an entire form submission.

This includes results for individual fields and for groups, as well as validation errors for the form as a whole.

METHODS

This class has the following methods:

Chloro::ResultSet->new()

The constructor accepts the following arguments:

  • form_errors

    This must be an array reference of Chloro::Error::Form objects. It is required, but can be empty.

  • params

    This must be a hash reference. This represents the raw user-submitted data, before any munging.

  • results

    This should be a hash reference.

    The keys can either be field names or group prefixes, and the values can be either Chloro::Result::Field or Chloro::Result::Group objects.

$resultset->results()

Returns a list of Chloro::Result::Field and Chloro::Result::Group objects.

$resultset->result_for($key)

Given a field name or a group prefix, returns a Chloro::Result::Field or Chloro::Result::Group object

$resultset->is_valid()

This returns true if there are no field or form errors in this resultset.

$resultset->results_as_hash()

This takes all the result objects as assembles them into a data hash reference. See Chloro::Manual::Groups for details on how group results are returned.

$resultset->secure_results_as_hash()

This is just like $resultset->results_as_hash(), but the result for any field marked as secure is omitted. This is useful if you need to pass the form data in a query string or session, and you don't want to include things like credit card numbers or passwords.

$resultset->secure_raw_params()

Returns a hash reference of the original parameters passed to $form->process() with any fields marked secure removed.

Note that if the keys in the original params do not match the field names (because you used a custom extractor), then those keys will still be in the returned hash reference.

$resultset->form_errors()

Returns a list of Chloro::Error::Form objects. This list may be empty.

$resultset->add_form_error()

Adds a Chloro::Error::Form object to the resultset.

$resultset->field_errors()

This returns a hash of errors associated with the fields. The hash keys are either plain field names, or a prefixed name for fields in groups. The value for each key is an array reference of error objects.

Fields without errors are not included in the hash.

$resultset->all_errors()

This method returns all the errors in the resultset, both form and field. They are returned a list.

ROLES

This class does the Chloro::Role::Result and Chloro::Role::ResultSet 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.