| 1 | package HTML::FormHandler::Fields; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: internal role for form and compound fields | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 146 | $HTML::FormHandler::Fields::VERSION = '0.410001'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | 146 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 146 | ▶ | use HTML::FormHandler::TraitFor::Types; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | has 'fields' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 9 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||
| 10 | isa => 'ArrayRef[HTML::FormHandler::Field]', | ||||||||||||||||||||||||||||||||||||||||||
| 11 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 408 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 146 | auto_deref => 1, | |||||||||||||||||||||||||||||||||||||||||
| 14 | handles => { | ||||||||||||||||||||||||||||||||||||||||||
| 15 | all_fields => 'elements', | ||||||||||||||||||||||||||||||||||||||||||
| 16 | clear_fields => 'clear', | ||||||||||||||||||||||||||||||||||||||||||
| 17 | add_field => 'push', | ||||||||||||||||||||||||||||||||||||||||||
| 18 | push_field => 'push', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | num_fields => 'count', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | has_fields => 'count', | ||||||||||||||||||||||||||||||||||||||||||
| 21 | set_field_at => 'set', | ||||||||||||||||||||||||||||||||||||||||||
| 22 | _pop_field => 'pop', | ||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # This is for updates applied via roles or compound field classes; allows doing | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # both updates on the process call and updates from class applied roles | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 146 | has 'update_subfields' => ( is => 'rw', isa => 'HashRef', builder => 'build_update_subfields', | |||||||||||||||||||||||||||||||||||||||||
| 28 | traits => ['Hash'], handles => { clear_update_subfields => 'clear', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | has_update_subfields => 'count' } ); | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 382 | ▶ | sub build_update_subfields {{}} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_update_subfields: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | # used to transfer tags to fields from form and compound fields | ||||||||||||||||||||||||||||||||||||||||||
| 33 | has 'widget_tags' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 34 | isa => 'HashRef', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | traits => ['Hash'], | ||||||||||||||||||||||||||||||||||||||||||
| 36 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 407 | ▶ | default => sub {{}}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 146 | handles => { | |||||||||||||||||||||||||||||||||||||||||
| 39 | has_widget_tags => 'count' | ||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | # compatibility wrappers for result errors | ||||||||||||||||||||||||||||||||||||||||||
| 44 | sub error_fields { | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error_fields: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 14 | return map { $_->field_def } @{ $self->result->error_results }; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 20 | ▶ | sub has_error_fields { shift->result->has_error_results } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_error_fields: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | sub add_error_field { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my ( $self, $field ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_error_field: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $self->result->add_error_result( $field->result ); | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 6 | ▶ | sub num_error_fields { shift->result->num_error_results } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num_error_fields: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 146 | has 'field_name_space' => ( | |||||||||||||||||||||||||||||||||||||||||
| 57 | isa => 'HFH::ArrayRefStr', | ||||||||||||||||||||||||||||||||||||||||||
| 58 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 59 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||
| 60 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | default => '', | ||||||||||||||||||||||||||||||||||||||||||
| 62 | coerce => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | handles => { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | add_field_name_space => 'push', | ||||||||||||||||||||||||||||||||||||||||||
| 65 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | sub field_index { | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 1102 | ▶ | my ( $self, $name ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
field_index: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 1102 | my $index = 0; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 1102 | for my $field ( $self->all_fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 72 | 2059 | ▶ | return $index if $field->name eq $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 2045 | $index++; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 1088 | return; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | sub subfield { | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 11 | ▶ | my ( $self, $name ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subfield: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 11 | return $self->field($name, undef, $self); | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | sub field { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 860 | ▶ | my ( $self, $name, $die, $f ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
field: called CC=13 SCAR=26.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 860 | my $index; | |||||||||||||||||||||||||||||||||||||||||
| 87 | # if this is a full_name for a compound field | ||||||||||||||||||||||||||||||||||||||||||
| 88 | # walk through the fields to get to it | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 860 | ▶ | return undef unless ( defined $name ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 860 | ▶ | if( $self->form && $self == $self->form && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$self->form and $self == $self->form and exists $self->index->{$name}
$self->form and $self == $self->form
MC/DC66%2/3
$self->form and $self == $self->form and exists $self->index->{$name}
$self->form
$self == $self->form
exists $self->index->{$name}
Truth table75%3/4
A and B and C
A= $self->formB= $self == $self->formC= exists $self->index->{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | exists $self->index->{$name} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 753 | return $self->index->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 107 | ▶ | if ( $name =~ /\./ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 12 | my @names = split /\./, $name; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 12 | ▶ | $f ||= $self->form || $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$f ||= $self->form || $self
$self->form || $self
MC/DC0%0/3
$f ||= $self->form || $self
$f
$self->form
$self
Truth table0%0/4
A ||= B || C
A= $fB= $self->formC= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 12 | foreach my $fname (@names) { | |||||||||||||||||||||||||||||||||||||||||
| 98 | 30 | $f = $f->field($fname); | |||||||||||||||||||||||||||||||||||||||||
| 99 | 30 | ▶ | return unless $f; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 12 | return $f; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | else # not a compound name | ||||||||||||||||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 95 | for my $field ( $self->all_fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 106 | 135 | ▶ | return $field if ( $field->name eq $name ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | ▶ | return unless $die; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | die "Field '$name' not found in '$self'"; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | sub sorted_fields { | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 940 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sorted_fields: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 2904 | my @fields = sort { $a->order <=> $b->order } | |||||||||||||||||||||||||||||||||||||||||
| 117 | 940 | grep { $_->is_active } $self->all_fields; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 940 | ▶ | return wantarray ? @fields : \@fields; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | # the routine for looping through and processing each field | ||||||||||||||||||||||||||||||||||||||||||
| 122 | sub _fields_validate { | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 268 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fields_validate: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 268 | ▶ | return unless $self->has_fields; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | # validate all fields | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 268 | my %value_hash; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 268 | foreach my $field ( $self->all_fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 129 | 838 | ▶ | next if ( $field->is_inactive || $field->disabled || !$field->has_result ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$field->is_inactive or $field->disabled or not $field->has_result
$field->is_inactive or $field->disabled
MC/DC66%2/3
$field->is_inactive or $field->disabled or not $field->has_result
$field->is_inactive
$field->disabled
not $field->has_result
Truth table75%3/4
A or B or not(C)
A= $field->is_inactiveB= $field->disabledC= not $field->has_result
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | # Validate each field and "inflate" input -> value. | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 824 | $field->validate_field; # this calls the field's 'validate' routine | |||||||||||||||||||||||||||||||||||||||||
| 132 | 824 | ▶ | $value_hash{ $field->accessor } = $field->value | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$field->has_value and not $field->noupdate
MC/DC100%2/2
$field->has_value and not $field->noupdate
$field->has_value
not $field->noupdate
Truth table100%3/3
A and not(B)
A= $field->has_valueB= not $field->noupdate
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | if ( $field->has_value && !$field->noupdate ); | ||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 268 | $self->_set_value( \%value_hash ); | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | sub fields_set_value { | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 177 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fields_set_value: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 177 | my %value_hash; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 177 | foreach my $field ( $self->all_fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 142 | 577 | ▶ | next if ( $field->is_inactive || !$field->has_result ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$field->is_inactive or not $field->has_result
MC/DC50%1/2
$field->is_inactive or not $field->has_result
$field->is_inactive
not $field->has_result
Truth table66%2/3
A or not(B)
A= $field->is_inactiveB= not $field->has_result
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 567 | ▶ | $value_hash{ $field->accessor } = $field->value | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$field->has_value and not $field->noupdate
MC/DC100%2/2
$field->has_value and not $field->noupdate
$field->has_value
not $field->noupdate
Truth table100%3/3
A and not(B)
A= $field->has_valueB= not $field->noupdate
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | if ( $field->has_value && !$field->noupdate ); | ||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 177 | $self->_set_value( \%value_hash ); | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | sub fields_fif { | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 146 | ▶ | my ( $self, $result, $prefix ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fields_fif: called CC=15 SCAR=27.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 146 | ▶ | $result ||= $self->result; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$result ||= $self->result
MC/DC0%0/2
$result ||= $self->result
$result
$self->result
Truth table66%2/3
A ||= B
A= $resultB= $self->result
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 146 | ▶ | return unless $result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 146 | ▶ | $prefix ||= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$prefix ||= ""
MC/DC100%1/1
$prefix ||= ""
$prefix
Truth table100%2/2
A
A= $prefix
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 146 | ▶ | if ( $self->isa('HTML::FormHandler') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 77 | ▶ | $prefix = $self->name . "." if $self->html_prefix; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 146 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 146 | foreach my $fld_result ( $result->results ) { | |||||||||||||||||||||||||||||||||||||||||
| 160 | 413 | my $field = $fld_result->field_def; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 413 | ▶ | next if ( $field->is_inactive || $field->password ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$field->is_inactive or $field->password
MC/DC0%0/2
$field->is_inactive or $field->password
$field->is_inactive
$field->password
Truth table33%1/3
A or B
A= $field->is_inactiveB= $field->password
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 413 | my $fif = $fld_result->fif; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 413 | ▶ | next if ( !defined $fif || (ref $fif eq 'ARRAY' && ! scalar @{$fif} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not defined $fif or ref $fif eq "ARRAY" and not scalar @{$fif;}
ref $fif eq "ARRAY" and not scalar @{$fif;}
MC/DC100%3/3
not defined $fif or ref $fif eq "ARRAY" and not scalar @{$fif;}
not defined $fif
ref $fif eq "ARRAY"
not scalar @{$fif;}
Truth table100%4/4
not(A) or B and not(C)
A= not defined $fifB= ref $fif eq "ARRAY"C= not scalar @{$fif;}
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 403 | ▶ | if ( $fld_result->has_results ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 69 | my $next_params = $fld_result->fields_fif( $prefix . $field->name . '.' ); | |||||||||||||||||||||||||||||||||||||||||
| 166 | 69 | ▶ | next unless $next_params; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 68 | %params = ( %params, %{$next_params} ); | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 334 | $params{ $prefix . $field->name } = $fif; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 146 | ▶ | return if !%params; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 144 | return \%params; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | sub clear_data { | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 212 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_data: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 212 | $self->clear_result; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 212 | $self->clear_active; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 212 | $_->clear_data for $self->all_fields; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | sub propagate_error { | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 138 | ▶ | my ( $self, $result ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
propagate_error: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | # References to fields with errors are propagated up the tree. | ||||||||||||||||||||||||||||||||||||||||||
| 188 | # All fields with errors should end up being in the form's | ||||||||||||||||||||||||||||||||||||||||||
| 189 | # error_results. Once. | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 138 | my ($found) = grep { $_ == $result } $self->result->all_error_results; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 138 | ▶ | unless ( $found ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 125 | $self->result->add_error_result($result); | |||||||||||||||||||||||||||||||||||||||||
| 193 | 125 | ▶ | if ( $self->parent ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 20 | $self->parent->propagate_error( $result ); | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | sub dump_fields { shift->dump(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump_fields: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | sub dump { | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | warn "HFH: ------- fields for ", $self->name, "-------\n"; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | for my $field ( $self->sorted_fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $field->dump; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | warn "HFH: ------- end fields -------\n"; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | sub dump_validated { | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump_validated: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | warn "HFH: fields validated:\n"; | |||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | foreach my $field ( $self->sorted_fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | $field->dump_validated if $field->can('dump_validated'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | my $message = $field->has_errors ? join( ' | ', $field->all_errors) : 'validated'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | warn "HFH: ", $field->name, ": $message\n"; | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 146 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 146 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | HTML::FormHandler::Fields - internal role for form and compound fields | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | version 0.410001 | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | A role to implement field attributes, accessors, etc. To be applied | ||||||||||||||||||||||||||||||||||||||||||
| 241 | to L<HTML::FormHandler> and L<HTML::FormHandler::Field::Compound>. | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | =head2 fields | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | The field definitions as built from the field_list and the 'has_field' | ||||||||||||||||||||||||||||||||||||||||||
| 246 | declarations. This provides clear_fields, add_field, remove_last_field, | ||||||||||||||||||||||||||||||||||||||||||
| 247 | num_fields, has_fields, and set_field_at methods. | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | =head2 field( $full_name ) | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | Return the field object with the full_name passed. Will return undef | ||||||||||||||||||||||||||||||||||||||||||
| 252 | if the field is not found, or will die if passed a second parameter. | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | =head2 field_index | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | Convenience function for use with 'set_field_at'. Pass in 'name' of field | ||||||||||||||||||||||||||||||||||||||||||
| 257 | (not full_name) | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | =head2 sorted_fields | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | Calls fields and returns them in sorted order by their "order" | ||||||||||||||||||||||||||||||||||||||||||
| 262 | value. Non-sorted fields are retrieved with 'fields'. | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | =head2 clear methods | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | clear_data | ||||||||||||||||||||||||||||||||||||||||||
| 267 | clear_fields | ||||||||||||||||||||||||||||||||||||||||||
| 268 | clear_error_fields | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | =head2 Dump information | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | dump - turn verbose flag on to get this output | ||||||||||||||||||||||||||||||||||||||||||
| 273 | dump_validated - shorter version | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | FormHandler Contributors - see HTML::FormHandler | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | This software is copyright (c) 2017 by Gerda Shank. | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 284 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | =cut | ||||||||||||||||||||||||||||||||||||||||||