| 1 | package HTML::FormHandler::Result; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: form result object | ||||||||||||||||||||||||||||
| 3 | 146 | $HTML::FormHandler::Result::VERSION = '0.410001'; | |||||||||||||||||||||||||||
| 4 | 146 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | # following is to allow the form to return an empty | ||||||||||||||||||||||||||||
| 6 | # hashref when value is undefined, without messing | ||||||||||||||||||||||||||||
| 7 | # with the way 'value' works for fields | ||||||||||||||||||||||||||||
| 8 | 146 | with 'HTML::FormHandler::Result::Role'; | |||||||||||||||||||||||||||
| 9 | 146 | with 'HTML::FormHandler::Traits'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 146 | has 'form' => ( | |||||||||||||||||||||||||||
| 13 | isa => 'HTML::FormHandler', | ||||||||||||||||||||||||||||
| 14 | is => 'ro', | ||||||||||||||||||||||||||||
| 15 | weak_ref => 1, | ||||||||||||||||||||||||||||
| 16 | # handles => ['render' ] | ||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 146 | has '_value' => ( | |||||||||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||||||||||
| 21 | writer => '_set_value', | ||||||||||||||||||||||||||||
| 22 | reader => '_get_value', | ||||||||||||||||||||||||||||
| 23 | clearer => '_clear_value', | ||||||||||||||||||||||||||||
| 24 | predicate => 'has_value', | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 84 | ▶ | sub value { shift->_get_value || {} } | ||||||||||||||||||||||||||
|
Subroutine
value: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | has 'form_errors' => ( | ||||||||||||||||||||||||||||
| 30 | traits => ['Array'], | ||||||||||||||||||||||||||||
| 31 | is => 'rw', | ||||||||||||||||||||||||||||
| 32 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||
| 33 | 567 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 146 | handles => { | |||||||||||||||||||||||||||
| 35 | all_form_errors => 'elements', | ||||||||||||||||||||||||||||
| 36 | push_form_errors => 'push', | ||||||||||||||||||||||||||||
| 37 | num_form_errors => 'count', | ||||||||||||||||||||||||||||
| 38 | has_form_errors => 'count', | ||||||||||||||||||||||||||||
| 39 | clear_form_errors => 'clear', | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | sub form_and_field_errors { | ||||||||||||||||||||||||||||
| 44 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
form_and_field_errors: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 1 | my @field_errors = map { $_->all_errors } $self->all_error_results; | |||||||||||||||||||||||||||
| 46 | 1 | my @form_errors = $self->all_form_errors; | |||||||||||||||||||||||||||
| 47 | 1 | return (@form_errors, @field_errors); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1124 | ▶ | sub validated { !$_[0]->has_error_results && $_[0]->has_input && !$_[0]->has_form_errors } | ||||||||||||||||||||||||||
|
Subroutine
validated: called CC=3 SCAR=11.0
Pod
undocumented
Branch: 1 branch
Condition100%3/3
not $_[0]->has_error_results and $_[0]->has_input
MC/DC100%2/2
not $_[0]->has_error_results and $_[0]->has_input
not $_[0]->has_error_results
$_[0]->has_input
Truth table100%3/3
not(A) and B
A= not $_[0]->has_error_resultsB= $_[0]->has_input
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 146 | has 'ran_validation' => ( is => 'rw', isa => 'Bool', default => 0 ); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | sub fif { | ||||||||||||||||||||||||||||
| 55 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
fif: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 56 | 1 | $self->form->fields_fif($self); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | sub peek { | ||||||||||||||||||||||||||||
| 60 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
peek: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 2 | my $string = "Form Result " . $self->name . "\n"; | |||||||||||||||||||||||||||
| 62 | 2 | my $indent = ' '; | |||||||||||||||||||||||||||
| 63 | 2 | foreach my $res ( $self->results ) { | |||||||||||||||||||||||||||
| 64 | 6 | $string .= $res->peek( $indent ); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 2 | return $string; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 146 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 70 | 146 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 71 | 146 | 1; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =pod | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head1 NAME | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | HTML::FormHandler::Result - form result object | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head1 VERSION | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | version 0.410001 | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | This is the Result object that maps to the Form. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | my $result = $self->form->run( $params ); | ||||||||||||||||||||||||||||
| 92 | my $result2 = $self->form->run( $other_params ); | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | my $value = $result->field('title')->value; | ||||||||||||||||||||||||||||
| 95 | my $fif = $result->fif; | ||||||||||||||||||||||||||||
| 96 | my $field_fid = $result->field('title')->fif; | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head2 DESCRIPTION | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | Although not experimental, the 'results' have not been exercised as much | ||||||||||||||||||||||||||||
| 101 | as the other parts of the code. If there is missing functionality or | ||||||||||||||||||||||||||||
| 102 | things that don't work, please ask or report bugs. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | The original FormHandler 'process' method, when used with persistent forms, | ||||||||||||||||||||||||||||
| 105 | leaves behind state data for a particular execution of 'process'. This is | ||||||||||||||||||||||||||||
| 106 | not optimal or clean from an architectural point of view. | ||||||||||||||||||||||||||||
| 107 | The intention with the 'result' object is to separate dynamic data from static. | ||||||||||||||||||||||||||||
| 108 | The 'form' object is treated as a kind of result factory, which will spit out | ||||||||||||||||||||||||||||
| 109 | results and leave the form in a consistent state. | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | In the current state of implementation, the result object can be used to render | ||||||||||||||||||||||||||||
| 112 | a form: | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | $result->render; | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | However there are still open questions about how much of the form/field | ||||||||||||||||||||||||||||
| 117 | should be forwarded to the result. At this point, the number of forwarded | ||||||||||||||||||||||||||||
| 118 | methods is minimal. Mechanisms to make this more customizable are being | ||||||||||||||||||||||||||||
| 119 | considered. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | Dynamic select lists are not supported yet. Static select lists | ||||||||||||||||||||||||||||
| 122 | (that are the same for every form execution) should work fine, but lists | ||||||||||||||||||||||||||||
| 123 | that are different depending on some field value will not. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | Most of this object is implemented in L<HTML::FormHandler::Result::Role>, | ||||||||||||||||||||||||||||
| 126 | because it is shared with L<HTML::FormHandler::Field::Result>. | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | FormHandler Contributors - see HTML::FormHandler | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | This software is copyright (c) 2017 by Gerda Shank. | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 137 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =cut | ||||||||||||||||||||||||||||