FormHandler/Field.pm

filter: Statementstmt 83.6% 454 / 543 Branchbran 69.2% 187 / 270 Conditioncond 62.7% 96 / 153 MC/DCmcdc 38.8% 35 / 90 Subroutinesub 84.0% 95 / 113 Podpod 13.2% 11 / 83 totaltotal 70.1% 878 / 1252 CC 201 SCAR 22.5
CC
201
Cov
76%
dump
72.0
value_changed
42.0
apply_rendering_widgets
42.0
CRAP 9.5
« FormHandler/Blocks.pm ↑ Summary FormHandler/Fields.pm »
1 package HTML::FormHandler::Field;
2 # ABSTRACT: base class for fields
3 148 $HTML::FormHandler::Field::VERSION = '0.410001';
4 148 ▶use HTML::FormHandler::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 148 ▶use HTML::FormHandler::Field::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 148 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 148 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 148 ▶use HTML::FormHandler::Merge ('merge');
Subroutine BEGIN: called CC=1 SCAR=0.0
9 148 ▶use HTML::FormHandler::Render::Util('cc_widget', 'ucc_widget');
Subroutine BEGIN: called CC=1 SCAR=0.0
10 148 ▶use Sub::Name;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 148 with 'HTML::FormHandler::Traits';
13 148 with 'HTML::FormHandler::Validate';
14 148 with 'HTML::FormHandler::Widget::ApplyRole';
15 148 with 'HTML::FormHandler::TraitFor::Types';
16  
17  
18 148 has 'name' => ( isa => 'Str', is => 'rw', required => 1 );
19 50 ▶has 'type' => ( isa => 'Str', is => 'rw', default => sub { ref shift } );
Subroutine __ANON__: called CC=1 SCAR=0.0
20 148 has 'parent' => ( is => 'rw', predicate => 'has_parent', weak_ref => 1 );
21 ▶sub has_fields { }
Subroutine has_fields: called CC=1 SCAR=0.0
Pod undocumented
22 148 has 'input_without_param' => (
23 is => 'rw',
24 predicate => 'has_input_without_param'
25 );
26 148 has 'not_nullable' => ( is => 'rw', isa => 'Bool' );
27 148 has 'no_value_if_empty' => ( is => 'rw', isa => 'Bool' );
28 148 has 'validate_when_empty' => ( is => 'rw', isa => 'Bool' );
29 148 has 'init_value' => ( is => 'rw', clearer => 'clear_init_value', predicate => 'has_init_value' );
30 148 has 'default' => ( is => 'rw' );
31 148 has 'default_over_obj' => ( is => 'rw', builder => 'build_default_over_obj' );
32 ▶sub build_default_over_obj { }
Subroutine build_default_over_obj: called CC=1 SCAR=0.0
Pod undocumented
33 148 has 'result' => (
34 isa => 'HTML::FormHandler::Field::Result',
35 is => 'ro',
36 weak_ref => 1,
37 clearer => 'clear_result',
38 predicate => 'has_result', # warning: will still return true if value has been garbage-collected
39 writer => '_set_result',
40 handles => [
41 '_set_input', '_clear_input', '_set_value', '_clear_value',
42 'errors', 'all_errors', '_push_errors', 'num_errors', 'has_errors',
43 'clear_errors', 'validated', 'add_warning', 'all_warnings', 'num_warnings',
44 'has_warnings', 'warnings', 'missing',
45 ],
46 );
47 148 has '_pin_result' => ( is => 'ro', reader => '_get_pin_result', writer => '_set_pin_result' );
48  
49 sub has_input {
50 4785 ▶ my $self = shift;
Subroutine has_input: called CC=3 SCAR=12.5
Pod undocumented
51 4785 ▶ return unless $self->has_result and $self->result;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_result and $self->result 0 4785 4785
Condition33%1/3
$self->has_result and $self->result
!ll&&!rl&&r
004785
MC/DC0%0/2
$self->has_result and $self->result
$self->has_result $self->result
Truth table33%1/3
A and B
A= $self->has_resultB= $self->result
ABresult
0X0
100
111
52 4785 return $self->result->has_input;
53 }
54  
55 sub has_value {
56 2402 ▶ my $self = shift;
Subroutine has_value: called CC=3 SCAR=12.5
Pod undocumented
57 2402 ▶ return unless $self->has_result and $self->result;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_result and $self->result 0 2402 2402
Condition33%1/3
$self->has_result and $self->result
!ll&&!rl&&r
002402
MC/DC0%0/2
$self->has_result and $self->result
$self->has_result $self->result
Truth table33%1/3
A and B
A= $self->has_resultB= $self->result
ABresult
0X0
100
111
58 2402 return $self->result->has_value;
59 }
60  
61 # these should normally only be called for field tests
62 sub reset_result {
63 13 ▶ my $self = shift;
Subroutine reset_result: called CC=1 SCAR=0.0
Pod undocumented
64 13 $self->clear_result;
65 13 $self->build_result;
66 }
67 sub build_result {
68 53 ▶ my $self = shift;
Subroutine build_result: called CC=3 SCAR=11.6
Pod undocumented
69 53 my @parent;
70 53 ▶ @parent = ( 'parent' => $self->parent->result )
Branch: 1 branch
BranchTrueFalseTotal
if $self->parent and $self->parent->result 0 53 53
Condition33%1/3
$self->parent and $self->parent->result
!ll&&!rl&&r
5300
MC/DC0%0/2
$self->parent and $self->parent->result
$self->parent $self->parent->result
Truth table33%1/3
A and B
A= $self->parentB= $self->parent->result
ABresult
0X0
100
111
71 if ( $self->parent && $self->parent->result );
72 53 my $result = HTML::FormHandler::Field::Result->new(
73 name => $self->name,
74 field_def => $self,
75 @parent
76 );
77 53 $self->_set_pin_result($result); # to prevent garbage collection of result
78 53 $self->_set_result($result);
79 }
80  
81 sub input {
82 1891 ▶ my $self = shift;
Subroutine input: called CC=5 SCAR=16.2
Pod documented
83  
84 # allow testing fields individually by creating result if no form
85 1891 ▶ return undef unless $self->has_result || !$self->form;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_result or not $self->form 1 1890 1891
Condition66%2/3
$self->has_result or not $self->form
l!l&&r!l&&!r
189001
MC/DC50%1/2
$self->has_result or not $self->form
$self->has_result not $self->form
Truth table66%2/3
A or not(B)
A= $self->has_resultB= not $self->form
ABresult
1X1
011
000
86 1890 my $result = $self->result;
87 1890 ▶ return undef unless $result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 1890 1890
88 1890 ▶ return $result->_set_input(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 5 1885 1890
89 1885 return $result->input;
90 }
91  
92 sub value {
93 7792 ▶ my $self = shift;
Subroutine value: called CC=5 SCAR=16.2
Pod documented
94  
95 # allow testing fields individually by creating result if no form
96 7792 ▶ return undef unless $self->has_result || !$self->form;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_result or not $self->form 10 7782 7792
Condition66%2/3
$self->has_result or not $self->form
l!l&&r!l&&!r
7782010
MC/DC50%1/2
$self->has_result or not $self->form
$self->has_result not $self->form
Truth table66%2/3
A or not(B)
A= $self->has_resultB= not $self->form
ABresult
1X1
011
000
97 7782 my $result = $self->result;
98 7782 ▶ return undef unless $result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 7782 7782
99 7782 ▶ return $result->_set_value(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 8 7774 7782
100 7774 return $result->value;
101 }
102 # for compatibility. deprecate and remove at some point
103 0 ▶sub clear_input { shift->_clear_input }
Subroutine clear_input: not called CC=1 SCAR=6.9
Pod undocumented
104 0 ▶sub clear_value { shift->_clear_value }
Subroutine clear_value: not called CC=1 SCAR=6.9
Pod undocumented
105 sub clear_data {
106 519 ▶ my $self = shift;
Subroutine clear_data: called CC=1 SCAR=0.0
Pod undocumented
107 519 $self->clear_result;
108 519 $self->clear_active;
109 }
110 # this is a kludge to allow testing field deflation
111 sub _deflate_and_set_value {
112 2 ▶ my ( $self, $value ) = @_;
Subroutine _deflate_and_set_value: called CC=2 SCAR=7.0
113 2 ▶ if( $self->_can_deflate ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_can_deflate) 2 0 2
114 2 $value = $self->_apply_deflation($value);
115 }
116 2 $self->_set_value($value);
117 }
118  
119 ▶sub is_repeatable { }
Subroutine is_repeatable: called CC=1 SCAR=0.0
Pod undocumented
120  
121 148 has 'fif_from_value' => ( isa => 'Str', is => 'ro' );
122  
123 sub fif {
124 1538 ▶ my ( $self, $result ) = @_;
Subroutine fif: called CC=18 SCAR=29.2
Pod documented
125  
126 1538 ▶ return if ( $self->inactive && !$self->_active );
Branch: 1 branch
BranchTrueFalseTotal
if $self->inactive and not $self->_active 0 1538 1538
Condition66%2/3
$self->inactive and not $self->_active
!ll&&!rl&&r
153170
MC/DC0%0/2
$self->inactive and not $self->_active
$self->inactive not $self->_active
Truth table66%2/3
A and not(B)
A= $self->inactiveB= not $self->_active
ABresult
0X0
100
111
127 1538 ▶ return '' if $self->password;
Branch: 1 branch
BranchTrueFalseTotal
if $self->password 8 1530 1538
128 1530 ▶ return unless $result || $self->has_result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result or $self->has_result 1 1529 1530
Condition100%3/3
$result or $self->has_result
l!l&&r!l&&!r
13381911
MC/DC100%2/2
$result or $self->has_result
$result $self->has_result
Truth table100%3/3
A or B
A= $resultB= $self->has_result
ABresult
1X1
011
000
129 1529 ▶ my $lresult = $result || $self->result;
Condition66%2/3
$result || $self->result
l!l&&r!l&&!r
13381910
MC/DC0%0/2
$result || $self->result
$result $self->result
Truth table66%2/3
A || B
A= $resultB= $self->result
ABresult
1X1
011
000
130 1529 ▶ return unless $lresult;
Branch: 1 branch
BranchTrueFalseTotal
unless $lresult 0 1529 1529
131 1529 ▶ if ( ( $self->has_result && $self->has_input && !$self->fif_from_value ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_result and $self->has_input and not $self->fif_from_value or $self->fif_from_value and not defined $lresult->value) 674 855 1529
Condition83%10/12
$self->has_result and $self->has_input and not $self->fif_from_value or $self->fif_from_value and not defined $lresult->value
l!l&&r!l&&!r
6740855
$self->has_result and $self->has_input and not $self->fif_from_value
!ll&&!rl&&r
8505674
$self->has_result and $self->has_input
!ll&&!rl&&r
38812679
$self->fif_from_value and not defined $lresult->value
!ll&&!rl&&r
84960
MC/DC40%2/5
$self->has_result and $self->has_input and not $self->fif_from_value or $self->fif_from_value and not defined $lresult->value
$self->has_result $self->has_input not $self->fif_from_value $self->fif_from_value not defined $lresult->value
Truth table30%3/10
A and B and not(C) or D and not(E)
A= $self->has_resultB= $self->has_inputC= not $self->fif_from_valueD= $self->fif_from_valueE= not defined $lresult->value
ABCDEresult
111XX1
0XX111
10X111
110111
0XX0X0
0XX100
10X0X0
10X100
1100X0
110100
132 ( $self->fif_from_value && !defined $lresult->value ) )
133 {
134 674 ▶ return defined $lresult->input ? $lresult->input : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $lresult->input ? : 669 5 674
135 }
136 855 ▶ if ( $lresult->has_value ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($lresult->has_value) { } 282 573 855
elsif (defined $self->value) { } 9 564 573
137 282 my $value;
138 282 ▶ if( $self->_can_deflate ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_can_deflate) { } 105 177 282
139 105 $value = $self->_apply_deflation($lresult->value);
140 }
141 else {
142 177 $value = $lresult->value;
143 }
144 282 ▶ return ( defined $value ? $value : '' );
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 282 0 282
145 }
146 elsif ( defined $self->value ) {
147 # this is because checkboxes and submit buttons have their own 'value'
148 # needs to be fixed in some better way
149 9 return $self->value;
150 }
151 564 return '';
152 }
153  
154 has 'accessor' => (
155 isa => 'Str',
156 is => 'rw',
157 lazy => 1,
158 default => sub {
159 746 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
160 746 my $accessor = $self->name;
161 746 ▶ $accessor =~ s/^(.*)\.//g if ( $accessor =~ /\./ );
Branch: 1 branch
BranchTrueFalseTotal
if $accessor =~ /\./ 0 746 746
162 746 return $accessor;
163 }
164 148 );
165 148 has 'is_contains' => ( is => 'rw', isa => 'Bool' );
166 148 has 'temp' => ( is => 'rw' );
167  
168 sub has_flag {
169 3000 ▶ my ( $self, $flag_name ) = @_;
Subroutine has_flag: called CC=2 SCAR=6.9
Pod undocumented
170 3000 ▶ return unless $self->can($flag_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($flag_name) 1211 1789 3000
171 1789 return $self->$flag_name;
172 }
173  
174 148 has 'label' => (
175 isa => 'Maybe[Str]',
176 is => 'rw',
177 lazy => 1,
178 builder => 'build_label',
179 );
180 148 has 'do_label' => ( isa => 'Bool', is => 'rw', default => 1 );
181 has 'build_label_method' => ( is => 'rw', isa => 'CodeRef',
182 traits => ['Code'], handles => { 'build_label' => 'execute_method' },
183 1182 ▶ default => sub { \&default_build_label },
Subroutine __ANON__: called CC=1 SCAR=0.0
184 148 );
185 sub default_build_label {
186 380 ▶ my $self = shift;
Subroutine default_build_label: called CC=1 SCAR=0.0
Pod undocumented
187 380 my $label = $self->name;
188 380 $label =~ s/_/ /g;
189 380 $label = ucfirst($label);
190 380 return $label;
191 }
192 sub loc_label {
193 555 ▶ my $self = shift;
Subroutine loc_label: called CC=1 SCAR=0.0
Pod undocumented
194 555 return $self->_localize($self->label);
195 }
196 148 has 'wrap_label_method' => (
197 traits => ['Code'],
198 is => 'ro',
199 isa => 'CodeRef',
200 predicate => 'does_wrap_label',
201 handles => { 'wrap_label' => 'execute_method' },
202 );
203 148 has 'title' => ( isa => 'Str', is => 'rw' );
204 148 has 'style' => ( isa => 'Str', is => 'rw' );
205 148 has 'form' => (
206 isa => 'HTML::FormHandler',
207 is => 'rw',
208 weak_ref => 1,
209 predicate => 'has_form',
210 );
211 0 ▶sub is_form { 0 }
Subroutine is_form: not called CC=1 SCAR=6.9
Pod undocumented
212 148 has 'html_name' => (
213 isa => 'Str',
214 is => 'rw',
215 lazy => 1,
216 builder => 'build_html_name'
217 );
218  
219 sub build_html_name {
220 510 ▶ my $self = shift;
Subroutine build_html_name: called CC=3 SCAR=12.5
Pod undocumented
221 510 ▶ my $prefix = ( $self->form && $self->form->html_prefix ) ? $self->form->name . "." : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->form && $self->form->html_prefix ? : 0 510 510
Condition33%1/3
$self->form and $self->form->html_prefix
!ll&&!rl&&r
05100
MC/DC0%0/2
$self->form and $self->form->html_prefix
$self->form $self->form->html_prefix
Truth table33%1/3
A and B
A= $self->formB= $self->form->html_prefix
ABresult
0X0
100
111
222 510 return $prefix . $self->full_name;
223 }
224 148 has 'widget' => ( isa => 'Str', is => 'rw' );
225 148 has 'widget_wrapper' => ( isa => 'Str', is => 'rw' );
226 148 has 'do_wrapper' => ( is => 'rw', default => 1 );
227 0 ▶sub wrapper { shift->widget_wrapper || '' }
Subroutine wrapper: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
(shift())->widget_wrapper or "" 0 0 0
228 83 ▶sub uwrapper { ucc_widget( shift->widget_wrapper || '' ) || 'simple' }
Subroutine uwrapper: called CC=3 SCAR=12.7
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
ucc_widget((shift())->widget_wrapper || "") or "simple" 0 83 83
Condition50%1/2
(shift())->widget_wrapper || ''
l!l
830
MC/DC0%0/1
(shift())->widget_wrapper || ''
(shift())->widget_wrapper
Truth table50%1/2
A
A= (shift())->widget_wrapper
Aresult
11
00
229 12 ▶sub twrapper { shift->uwrapper . ".tt" }
Subroutine twrapper: called CC=1 SCAR=0.0
Pod undocumented
230 16 ▶sub uwidget { ucc_widget( shift->widget || '' ) || 'simple' }
Subroutine uwidget: called CC=3 SCAR=12.7
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
ucc_widget((shift())->widget || "") or "simple" 0 16 16
Condition50%1/2
(shift())->widget || ''
l!l
160
MC/DC0%0/1
(shift())->widget || ''
(shift())->widget
Truth table50%1/2
A
A= (shift())->widget
Aresult
11
00
231 12 ▶sub twidget { shift->uwidget . ".tt" }
Subroutine twidget: called CC=1 SCAR=0.0
Pod undocumented
232 # for use of wrapper classes
233 148 has 'wrapper_tags' => (
234 isa => 'HashRef',
235 traits => ['Hash'],
236 is => 'rw',
237 builder => 'build_wrapper_tags',
238 handles => {
239 has_wrapper_tags => 'count'
240 }
241 );
242 1163 ▶sub build_wrapper_tags { {} }
Subroutine build_wrapper_tags: called CC=1 SCAR=0.0
Pod undocumented
243 148 has 'tags' => (
244 traits => ['Hash'],
245 isa => 'HashRef',
246 is => 'rw',
247 builder => 'build_tags',
248 handles => {
249 _get_tag => 'get',
250 set_tag => 'set',
251 has_tag => 'exists',
252 tag_exists => 'exists',
253 delete_tag => 'delete',
254 },
255 );
256 1066 ▶sub build_tags {{}}
Subroutine build_tags: called CC=1 SCAR=0.0
Pod undocumented
257 sub merge_tags {
258 20 ▶ my ( $self, $new ) = @_;
Subroutine merge_tags: called CC=1 SCAR=0.0
Pod undocumented
259 20 my $old = $self->tags;
260 20 $self->tags( merge($new, $old) );
261 }
262 sub get_tag {
263 6855 ▶ my ( $self, $name ) = @_;
Subroutine get_tag: called CC=6 SCAR=18.5
Pod undocumented
264 6855 ▶ return '' unless $self->tag_exists($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->tag_exists($name) 6734 121 6855
265 121 my $tag = $self->_get_tag($name);
266 121 ▶ return $self->$tag if ref $tag eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $tag eq "CODE" 2 119 121
267 119 ▶ return $tag unless $tag =~ /^%/;
Branch: 1 branch
BranchTrueFalseTotal
unless $tag =~ /^%/ 118 1 119
268 1 ( my $block_name = $tag ) =~ s/^%//;
269 1 ▶ return $self->form->block($block_name)->render
Branch: 1 branch
BranchTrueFalseTotal
if $self->form and $self->form->block_exists($block_name) 1 0 1
Condition33%1/3
$self->form and $self->form->block_exists($block_name)
!ll&&!rl&&r
001
MC/DC0%0/2
$self->form and $self->form->block_exists($block_name)
$self->form $self->form->block_exists($block_name)
Truth table33%1/3
A and B
A= $self->formB= $self->form->block_exists($block_name)
ABresult
0X0
100
111
270 if ( $self->form && $self->form->block_exists($block_name) );
271 0 return '';
272 }
273  
274 has 'widget_name_space' => (
275 isa => 'HFH::ArrayRefStr',
276 is => 'rw',
277 traits => ['Array'],
278 1183 ▶ default => sub {[]},
Subroutine __ANON__: called CC=1 SCAR=0.0
279 148 coerce => 1,
280 handles => {
281 push_widget_name_space => 'push',
282 },
283 );
284  
285 sub add_widget_name_space {
286 1113 ▶ my ( $self, @ns ) = @_;
Subroutine add_widget_name_space: called CC=3 SCAR=12.0
Pod undocumented
287 1113 ▶ @ns = @{$ns[0]}if( scalar @ns && ref $ns[0] eq 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @ns and ref $ns[0] eq "ARRAY" 1113 0 1113
Condition33%1/3
scalar @ns and ref $ns[0] eq "ARRAY"
!ll&&!rl&&r
001113
MC/DC0%0/2
scalar @ns and ref $ns[0] eq "ARRAY"
scalar @ns ref $ns[0] eq "ARRAY"
Truth table33%1/3
A and B
A= scalar @nsB= ref $ns[0] eq "ARRAY"
ABresult
0X0
100
111
288 1113 $self->push_widget_name_space(@ns);
289 }
290  
291 148 has 'order' => ( isa => 'Int', is => 'rw', default => 0 );
292 # 'inactive' is set in the field declaration, and is static. Default status.
293 148 has 'inactive' => ( isa => 'Bool', is => 'rw', clearer => 'clear_inactive' );
294 # 'active' is cleared whenever the form is cleared. Ephemeral activation.
295 148 has '_active' => ( isa => 'Bool', is => 'rw', clearer => 'clear_active', predicate => 'has__active' );
296 sub is_active {
297 2785 ▶ my $self = shift;
Subroutine is_active: called CC=1 SCAR=0.0
Pod documented
298 2785 return ! $self->is_inactive;
299 }
300 sub is_inactive {
301 4695 ▶ my $self = shift;
Subroutine is_inactive: called CC=5 SCAR=16.1
Pod documented
302 4695 ▶ return (($self->inactive && !$self->_active) || (!$self->inactive && $self->has__active && $self->_active == 0 ) );
Condition91%11/12
$self->inactive && !$self->_active || !$self->inactive && $self->has__active && $self->_active == 0
l!l&&r!l&&!r
5524638
$self->inactive and not $self->_active
!ll&&!rl&&r
46241655
not $self->inactive and $self->has__active and $self->_active == 0
!ll&&!rl&&r
463802
not $self->inactive and $self->has__active
!ll&&!rl&&r
1646222
MC/DC60%3/5
$self->inactive && !$self->_active || !$self->inactive && $self->has__active && $self->_active == 0
$self->inactive not $self->_active not $self->inactive $self->has__active $self->_active == 0
Truth table44%4/9
A and not(B) || not(C) and D and E
A= $self->inactiveB= not $self->_activeC= not $self->inactiveD= $self->has__activeE= $self->_active == 0
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
303 }
304 148 has 'id' => ( isa => 'Str', is => 'rw', lazy => 1, builder => 'build_id' );
305 has 'build_id_method' => ( is => 'rw', isa => 'CodeRef', traits => ['Code'],
306 819 ▶ default => sub { sub { shift->html_name } },
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
307 148 handles => { build_id => 'execute_method' },
308 );
309  
310 # html attributes
311 148 has 'password' => ( isa => 'Bool', is => 'rw' );
312 148 has 'disabled' => ( isa => 'Bool', is => 'rw' );
313 148 has 'readonly' => ( isa => 'Bool', is => 'rw' );
314 148 has 'tabindex' => ( is => 'rw', isa => 'Int' );
315  
316 34 ▶sub html_element { 'input' }
Subroutine html_element: called CC=1 SCAR=0.0
Pod undocumented
317 148 has 'type_attr' => ( is => 'rw', isa => 'Str', default => 'text' );
318 148 has 'html5_type_attr' => ( isa => 'Str', is => 'ro', default => 'text' );
319 sub input_type {
320 385 ▶ my $self = shift;
Subroutine input_type: called CC=3 SCAR=11.0
Pod undocumented
321 385 ▶ return $self->html5_type_attr if ( $self->form && $self->form->has_flag('is_html5') );
Branch: 1 branch
BranchTrueFalseTotal
if $self->form and $self->form->has_flag("is_html5") 27 358 385
Condition66%2/3
$self->form and $self->form->has_flag("is_html5")
!ll&&!rl&&r
035827
MC/DC50%1/2
$self->form and $self->form->has_flag("is_html5")
$self->form $self->form->has_flag("is_html5")
Truth table66%2/3
A and B
A= $self->formB= $self->form->has_flag("is_html5")
ABresult
0X0
100
111
322 358 return $self->type_attr;
323 }
324 # temporary methods for compatibility after name change
325 0 ▶sub html_attr { shift->element_attr(@_) }
Subroutine html_attr: not called CC=1 SCAR=6.9
Pod undocumented
326 0 ▶sub has_html_attr { shift->has_element_attr(@_) }
Subroutine has_html_attr: not called CC=1 SCAR=6.9
Pod undocumented
327 0 ▶sub get_html_attr { shift->get_element_attr(@_) }
Subroutine get_html_attr: not called CC=1 SCAR=6.9
Pod undocumented
328 0 ▶sub set_html_attr { shift->set_element_attr(@_) }
Subroutine set_html_attr: not called CC=1 SCAR=6.9
Pod undocumented
329  
330 {
331 # create the attributes and methods for
332 # element_attr, build_element_attr, element_class,
333 # label_attr, build_label_attr, label_class,
334 # wrapper_attr, build_wrapper_atrr, wrapper_class
335 148 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
336 148 foreach my $attr ('wrapper', 'element', 'label' ) {
337 # trigger to move 'class' set via _attr to the class slot
338 444 my $add_meth = "add_${attr}_class";
339 my $trigger_sub = sub {
340 38 ▶ my ( $self, $value ) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
341 38 ▶ if( my $class = delete $self->{"${attr}_attr"}->{class} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = delete $$self{"${attr}_attr"}{"class"}) 18 20 38
342 18 $self->$add_meth($class);
343 }
344 444 };
345 444 has "${attr}_attr" => ( is => 'rw', traits => ['Hash'],
346 builder => "build_${attr}_attr",
347 handles => {
348 "has_${attr}_attr" => 'count',
349 "get_${attr}_attr" => 'get',
350 "set_${attr}_attr" => 'set',
351 "delete_${attr}_attr" => 'delete',
352 "exists_${attr}_attr" => 'exists',
353 },
354 trigger => $trigger_sub,
355 );
356 # create builders fo _attrs
357 444 my $attr_builder = __PACKAGE__ . "::build_${attr}_attr";
358 853 ▶ *$attr_builder = subname $attr_builder, sub {{}};
Subroutine build_label_attr: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Pod undocumented
359 # create the 'class' slots
360 444 has "${attr}_class" => ( is => 'rw', isa => 'HFH::ArrayRefStr',
361 traits => ['Array'],
362 coerce => 1,
363 builder => "build_${attr}_class",
364 handles => {
365 "has_${attr}_class" => 'count',
366 "_add_${attr}_class" => 'push',
367 },
368 );
369 # create builders for classes
370 444 my $class_builder = __PACKAGE__ . "::build_${attr}_class";
371 1134 ▶ *$class_builder = subname $class_builder, sub {[]};
Subroutine build_label_class: called CC=1 SCAR=0.0
Subroutine build_element_class: called CC=1 SCAR=0.0
Pod undocumented
Pod undocumented
372 # create wrapper for add_to_ to accept arrayref
373 444 my $add_to_class = __PACKAGE__ . "::add_${attr}_class";
374 444 my $_add_meth = __PACKAGE__ . "::_add_${attr}_class";
375 2 ▶ *$add_to_class = subname $add_to_class, sub { shift->$_add_meth((ref $_[0] eq 'ARRAY' ? @{$_[0]} : @_)); }
Subroutine add_wrapper_class: called CC=2 SCAR=7.2
Subroutine add_label_class: called CC=2 SCAR=7.2
Pod undocumented
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 2 2
ref $_[0] eq 'ARRAY' ? : 4 42 46
376 444 }
377 }
378  
379 # we're assuming that the only attribute we want in an element wrapper is a class
380 148 has 'element_wrapper_class' => (
381 is => 'rw', isa => 'HFH::ArrayRefStr',
382 traits => ['Array'],
383 coerce => 1,
384 builder => "build_element_wrapper_class",
385 handles => {
386 has_element_wrapper_class => 'count',
387 _add_element_wrapper_class => 'push',
388 },
389 );
390 0 ▶sub add_element_wrapper_class { shift->_add_element_wrapper_class((ref $_[0] eq 'ARRAY' ? @{$_[0]} : @_)); }
Subroutine add_element_wrapper_class: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 0 0
391 1178 ▶sub build_element_wrapper_class { [] }
Subroutine build_element_wrapper_class: called CC=1 SCAR=0.0
Pod undocumented
392 sub element_wrapper_attributes {
393 24 ▶ my ( $self, $result ) = @_;
Subroutine element_wrapper_attributes: called CC=5 SCAR=16.6
Pod undocumented
394 24 ▶ $result ||= $self->result;
Condition33%1/3
$result ||= $self->result
l!l&&r!l&&!r
2400
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
395 # local copy of label_attr
396 24 my $attr = {};
397 24 my $class = [@{$self->element_wrapper_class}];
398 24 $self->add_standard_element_wrapper_classes( $result, $class );
399 24 ▶ $attr->{class} = $class if @$class;
Branch: 1 branch
BranchTrueFalseTotal
if @$class 19 5 24
400 # call form hook
401 24 my $mod_attr;
402 24 ▶ $mod_attr = $self->form->html_attributes($self, 'element_wrapper', $attr, $result) if $self->form;
Branch: 1 branch
BranchTrueFalseTotal
if $self->form 24 0 24
403 24 ▶ return ref($mod_attr) eq 'HASH' ? $mod_attr : $attr;
Branch: 1 branch
BranchTrueFalseTotal
ref $mod_attr eq 'HASH' ? : 24 0 24
404 }
405 sub add_standard_element_wrapper_classes {
406 1 ▶ my ( $self, $result, $class ) = @_;
Subroutine add_standard_element_wrapper_classes: called CC=1 SCAR=0.0
Pod undocumented
407 }
408  
409 14 ▶sub attributes { shift->element_attributes(@_) }
Subroutine attributes: called CC=1 SCAR=0.0
Pod documented
410 sub element_attributes {
411 586 ▶ my ( $self, $result ) = @_;
Subroutine element_attributes: called CC=15 SCAR=27.2
Pod undocumented
412 586 ▶ $result ||= $self->result;
Condition66%2/3
$result ||= $self->result
l!l&&r!l&&!r
490960
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table66%2/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
413 586 my $attr = {};
414 # handle html5 attributes
415 586 ▶ if ($self->form && $self->form->has_flag('is_html5')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form and $self->form->has_flag("is_html5")) 28 558 586
Condition66%2/3
$self->form and $self->form->has_flag("is_html5")
!ll&&!rl&&r
055828
MC/DC50%1/2
$self->form and $self->form->has_flag("is_html5")
$self->form $self->form->has_flag("is_html5")
Truth table66%2/3
A and B
A= $self->formB= $self->form->has_flag("is_html5")
ABresult
0X0
100
111
416 28 ▶ $attr->{required} = 'required' if $self->required && $self->html5_type_attr ne 'hidden';
Branch: 1 branch
BranchTrueFalseTotal
if $self->required and $self->html5_type_attr ne "hidden" 5 23 28
Condition100%3/3
$self->required and $self->html5_type_attr ne "hidden"
!ll&&!rl&&r
2215
MC/DC100%2/2
$self->required and $self->html5_type_attr ne "hidden"
$self->required $self->html5_type_attr ne "hidden"
Truth table100%3/3
A and B
A= $self->requiredB= $self->html5_type_attr ne "hidden"
ABresult
0X0
100
111
417 28 ▶ $attr->{min} = $self->range_start if defined $self->range_start;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->range_start 4 24 28
418 28 ▶ $attr->{max} = $self->range_end if defined $self->range_end;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->range_end 4 24 28
419 }
420 # pull in deprecated attributes for backward compatibility
421 586 for my $dep_attr ( 'readonly', 'disabled' ) {
422 1172 ▶ $attr->{$dep_attr} = $dep_attr if $self->$dep_attr;
Branch: 1 branch
BranchTrueFalseTotal
if $self->$dep_attr 4 1168 1172
423 }
424 586 for my $dep_attr ( 'style', 'title', 'tabindex' ) {
425 1758 ▶ $attr->{$dep_attr} = $self->$dep_attr if defined $self->$dep_attr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->$dep_attr 24 1734 1758
426 }
427 586 $attr = {%$attr, %{$self->element_attr}};
428 586 my $class = [@{$self->element_class}];
429 586 $self->add_standard_element_classes($result, $class);
430 586 ▶ $attr->{class} = $class if @$class;
Branch: 1 branch
BranchTrueFalseTotal
if @$class 100 486 586
431 # call form hook
432 586 my $mod_attr;
433 586 ▶ $mod_attr = $self->form->html_attributes($self, 'element', $attr, $result) if $self->form;
Branch: 1 branch
BranchTrueFalseTotal
if $self->form 586 0 586
434 586 ▶ return ref($mod_attr) eq 'HASH' ? $mod_attr : $attr;
Branch: 1 branch
BranchTrueFalseTotal
ref $mod_attr eq 'HASH' ? : 586 0 586
435 }
436  
437 sub add_standard_element_classes {
438 569 ▶ my ( $self, $result, $class ) = @_;
Subroutine add_standard_element_classes: called CC=4 SCAR=13.9
Pod undocumented
439 569 ▶ push @$class, 'error' if $result->has_errors;
Branch: 1 branch
BranchTrueFalseTotal
if $result->has_errors 29 540 569
440 569 ▶ push @$class, 'warning' if $result->has_warnings;
Branch: 1 branch
BranchTrueFalseTotal
if $result->has_warnings 2 567 569
441 569 ▶ push @$class, 'disabled' if $self->disabled;
Branch: 1 branch
BranchTrueFalseTotal
if $self->disabled 4 565 569
442 }
443  
444 sub label_attributes {
445 517 ▶ my ( $self, $result ) = @_;
Subroutine label_attributes: called CC=5 SCAR=16.3
Pod undocumented
446 517 ▶ $result ||= $self->result;
Condition66%2/3
$result ||= $self->result
l!l&&r!l&&!r
422950
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table66%2/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
447 # local copy of label_attr
448 517 my $attr = {%{$self->label_attr}};
449 517 my $class = [@{$self->label_class}];
450 517 $self->add_standard_label_classes($result, $class);
451 517 ▶ $attr->{class} = $class if @$class;
Branch: 1 branch
BranchTrueFalseTotal
if @$class 10 507 517
452 # call form hook
453 517 my $mod_attr;
454 517 ▶ $mod_attr = $self->form->html_attributes($self, 'label', $attr, $result) if $self->form;
Branch: 1 branch
BranchTrueFalseTotal
if $self->form 517 0 517
455 517 ▶ return ref($mod_attr) eq 'HASH' ? $mod_attr : $attr;
Branch: 1 branch
BranchTrueFalseTotal
ref $mod_attr eq 'HASH' ? : 517 0 517
456 }
457  
458 sub add_standard_label_classes {
459 504 ▶ my ( $self, $result, $class ) = @_;
Subroutine add_standard_label_classes: called CC=1 SCAR=0.0
Pod undocumented
460 }
461  
462 sub wrapper_attributes {
463 614 ▶ my ( $self, $result ) = @_;
Subroutine wrapper_attributes: called CC=8 SCAR=21.5
Pod undocumented
464 614 ▶ $result ||= $self->result;
Condition66%2/3
$result ||= $self->result
l!l&&r!l&&!r
5061080
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table66%2/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
465 # copy wrapper
466 614 my $attr = {%{$self->wrapper_attr}};
467 614 my $class = [@{$self->wrapper_class}];
468 # add 'error' to class
469 614 $self->add_standard_wrapper_classes($result, $class);
470 614 ▶ $attr->{class} = $class if @$class;
Branch: 1 branch
BranchTrueFalseTotal
if @$class 92 522 614
471 # add id if compound field and id doesn't exist unless 'no_wrapper_id' tag
472 $attr->{id} = $self->id
473 614 ▶ if ( $self->has_flag('is_compound') && not exists $attr->{id} && ! $self->get_tag('no_wrapper_id') );
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_flag("is_compound") and not exists $attr->{"id"} && !$self->get_tag("no_wrapper_id") 60 554 614
Condition50%3/6
$self->has_flag("is_compound") and not exists $attr->{"id"} && !$self->get_tag("no_wrapper_id")
!ll&&!rl&&r
554060
exists $attr->{'id'} && !$self->get_tag('no_wrapper_id')
!ll&&!rl&&r
6000
MC/DC33%1/3
$self->has_flag("is_compound") and not exists $attr->{"id"} && !$self->get_tag("no_wrapper_id")
$self->has_flag("is_compound") exists $attr->{'id'} !$self->get_tag('no_wrapper_id')
Truth table50%2/4
A and not(B && not(C))
A= $self->has_flag("is_compound")B= exists $attr->{'id'}C= !$self->get_tag('no_wrapper_id')
ABCresult
0XX0
1110
10X1
1101
474 # call form hook
475 614 my $mod_attr;
476 614 ▶ $mod_attr = $self->form->html_attributes($self, 'wrapper', $attr, $result) if $self->form;
Branch: 1 branch
BranchTrueFalseTotal
if $self->form 614 0 614
477 614 ▶ return ref($mod_attr) eq 'HASH' ? $mod_attr : $attr;
Branch: 1 branch
BranchTrueFalseTotal
ref $mod_attr eq 'HASH' ? : 614 0 614
478 }
479  
480 sub add_standard_wrapper_classes {
481 594 ▶ my ( $self, $result, $class ) = @_;
Subroutine add_standard_wrapper_classes: called CC=4 SCAR=13.9
Pod undocumented
482 594 ▶ push @$class, 'error' if ( $result->has_error_results || $result->has_errors );
Branch: 1 branch
BranchTrueFalseTotal
if $result->has_error_results or $result->has_errors 33 561 594
Condition100%3/3
$result->has_error_results or $result->has_errors
l!l&&r!l&&!r
429561
MC/DC100%2/2
$result->has_error_results or $result->has_errors
$result->has_error_results $result->has_errors
Truth table100%3/3
A or B
A= $result->has_error_resultsB= $result->has_errors
ABresult
1X1
011
000
483 594 ▶ push @$class, 'warning' if $result->has_warnings;
Branch: 1 branch
BranchTrueFalseTotal
if $result->has_warnings 2 592 594
484 }
485  
486  
487 sub wrapper_tag {
488 0 ▶ my $self = shift;
Subroutine wrapper_tag: not called CC=2 SCAR=17.9
Pod undocumented
489 0 ▶ return $self->get_tag('wrapper_tag') || 'div';
Condition0%0/2
$self->get_tag('wrapper_tag') || 'div'
l!l
00
MC/DC0%0/1
$self->get_tag('wrapper_tag') || 'div'
$self->get_tag('wrapper_tag')
Truth table0%0/2
A
A= $self->get_tag('wrapper_tag')
Aresult
11
00
490 }
491  
492 #=====================
493 # these may be temporary
494 sub field_filename {
495 0 ▶ my $self = shift;
Subroutine field_filename: not called CC=2 SCAR=17.9
Pod undocumented
496 0 ▶ return 'checkbox_tag.tt' if $self->input_type eq 'checkbox';
Branch: 1 branch
BranchTrueFalseTotal
if $self->input_type eq "checkbox" 0 0 0
497 0 return 'input_tag.tt';
498 }
499 sub label_tag {
500 439 ▶ my $self = shift;
Subroutine label_tag: called CC=2 SCAR=6.9
Pod undocumented
501 439 ▶ return $self->get_tag('label_tag') || 'label';
Condition100%2/2
$self->get_tag('label_tag') || 'label'
l!l
13426
MC/DC100%1/1
$self->get_tag('label_tag') || 'label'
$self->get_tag('label_tag')
Truth table100%2/2
A
A= $self->get_tag('label_tag')
Aresult
11
00
502 }
503 #===================
504  
505 148 has 'writeonly' => ( isa => 'Bool', is => 'rw' );
506 148 has 'noupdate' => ( isa => 'Bool', is => 'rw' );
507  
508 #==============
509 sub convert_full_name {
510 2469 ▶ my $full_name = shift;
Subroutine convert_full_name: called CC=1 SCAR=0.0
Pod undocumented
511 2469 $full_name =~ s/\.\d+\./_/g;
512 2469 $full_name =~ s/\./_/g;
513 2469 return $full_name;
514 }
515 148 has 'validate_method' => (
516 traits => ['Code'],
517 is => 'ro',
518 isa => 'CodeRef',
519 lazy => 1,
520 builder => 'build_validate_method',
521 handles => { '_validate' => 'execute_method' },
522 );
523 148 has 'set_validate' => ( isa => 'Str', is => 'ro',);
524 sub build_validate_method {
525 1179 ▶ my $self = shift;
Subroutine build_validate_method: called CC=5 SCAR=16.1
Pod undocumented
526 1179 my $set_validate = $self->set_validate;
527 1179 ▶ $set_validate ||= "validate_" . convert_full_name($self->full_name);
Condition100%2/2
$set_validate ||= 'validate_' . convert_full_name($self->full_name)
l!l
11178
MC/DC100%1/1
$set_validate ||= 'validate_' . convert_full_name($self->full_name)
$set_validate
Truth table100%2/2
A
A= $set_validate
Aresult
11
00
528 27 ▶ return sub { my $self = shift; $self->form->$set_validate($self); }
Subroutine __ANON__: called CC=1 SCAR=0.0
529 1179 ▶ if ( $set_validate ne 'validate_model' && $self->form && $self->form->can($set_validate) );
Branch: 1 branch
BranchTrueFalseTotal
if $set_validate ne "validate_model" and $self->form and $self->form->can($set_validate) 20 1159 1179
Condition83%5/6
$set_validate ne "validate_model" and $self->form and $self->form->can($set_validate)
!ll&&!rl&&r
70108920
$set_validate ne "validate_model" and $self->form
!ll&&!rl&&r
0701109
MC/DC66%2/3
$set_validate ne "validate_model" and $self->form and $self->form->can($set_validate)
$set_validate ne "validate_model" $self->form $self->form->can($set_validate)
Truth table75%3/4
A and B and C
A= $set_validate ne "validate_model"B= $self->formC= $self->form->can($set_validate)
ABCresult
0XX0
10X0
1100
1111
530 1159 ▶ return sub { };
Subroutine __ANON__: called CC=1 SCAR=0.0
531 }
532  
533 148 has 'default_method' => (
534 traits => ['Code'],
535 is => 'ro',
536 isa => 'CodeRef',
537 writer => '_set_default_method',
538 predicate => 'has_default_method',
539 handles => { '_default' => 'execute_method' },
540 );
541 148 has 'set_default' => ( isa => 'Str', is => 'ro', writer => '_set_default');
542 # this is not a "true" builder, because sometimes 'default_method' is not set
543 sub build_default_method {
544 1183 ▶ my $self = shift;
Subroutine build_default_method: called CC=4 SCAR=13.9
Pod undocumented
545 1183 my $set_default = $self->set_default;
546 1183 ▶ $set_default ||= "default_" . convert_full_name($self->full_name);
Condition50%1/2
$set_default ||= 'default_' . convert_full_name($self->full_name)
l!l
01183
MC/DC0%0/1
$set_default ||= 'default_' . convert_full_name($self->full_name)
$set_default
Truth table50%1/2
A
A= $set_default
Aresult
11
00
547 1183 ▶ if ( $self->form && $self->form->can($set_default) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form and $self->form->can($set_default)) 7 1176 1183
Condition100%3/3
$self->form and $self->form->can($set_default)
!ll&&!rl&&r
7011067
MC/DC100%2/2
$self->form and $self->form->can($set_default)
$self->form $self->form->can($set_default)
Truth table100%3/3
A and B
A= $self->formB= $self->form->can($set_default)
ABresult
0X0
100
111
548 $self->_set_default_method(
549 11 ▶ sub { my $self = shift; return $self->form->$set_default($self, $self->form->item); }
Subroutine __ANON__: called CC=1 SCAR=0.0
550 7 );
551 }
552 }
553  
554 sub get_default_value {
555 1458 ▶ my $self = shift;
Subroutine get_default_value: called CC=3 SCAR=11.0
Pod undocumented
556 1458 ▶ if ( $self->has_default_method ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->has_default_method) { } 13 1445 1458
elsif (defined $self->default) { } 67 1378 1445
557 13 return $self->_default;
558 }
559 elsif ( defined $self->default ) {
560 67 return $self->default;
561 }
562 1378 return;
563 }
564 {
565 # create inflation/deflation methods
566 148 foreach my $type ( 'inflate_default', 'deflate_value', 'inflate', 'deflate' ) {
567 592 has "${type}_method" => ( is => 'ro', traits => ['Code'],
568 isa => 'CodeRef',
569 writer => "_set_${type}_method",
570 predicate => "has_${type}_method",
571 handles => {
572 $type => 'execute_method',
573 },
574 );
575 }
576 }
577  
578 148 has 'deflation' => (
579 is => 'rw',
580 predicate => 'has_deflation',
581 );
582 has 'trim' => (
583 is => 'rw',
584 1181 ▶ default => sub { { transform => \&default_trim } }
Subroutine __ANON__: called CC=1 SCAR=0.0
585 148 );
586  
587 sub default_trim {
588 953 ▶ my $value = shift;
Subroutine default_trim: called CC=7 SCAR=19.5
Pod undocumented
589 953 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 953 953
590 953 ▶ my @values = ref $value eq 'ARRAY' ? @$value : ($value);
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 67 886 953
591 953 for (@values) {
592 1008 ▶ next if ref $_ or !defined;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ or not defined $_ 148 860 1008
Condition100%3/3
ref $_ or not defined $_
l!l&&r!l&&!r
1462860
MC/DC100%2/2
ref $_ or not defined $_
ref $_ not defined $_
Truth table100%3/3
A or not(B)
A= ref $_B= not defined $_
ABresult
1X1
011
000
593 860 s/^\s+//;
594 860 s/\s+$//;
595 }
596 953 ▶ return ref $value eq 'ARRAY' ? \@values : $values[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 67 886 953
597 }
598 148 has 'render_filter' => (
599 traits => ['Code'],
600 is => 'ro',
601 isa => 'CodeRef',
602 lazy => 1,
603 builder => 'build_render_filter',
604 handles => { html_filter => 'execute' },
605 );
606  
607 sub build_render_filter {
608 446 ▶ my $self = shift;
Subroutine build_render_filter: called CC=3 SCAR=11.0
Pod undocumented
609  
610 446 ▶ if( $self->form && $self->form->can('render_filter') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form and $self->form->can('render_filter')) { } 1 445 446
Condition100%3/3
$self->form and $self->form->can("render_filter")
!ll&&!rl&&r
14441
MC/DC100%2/2
$self->form and $self->form->can("render_filter")
$self->form $self->form->can("render_filter")
Truth table100%3/3
A and B
A= $self->formB= $self->form->can("render_filter")
ABresult
0X0
100
111
611 1 my $coderef = $self->form->can('render_filter');
612 1 return $coderef;
613 }
614 else {
615 445 return \&default_render_filter;
616 }
617 }
618  
619 sub default_render_filter {
620 1856 ▶ my $string = shift;
Subroutine default_render_filter: called CC=2 SCAR=7.0
Pod undocumented
621 1856 ▶ return '' if (!defined $string);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 1856 1856
622 1856 $string =~ s/&/&/g;
623 1856 $string =~ s/</&lt;/g;
624 1856 $string =~ s/>/&gt;/g;
625 1856 $string =~ s/"/&quot;/g;
626 1856 return $string;
627 }
628  
629 148 has 'input_param' => ( is => 'rw', isa => 'Str' );
630  
631 148 has 'language_handle' => (
632 isa => duck_type( [ qw(maketext) ] ),
633 is => 'rw',
634 reader => 'get_language_handle',
635 writer => 'set_language_handle',
636 predicate => 'has_language_handle'
637 );
638  
639 sub language_handle {
640 860 ▶ my ( $self, $value ) = @_;
Subroutine language_handle: called CC=6 SCAR=19.7
Pod undocumented
641 860 ▶ if( $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) 0 860 860
642 0 $self->set_language_handle($value);
643 0 return;
644 }
645 860 ▶ return $self->get_language_handle if( $self->has_language_handle );
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_language_handle 56 804 860
646 # if language handle isn't set use form language handle if possible
647 804 ▶ return $self->form->language_handle if ( $self->has_form );
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_form 776 28 804
648 # no form, no language handle. This should only happen when
649 # testing fields.
650 28 my $lh;
651 28 ▶ if ( $ENV{LANGUAGE_HANDLE} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'LANGUAGE_HANDLE'}) { } 28 0 28
652 28 ▶ if ( blessed $ENV{LANGUAGE_HANDLE} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($ENV{'LANGUAGE_HANDLE'})) { } 0 28 28
653 0 $lh = $ENV{LANGUAGE_HANDLE};
654 }
655 else {
656 28 $lh = HTML::FormHandler::I18N->get_handle( $ENV{LANGUAGE_HANDLE} );
657 }
658 }
659 else {
660 0 require HTML::FormHandler::I18N;
661 0 $lh = HTML::FormHandler::I18N->get_handle;
662 }
663 28 $self->set_language_handle($lh);
664 28 return $lh;
665 }
666  
667 148 has 'localize_meth' => (
668 traits => ['Code'],
669 is => 'ro',
670 isa => 'CodeRef',
671 lazy => 1,
672 builder => 'build_localize_meth',
673 handles => { '_localize' => 'execute_method' },
674 );
675  
676 sub build_localize_meth {
677 521 ▶ my $self = shift;
Subroutine build_localize_meth: called CC=3 SCAR=12.7
Pod undocumented
678  
679 521 ▶ if( $self->form && $self->form->can('localize_meth') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form and $self->form->can('localize_meth')) { } 0 521 521
Condition66%2/3
$self->form and $self->form->can("localize_meth")
!ll&&!rl&&r
284930
MC/DC0%0/2
$self->form and $self->form->can("localize_meth")
$self->form $self->form->can("localize_meth")
Truth table66%2/3
A and B
A= $self->formB= $self->form->can("localize_meth")
ABresult
0X0
100
111
680 0 my $coderef = $self->form->can('localize_meth');
681 0 return $coderef;
682 }
683 else {
684 521 return \&default_localize;
685 }
686 }
687  
688 sub default_localize {
689 860 ▶ my ($self, @message) = @_;
Subroutine default_localize: called CC=1 SCAR=0.0
Pod undocumented
690 860 my $message = $self->language_handle->maketext(@message);
691 860 return $message;
692 }
693  
694 has 'messages' => ( is => 'rw',
695 isa => 'HashRef',
696 traits => ['Hash'],
697 1180 ▶ default => sub {{}},
Subroutine __ANON__: called CC=1 SCAR=0.0
698 148 handles => {
699 '_get_field_message' => 'get',
700 '_has_field_message' => 'exists',
701 'set_message' => 'set',
702 },
703 );
704  
705 148 our $class_messages = {
706 'field_invalid' => 'field is invalid',
707 'range_too_low' => 'Value must be greater than or equal to [_1]',
708 'range_too_high' => 'Value must be less than or equal to [_1]',
709 'range_incorrect' => 'Value must be between [_1] and [_2]',
710 'wrong_value' => 'Wrong value',
711 'no_match' => '[_1] does not match',
712 'not_allowed' => '[_1] not allowed',
713 'error_occurred' => 'error occurred',
714 'required' => '[_1] field is required',
715 'unique' => 'Duplicate value for [_1]',
716 };
717  
718 sub get_class_messages {
719 135 ▶ my $self = shift;
Subroutine get_class_messages: called CC=3 SCAR=11.0
Pod undocumented
720 135 my $messages = { %$class_messages };
721 135 ▶ $messages->{required} = $self->required_message
Branch: 1 branch
BranchTrueFalseTotal
if $self->required_message 1 134 135
722 if $self->required_message;
723 135 ▶ $messages->{unique} = $self->unique_message
Branch: 1 branch
BranchTrueFalseTotal
if $self->unique_message 0 135 135
724 if $self->unique_message;
725 135 return $messages;
726 }
727  
728 sub get_message {
729 139 ▶ my ( $self, $msg ) = @_;
Subroutine get_message: called CC=4 SCAR=13.9
Pod undocumented
730  
731 # first look in messages set on individual field
732 139 ▶ return $self->_get_field_message($msg)
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_field_message($msg) 3 136 139
733 if $self->_has_field_message($msg);
734 # then look at form messages
735 136 ▶ return $self->form->_get_form_message($msg)
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_form and $self->form->_has_form_message($msg) 1 135 136
Condition100%3/3
$self->has_form and $self->form->_has_form_message($msg)
!ll&&!rl&&r
59761
MC/DC100%2/2
$self->has_form and $self->form->_has_form_message($msg)
$self->has_form $self->form->_has_form_message($msg)
Truth table100%3/3
A and B
A= $self->has_formB= $self->form->_has_form_message($msg)
ABresult
0X0
100
111
736 if $self->has_form && $self->form->_has_form_message($msg);
737 # then look for messages up through inherited field classes
738 135 return $self->get_class_messages->{$msg};
739 }
740 sub all_messages {
741 0 ▶ my $self = shift;
Subroutine all_messages: not called CC=4 SCAR=30.0
Pod undocumented
742 0 ▶ my $form_messages = $self->has_form ? $self->form->messages : {};
Branch: 1 branch
BranchTrueFalseTotal
$self->has_form ? : 0 0 0
743 0 ▶ my $field_messages = $self->messages || {};
Condition0%0/2
$self->messages || {}
l!l
00
MC/DC0%0/1
$self->messages || {}
$self->messages
Truth table0%0/2
A
A= $self->messages
Aresult
11
00
744 0 ▶ my $lclass_messages = $self->my_class_messages || {};
Condition0%0/2
$self->my_class_messages || {}
l!l
00
MC/DC0%0/1
$self->my_class_messages || {}
$self->my_class_messages
Truth table0%0/2
A
A= $self->my_class_messages
Aresult
11
00
745 0 return {%{$lclass_messages}, %{$form_messages}, %{$field_messages}};
746 }
747  
748 sub BUILDARGS {
749 1183 ▶ my $class = shift;
Subroutine BUILDARGS: called CC=3 SCAR=11.3
Pod documented
750  
751 # for backwards compatibility; these will be removed eventually
752 1183 my @new;
753 push @new, ('element_attr', {@_}->{html_attr} )
754 1183 ▶ if( exists {@_}->{html_attr} );
Branch: 1 branch
BranchTrueFalseTotal
if exists {@_}->{"html_attr"} 0 1183 1183
755 push @new, ('do_label', !{@_}->{no_render_label} )
756 1183 ▶ if( exists {@_}->{no_render_label} );
Branch: 1 branch
BranchTrueFalseTotal
if exists {@_}->{"no_render_label"} 0 1183 1183
757 1183 return $class->SUPER::BUILDARGS(@_, @new);
758 }
759  
760 sub BUILD {
761 1183 ▶ my ( $self, $params ) = @_;
Subroutine BUILD: called CC=5 SCAR=16.1
Pod undocumented
762  
763 # temporary, for compatibility. move widget_tags to tags
764 1183 ▶ $self->merge_tags($self->wrapper_tags) if $self->has_wrapper_tags;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_wrapper_tags 20 1163 1183
765 # run default method builder
766 1183 $self->build_default_method;
767 # build validate_method; needs to happen before validation
768 # in order to have the "real" repeatable field names, not the instances
769 1183 $self->validate_method;
770 # merge form widget_name_space
771 1183 ▶ $self->add_widget_name_space( $self->form->widget_name_space ) if $self->form;
Branch: 1 branch
BranchTrueFalseTotal
if $self->form 1113 70 1183
772 # handle apply actions
773 1183 ▶ $self->add_action( $self->trim ) if $self->trim;
Branch: 1 branch
BranchTrueFalseTotal
if $self->trim 1182 1 1183
774 1183 $self->_build_apply_list;
775 1183 ▶ $self->add_action( @{ $params->{apply} } ) if $params->{apply};
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"apply"} 70 1113 1183
776 }
777  
778 # this is the recursive routine that is used
779 # to initialize field results if there is no initial object and no params
780 sub _result_from_fields {
781 1189 ▶ my ( $self, $result ) = @_;
Subroutine _result_from_fields: called CC=8 SCAR=20.9
782  
783 1189 ▶ if ( $self->disabled && $self->has_init_value ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->disabled and $self->has_init_value) { } 4 1185 1189
elsif (my(@values) = $self->get_default_value) { } 68 1117 1185
Condition100%3/3
$self->disabled and $self->has_init_value
!ll&&!rl&&r
118054
MC/DC100%2/2
$self->disabled and $self->has_init_value
$self->disabled $self->has_init_value
Truth table100%3/3
A and B
A= $self->disabledB= $self->has_init_value
ABresult
0X0
100
111
784 4 $result->_set_value($self->init_value);
785 }
786 elsif ( my @values = $self->get_default_value ) {
787 68 ▶ if ( $self->has_inflate_default_method ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_inflate_default_method) 2 66 68
788 2 @values = $self->inflate_default(@values);
789 }
790 68 ▶ my $value = @values > 1 ? \@values : shift @values;
Branch: 1 branch
BranchTrueFalseTotal
@values > 1 ? : 0 68 68
791 68 ▶ $self->init_value($value) if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 68 0 68
792 68 ▶ $result->_set_value($value) if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 68 0 68
793 }
794 1189 $self->_set_result($result);
795 1189 $result->_set_field_def($self);
796 1189 return $result;
797 }
798  
799 sub _result_from_input {
800 765 ▶ my ( $self, $result, $input, $exists ) = @_;
Subroutine _result_from_input: called CC=6 SCAR=17.9
801  
802 765 ▶ if ($exists) {
Branch: 4 branches
BranchTrueFalseTotal
if ($exists) { } 650 115 765
elsif ($self->disabled) { } 2 113 115
elsif ($self->form and $self->form->use_fields_for_input_without_param) { } 6 107 113
elsif ($self->has_input_without_param) { } 31 76 107
803 650 $result->_set_input($input);
804 }
805 elsif ( $self->disabled ) {
806 # This maybe should come from _result_from_object, but there's
807 # not a reliable way to get there from here. Field can handle...
808 2 return $self->_result_from_fields( $result );
809 }
810 ▶ elsif ( $self->form && $self->form->use_fields_for_input_without_param ) {
Condition66%2/3
$self->form and $self->form->use_fields_for_input_without_param
!ll&&!rl&&r
01076
MC/DC50%1/2
$self->form and $self->form->use_fields_for_input_without_param
$self->form $self->form->use_fields_for_input_without_param
Truth table66%2/3
A and B
A= $self->formB= $self->form->use_fields_for_input_without_param
ABresult
0X0
100
111
811 6 return $self->_result_from_fields( $result );
812 }
813 elsif ( $self->has_input_without_param ) {
814 31 $result->_set_input( $self->input_without_param );
815 }
816 757 $self->_set_result($result);
817 757 $result->_set_field_def($self);
818 757 return $result;
819 }
820  
821 sub _result_from_object {
822 257 ▶ my ( $self, $result, $value ) = @_;
Subroutine _result_from_object: called CC=3 SCAR=11.8
823  
824 257 $self->_set_result($result);
825  
826 257 ▶ if ( $self->form ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form) { } 257 0 257
827 257 $self->form->init_value( $self, $value );
828 }
829 else {
830 0 $self->init_value($value);
831 0 $result->_set_value($value);
832 }
833 257 ▶ $result->_set_value(undef) if $self->writeonly;
Branch: 1 branch
BranchTrueFalseTotal
if $self->writeonly 0 257 257
834 257 $result->_set_field_def($self);
835 257 return $result;
836 }
837  
838 sub full_name {
839 5772 ▶ my $field = shift;
Subroutine full_name: called CC=4 SCAR=13.9
Pod documented
840  
841 5772 my $name = $field->name;
842 5772 my $parent_name;
843 # field should always have a parent unless it's a standalone field test
844 5772 ▶ if ( $field->parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->parent) 5599 173 5772
845 5599 $parent_name = $field->parent->full_name;
846 }
847 5772 ▶ return $name unless defined $parent_name && length $parent_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parent_name and length $parent_name 4372 1400 5772
Condition100%3/3
defined $parent_name and length $parent_name
!ll&&!rl&&r
17341991400
MC/DC100%2/2
defined $parent_name and length $parent_name
defined $parent_name length $parent_name
Truth table100%3/3
A and B
A= defined $parent_nameB= length $parent_name
ABresult
0X0
100
111
848 1400 return $parent_name . '.' . $name;
849 }
850  
851 sub full_accessor {
852 2 ▶ my $field = shift;
Subroutine full_accessor: called CC=6 SCAR=19.1
Pod documented
853  
854 2 my $parent = $field->parent;
855 2 ▶ if( $field->is_contains ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->is_contains) 1 1 2
856 1 ▶ return '' unless $parent;
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 1 1
857 1 return $parent->full_accessor;
858 }
859 1 my $accessor = $field->accessor;
860 1 my $parent_accessor;
861 1 ▶ if ( $parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent) 1 0 1
862 1 $parent_accessor = $parent->full_accessor;
863 }
864 1 ▶ return $accessor unless defined $parent_accessor && length $parent_accessor;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parent_accessor and length $parent_accessor 1 0 1
Condition33%1/3
defined $parent_accessor and length $parent_accessor
!ll&&!rl&&r
010
MC/DC0%0/2
defined $parent_accessor and length $parent_accessor
defined $parent_accessor length $parent_accessor
Truth table33%1/3
A and B
A= defined $parent_accessorB= length $parent_accessor
ABresult
0X0
100
111
865 0 return $parent_accessor . '.' . $accessor;
866 }
867  
868 sub add_error {
869 194 ▶ my ( $self, @message ) = @_;
Subroutine add_error: called CC=4 SCAR=13.9
Pod documented
870  
871 194 ▶ unless ( defined $message[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $message[0]) 1 193 194
872 1 @message = ( $class_messages->{field_invalid});
873 }
874 194 ▶ if ( ref $message[0] eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $message[0] eq "ARRAY") 1 193 194
875 # The list-or-arrayref spelling here is the same convenience idiom as
876 # add_element_class and friends. It is not documented for add_error,
877 # nothing in the distribution reaches it, and what does reach it is
878 # request data: $field->add_error($field->value), where the request
879 # parser folded a duplicate parameter into an arrayref, puts submitted
880 # text in element 0 -- which _localize hands to Locale::Maketext as the
881 # FORMAT. Dereference as before, but if element 0 could be parsed as a
882 # bracket group, pass it as an inert argument instead of as the format.
883 # A caller who really wants a compiled template passes it as a plain
884 # list, $field->add_error($template, @args), which is the documented
885 # spelling and is unchanged.
886 1 my @args = @{ $message[0] };
887 # Interpolate explicitly: '[_1]' alone returns its argument unchanged
888 # (see the note in Validate.pm's _needs_inert_format caller), and the
889 # errors attribute holds strings.
890 1 ▶ @message = $self->_needs_inert_format( $args[0] )
Branch: 1 branch
BranchTrueFalseTotal
$self->_needs_inert_format($args[0]) ? : 1 0 1
891 ? ( '[_1]', "$args[0]" )
892 : @args;
893 }
894 194 my $out;
895 try {
896 194 ▶ $out = $self->_localize(@message);
Subroutine __ANON__: called CC=1 SCAR=0.0
897 }
898 catch {
899 0 ▶ die "Error occurred localizing error message for " . $self->label . ". Check brackets. $_";
Subroutine __ANON__: not called CC=1 SCAR=6.9
900 194 };
901 194 return $self->push_errors($out);;
902 }
903  
904 sub push_errors {
905 194 ▶ my $self = shift;
Subroutine push_errors: called CC=2 SCAR=6.9
Pod undocumented
906 194 $self->_push_errors(@_);
907 194 ▶ if ( $self->parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->parent) 118 76 194
908 118 $self->parent->propagate_error($self->result);
909 }
910 194 return;
911 }
912  
913 sub _apply_deflation {
914 107 ▶ my ( $self, $value ) = @_;
Subroutine _apply_deflation: called CC=3 SCAR=11.0
915  
916 107 ▶ if ( $self->has_deflation ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->has_deflation) { } 1 106 107
elsif ($self->has_deflate_method) { } 106 0 106
917 1 $value = $self->deflation->($value);
918 }
919 elsif ( $self->has_deflate_method ) {
920 106 $value = $self->deflate($value);
921 }
922 107 return $value;
923 }
924 sub _can_deflate {
925 284 ▶ my $self = shift;
Subroutine _can_deflate: called CC=2 SCAR=6.9
926 284 ▶ return $self->has_deflation || $self->has_deflate_method;
Condition100%3/3
$self->has_deflation || $self->has_deflate_method
l!l&&r!l&&!r
1106177
MC/DC100%2/2
$self->has_deflation || $self->has_deflate_method
$self->has_deflation $self->has_deflate_method
Truth table100%3/3
A || B
A= $self->has_deflationB= $self->has_deflate_method
ABresult
1X1
011
000
927 }
928  
929 # use Class::MOP to clone
930 sub clone {
931 665 ▶ my ( $self, %params ) = @_;
Subroutine clone: called CC=1 SCAR=0.0
Pod undocumented
932 665 $self->meta->clone_object( $self, %params );
933 }
934  
935 sub value_changed {
936 0 ▶ my ($self) = @_;
Subroutine value_changed: not called CC=6 SCAR=37.4
Pod undocumented
937  
938 0 my @cmp;
939 0 for ( 'init_value', 'value' ) {
940 0 my $val = $self->$_;
941 0 ▶ $val = '' unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
942 push @cmp, join '|', sort
943 0 ▶ map { ref($_) && $_->isa('DateTime') ? $_->iso8601 : "$_" }
Branch: 2 branches
BranchTrueFalseTotal
ref $_ && $_->isa('DateTime') ? : 0 0 0
ref $val eq 'ARRAY' ? : 0 0 0
Condition0%0/3
ref $_ and $_->isa("DateTime")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ and $_->isa("DateTime")
ref $_ $_->isa("DateTime")
Truth table0%0/3
A and B
A= ref $_B= $_->isa("DateTime")
ABresult
0X0
100
111
944 ref($val) eq 'ARRAY' ? @$val : $val;
945 }
946 0 return $cmp[0] ne $cmp[1];
947 }
948  
949 0 ▶sub required_text { shift->required ? 'required' : 'optional' }
Subroutine required_text: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
(shift())->required ? : 0 0 0
950  
951 sub input_defined {
952 1045 ▶ my ($self) = @_;
Subroutine input_defined: called CC=2 SCAR=7.1
Pod undocumented
953 1045 ▶ return unless $self->has_input;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_input 0 1045 1045
954 1045 return has_some_value( $self->input );
955 }
956  
957 sub dump {
958 0 ▶ my $self = shift;
Subroutine dump: not called CC=8 SCAR=42.8
Pod documented
959  
960 0 require Data::Dumper;
961 0 warn "HFH: ----- ", $self->name, " -----\n";
962 0 warn "HFH: type: ", $self->type, "\n";
963 0 ▶ warn "HFH: required: ", ( $self->required || '0' ), "\n";
Condition0%0/2
$self->required || '0'
l!l
00
MC/DC0%0/1
$self->required || '0'
$self->required
Truth table0%0/2
A
A= $self->required
Aresult
11
00
964 0 warn "HFH: label: ", $self->label, "\n";
965 0 ▶ warn "HFH: widget: ", $self->widget || '', "\n";
Condition0%0/2
$self->widget || ''
l!l
00
MC/DC0%0/1
$self->widget || ''
$self->widget
Truth table0%0/2
A
A= $self->widget
Aresult
11
00
966 0 my $v = $self->value;
967 0 ▶ warn "HFH: value: ", Data::Dumper::Dumper($v) if $v;
Branch: 1 branch
BranchTrueFalseTotal
if $v 0 0 0
968 0 my $iv = $self->init_value;
969 0 ▶ warn "HFH: init_value: ", Data::Dumper::Dumper($iv) if $iv;
Branch: 1 branch
BranchTrueFalseTotal
if $iv 0 0 0
970 0 my $i = $self->input;
971 0 ▶ warn "HFH: input: ", Data::Dumper::Dumper($i) if $i;
Branch: 1 branch
BranchTrueFalseTotal
if $i 0 0 0
972 0 my $fif = $self->fif;
973 0 ▶ warn "HFH: fif: ", Data::Dumper::Dumper($fif) if $fif;
Branch: 1 branch
BranchTrueFalseTotal
if $fif 0 0 0
974  
975 0 ▶ if ( $self->can('options') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("options")) 0 0 0
976 0 my $o = $self->options;
977 0 warn "HFH: options: " . Data::Dumper::Dumper($o);
978 }
979 }
980  
981 sub apply_rendering_widgets {
982 0 ▶ my $self = shift;
Subroutine apply_rendering_widgets: not called CC=6 SCAR=37.4
Pod undocumented
983  
984 0 ▶ if ( $self->widget ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->widget) 0 0 0
985 0 warn "in apply_rendering_widgets " . $self->widget . " Field\n";
986 0 $self->apply_widget_role( $self, $self->widget, 'Field' );
987 }
988 0 my $widget_wrapper = $self->widget_wrapper;
989 0 ▶ $widget_wrapper ||= $self->form->widget_wrapper if $self->form;
Branch: 1 branch
BranchTrueFalseTotal
if $self->form 0 0 0
Condition0%0/3
$widget_wrapper ||= $self->form->widget_wrapper
l!l&&r!l&&!r
000
MC/DC0%0/2
$widget_wrapper ||= $self->form->widget_wrapper
$widget_wrapper $self->form->widget_wrapper
Truth table0%0/3
A ||= B
A= $widget_wrapperB= $self->form->widget_wrapper
ABresult
1X1
011
000
990 0 ▶ $widget_wrapper ||= 'Simple';
Condition0%0/2
$widget_wrapper ||= "Simple"
l!l
00
MC/DC0%0/1
$widget_wrapper ||= "Simple"
$widget_wrapper
Truth table0%0/2
A
A= $widget_wrapper
Aresult
11
00
991 0 ▶ unless ( $widget_wrapper eq 'none' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($widget_wrapper eq "none") 0 0 0
992 0 $self->apply_widget_role( $self, $widget_wrapper, 'Wrapper' );
993 }
994 0 return;
995  
996 }
997  
998 sub peek {
999 0 ▶ my ( $self, $indent ) = @_;
Subroutine peek: not called CC=6 SCAR=37.4
Pod undocumented
1000  
1001 0 ▶ $indent ||= '';
Condition0%0/2
$indent ||= ""
l!l
00
MC/DC0%0/1
$indent ||= ""
$indent
Truth table0%0/2
A
A= $indent
Aresult
11
00
1002 0 my $string = $indent . 'field: "' . $self->name . '" type: ' . $self->type . "\n";
1003 0 ▶ if( $self->has_flag('has_contains') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_flag("has_contains")) 0 0 0
1004 0 $string .= $indent . "contains: \n";
1005 0 my $lindent = $indent . ' ';
1006 0 foreach my $field ( $self->contains->sorted_fields ) {
1007 0 $string .= $field->peek( $lindent );
1008 }
1009 }
1010 0 ▶ if( $self->has_fields ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_fields) 0 0 0
1011 0 $string .= $indent . 'subfields of "' . $self->name . '": ' . $self->num_fields . "\n";
1012 0 my $lindent = $indent . ' ';
1013 0 foreach my $field ( $self->sorted_fields ) {
1014 0 $string .= $field->peek( $lindent );
1015 }
1016 }
1017 0 return $string;
1018 }
1019  
1020 sub has_some_value {
1021 1209 ▶ my $x = shift;
Subroutine has_some_value: called CC=11 SCAR=24.5
Pod undocumented
1022  
1023 1209 ▶ return unless defined $x;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $x 12 1197 1209
1024 1197 ▶ return $x =~ /\S/ if !ref $x;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $x 1036 161 1197
1025 161 ▶ if ( ref $x eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x eq "ARRAY") 39 122 161
1026 39 for my $elem (@$x) {
1027 32 ▶ return 1 if has_some_value($elem);
Branch: 1 branch
BranchTrueFalseTotal
if has_some_value($elem) 28 4 32
1028 }
1029 11 return 0;
1030 }
1031 122 ▶ if ( ref $x eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x eq "HASH") 119 3 122
1032 119 for my $key ( keys %$x ) {
1033 130 ▶ return 1 if has_some_value( $x->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
if has_some_value($x->{$key}) 109 21 130
1034 }
1035 10 return 0;
1036 }
1037 3 ▶ return 1 if blessed($x); # true if blessed, otherwise false
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($x) 3 0 3
1038 0 ▶ return 1 if ref( $x );
Branch: 1 branch
BranchTrueFalseTotal
if ref $x 0 0 0
1039 0 return;
1040 }
1041  
1042 sub apply_traits {
1043 1 ▶ my ($class, @traits) = @_;
Subroutine apply_traits: called CC=1 SCAR=0.0
Pod undocumented
1044  
1045 1 $class->meta->make_mutable;
1046 1 Moose::Util::apply_all_roles($class->meta, @traits);
1047 1 $class->meta->make_immutable;
1048 }
1049  
1050 148 __PACKAGE__->meta->make_immutable;
1051 148 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
1052 148 1;
1053  
1054 __END__
1055  
1056 =pod
1057  
1058 =encoding UTF-8
1059  
1060 =head1 NAME
1061  
1062 HTML::FormHandler::Field - base class for fields
1063  
1064 =head1 VERSION
1065  
1066 version 0.410001
1067  
1068 =head1 SYNOPSIS
1069  
1070 Instances of Field subclasses are generally built by L<HTML::FormHandler>
1071 from 'has_field' declarations or the field_list, but they can also be constructed
1072 using new for test purposes (since there's no standard way to add a field to a form
1073 after construction).
1074  
1075 use HTML::FormHandler::Field::Text;
1076 my $field = HTML::FormHandler::Field::Text->new( name => $name, ... );
1077  
1078 In your custom field class:
1079  
1080 package MyApp::Field::MyText;
1081 use HTML::FormHandler::Moose;
1082 extends 'HTML::FormHandler::Field::Text';
1083  
1084 has 'my_attribute' => ( isa => 'Str', is => 'rw' );
1085  
1086 apply [ { transform => sub { ... } },
1087 { check => ['fighter', 'bard', 'mage' ], message => '....' }
1088 ];
1089 1;
1090  
1091 =head1 DESCRIPTION
1092  
1093 This is the base class for form fields. The 'type' of a field class
1094 is used in the FormHandler field_list or has_field to identify which field class to
1095 load from the 'field_name_space' (or directly, when prefixed with '+').
1096 If the type is not specified, it defaults to Text.
1097  
1098 See L<HTML::FormHandler::Manual::Fields> for a list of the fields and brief
1099 descriptions of their structure.
1100  
1101 =head1 ATTRIBUTES
1102  
1103 =head2 Names, types, accessor
1104  
1105 =over
1106  
1107 =item name
1108  
1109 The name of the field. Used in the HTML form. Often a db accessor.
1110 The only required attribute.
1111  
1112 =item type
1113  
1114 The class or type of the field. The 'type' of L<HTML::FormHandler::Field::Money>
1115 is 'Money'. Classes that you define yourself are prefixed with '+'.
1116  
1117 =item accessor
1118  
1119 If the name of your field is different than your database accessor, use
1120 this attribute to provide the accessor.
1121  
1122 =item full_name
1123  
1124 The name of the field with all parents:
1125  
1126 'event.start_date.month'
1127  
1128 =item full_accessor
1129  
1130 The field accessor with all parents.
1131  
1132 =item html_name
1133  
1134 The full_name plus the form name if 'html_prefix' is set.
1135  
1136 =item input_param
1137  
1138 By default we expect an input parameter based on the field name. This allows
1139 you to look for a different input parameter.
1140  
1141 =back
1142  
1143 =head2 Field data
1144  
1145 =over
1146  
1147 =item inactive, is_inactive, is_active
1148  
1149 Set the 'inactive' attribute to 1 if this field is inactive. The 'inactive' attribute
1150 that isn't set or is set to 0 will make a field 'active'.
1151 This provides a way to define fields in the form and selectively set them to inactive.
1152 There is also an '_active' attribute, for internal use to indicate that the field has
1153 been activated/inactivated on 'process' by the form's 'active'/'inactive' attributes.
1154  
1155 You can use the is_inactive and is_active methods to check whether this particular
1156 field is active.
1157  
1158 if( $form->field('foo')->is_active ) { ... }
1159  
1160 =item input
1161  
1162 The input string from the parameters passed in.
1163  
1164 =item value
1165  
1166 The value as it would come from or go into the database, after being
1167 acted on by inflations/deflations and transforms. Used to construct the
1168 C<< $form->values >> hash. Validation and constraints act on 'value'.
1169  
1170 See also L<HTML::FormHandler::Manual::InflationDeflation>.
1171  
1172 =item fif
1173  
1174 Values used to fill in the form. Read only. Use a deflation to get
1175 from 'value' to 'fif' if an inflator was used. Use 'fif_from_value'
1176 attribute if you want to use the field 'value' to fill in the form.
1177  
1178 [% form.field('title').fif %]
1179  
1180 =item init_value
1181  
1182 Initial value populated by init_from_object. You can tell if a field
1183 has changed by comparing 'init_value' and 'value'. Read only.
1184  
1185 =item input_without_param
1186  
1187 Input for this field if there is no param. Set by default for Checkbox,
1188 and Select, since an unchecked checkbox or unselected pulldown
1189 does not return a parameter.
1190  
1191 =back
1192  
1193 =head2 Form, parent
1194  
1195 =over
1196  
1197 =item form
1198  
1199 A reference to the containing form.
1200  
1201 =item parent
1202  
1203 A reference to the parent of this field. Compound fields are the
1204 parents for the fields they contain.
1205  
1206 =back
1207  
1208 =head2 Errors
1209  
1210 =over
1211  
1212 =item errors
1213  
1214 Returns the error list for the field. Also provides 'num_errors',
1215 'has_errors', 'push_errors' and 'clear_errors' from Array
1216 trait. Use 'add_error' to add an error to the array if you
1217 want to use a MakeText language handle. Default is an empty list.
1218  
1219 =item add_error
1220  
1221 Add an error to the list of errors. Error message will be localized
1222 using '_localize' method.
1223 See also L<HTML::FormHandler::TraitFor::I18N>.
1224  
1225 return $field->add_error( 'bad data' ) if $bad;
1226  
1227 The first argument is the localization FORMAT, which for a
1228 L<Locale::Maketext> handle means bracket notation in it is compiled and
1229 executed. Do not build that argument out of submitted data: a value
1230 containing a C<[...]> group would be run as a method call rather than
1231 shown. Pass the value as an argument instead, where it is inert:
1232  
1233 # wrong -- the submitted value becomes part of the format
1234 $field->add_error( "The value '" . $field->value . "' is not allowed" );
1235  
1236 # right -- the format is yours, the value is just an argument
1237 $field->add_error( "The value '[_1]' is not allowed", $field->value );
1238  
1239 Also note that the first argument is cached by L<Locale::Maketext>,
1240 without any size limits or purging of data. Passing error messages in
1241 the first argument that contain text submitted over the network opens
1242 up a system to memory consumption attacks.
1243  
1244 =item error_fields
1245  
1246 Compound fields will have an array of errors from the subfields.
1247  
1248 =item localize_meth
1249  
1250 Set the method used to localize.
1251  
1252 =back
1253  
1254 =head2 Attributes for creating HTML
1255  
1256 The 'element_attr' hashref attribute can be used to set
1257 arbitrary HTML attributes on a field's input tag.
1258  
1259 has_field 'foo' => ( element_attr => { readonly => 1, my_attr => 'abc' } );
1260  
1261 Note that the 'id' and 'type' attributes are not set using element_attr. Use
1262 the field's 'id' attribute (or 'build_id_method') to set the id.
1263  
1264 The 'label_attr' hashref is for label attributes, and the 'wrapper_attr'
1265 is for attributes on the wrapping element (a 'div' for the standard 'simple'
1266 wrapper).
1267  
1268 A 'javascript' key in one of the '_attr' hashes will be inserted into the
1269 element as-is.
1270  
1271 The following are used in rendering HTML, but are handled specially.
1272  
1273 label - Text label for this field. Defaults to ucfirst field name.
1274 build_label_method - coderef for constructing the label
1275 wrap_label_method - coderef for constructing a wrapped label
1276 id - Useful for javascript (default is html_name. to prefix with
1277 form name, use 'html_prefix' in your form)
1278 build_id_method - coderef for constructing the id
1279 render_filter - Coderef for filtering fields before rendering. By default
1280 changes >, <, &, " to the html entities
1281 disabled - Boolean to set field disabled
1282  
1283 The order attribute may be used to set the order in which fields are rendered.
1284  
1285 order - Used for sorting errors and fields. Built automatically,
1286 but may also be explicitly set
1287  
1288 The following are discouraged. Use 'element_attr', 'label_attr', and 'wrapper_attr'
1289 instead.
1290  
1291 title - instead use element_attr => { title => '...' }
1292 style - instead use element_attr => { style => '...' }
1293 tabindex - instead use element_attr => { tabindex => 1 }
1294 readonly - instead use element_attr => { readonly => 'readonly' }
1295  
1296 Rendering of the various HTML attributes is done by calling the 'process_attrs'
1297 function (from HTML::FormHandler::Render::Util) and passing in a method that
1298 adds in error classes, provides backward compatibility with the deprecated
1299 attributes, etc.
1300  
1301 attribute hashref class attribute wrapping method
1302 ================= ================= ================
1303 element_attr element_class element_attributes
1304 label_attr label_class label_attributes
1305 wrapper_attr wrapper_class wrapper_attributes
1306 element_wrapper_class element_wrapper_attributes
1307  
1308 ('element_wrapper' is for an inner div around the input element, not
1309 including the label. Used for Bootstrap3 rendering, but also available
1310 in the Simple wrapper.)
1311 The slots for the class attributes are arrayrefs; they will coerce a
1312 string into an arrayref.
1313 In addition, these 'wrapping methods' call a hook method in the form class,
1314 'html_attributes', which you can use to customize and localize the various
1315 attributes. (Field types: 'element', 'wrapper', 'label')
1316  
1317 sub html_attributes {
1318 my ( $self, $field, $type, $attr ) = @_;
1319 $attr->{class} = 'label' if $type eq 'label';
1320 return $attr;
1321 }
1322  
1323 The 'process_attrs' function will also handle an array of strings, such as for the
1324 'class' attribute.
1325  
1326 =head2 tags
1327  
1328 A hashref containing flags and strings for use in the rendering code.
1329 The value of a tag can be a string, a coderef (accessed as a method on the
1330 field) or a block specified with a percent followed by the blockname
1331 ('%blockname').
1332  
1333 Retrieve a tag with 'get_tag'. It returns a '' if the tag doesn't exist.
1334  
1335 This attribute used to be named 'widget_tags', which is deprecated.
1336  
1337 =head2 html5_type_attr [string]
1338  
1339 This string is used when rendering an input element as the value for the type attribute.
1340 It is used when the form has the is_html5 flag on.
1341  
1342 =head2 widget
1343  
1344 The 'widget' attribute is used in rendering, so if you are
1345 not using FormHandler's rendering facility, you don't need this
1346 attribute. It is used in generating HTML, in templates and the
1347 rendering roles. Fields of different type can use the same widget.
1348  
1349 This attribute is set in the field classes, or in the fields
1350 defined in the form. If you want a new widget type, create a
1351 widget role, such as MyApp::Form::Widget::Field::MyWidget. Provide
1352 the name space in the 'widget_name_space' attribute, and set
1353 the 'widget' of your field to the package name after the
1354 Field/Form/Wrapper:
1355  
1356 has_field 'my_field' => ( widget => 'MyWidget' );
1357  
1358 If you are using a template based rendering system you will want
1359 to create a widget template.
1360 (see L<HTML::FormHandler::Manual::Templates>)
1361  
1362 Widget types for some of the provided field classes:
1363  
1364 Widget : Field classes
1365 -----------------------:---------------------------------
1366 Text : Text, Integer
1367 Checkbox : Checkbox, Boolean
1368 RadioGroup : Select, Multiple, IntRange (etc)
1369 Select : Select, Multiple, IntRange (etc)
1370 CheckboxGroup : Multiple select
1371 TextArea : TextArea
1372 Compound : Compound, Repeatable, DateTime
1373 Password : Password
1374 Hidden : Hidden
1375 Submit : Submit
1376 Reset : Reset
1377 NoRender :
1378 Upload : Upload
1379  
1380 Widget roles are automatically applied to field classes
1381 unless they already have a 'render' method, and if the
1382 'no_widgets' flag in the form is not set.
1383  
1384 You can create your own widget roles and specify the namespace
1385 in 'widget_name_space'. In the form:
1386  
1387 has '+widget_name_space' => ( default => sub { ['MyApp::Widget'] } );
1388  
1389 If you want to use a fully specified role name for a widget, you
1390 can prefix it with a '+':
1391  
1392 widget => '+MyApp::Widget::SomeWidget'
1393  
1394 For more about widgets, see L<HTML::FormHandler::Manual::Rendering>.
1395  
1396 =head2 Flags
1397  
1398 password - prevents the entered value from being displayed in the form
1399 writeonly - The initial value is not taken from the database
1400 noupdate - Do not update this field in the database (does not appear in $form->value)
1401  
1402 =head2 Defaults
1403  
1404 See also the documentation on L<HTML::FormHandler::Manual::Intro/Defaults>.
1405  
1406 =over
1407  
1408 =item default_method, set_default
1409  
1410 Supply a coderef (which will be a method on the field) with 'default_method'
1411 or the name of a form method with 'set_default' (which will be a method on
1412 the form). If not specified and a form method with a name of
1413 C<< default_<field_name> >> exists, it will be used.
1414  
1415 =item default
1416  
1417 Provide an initial value just like the 'set_default' method, except in the field
1418 declaration:
1419  
1420 has_field 'bax' => ( default => 'Default bax' );
1421  
1422 FormHandler has flipped back and forth a couple of times about whether a default
1423 specified in the has_field definition should override values provided in an
1424 initial item or init_object. Sometimes people want one behavior, and sometimes
1425 the other. Now 'default' does *not* override.
1426  
1427 If you pass in a model object with C<< item => $row >> or an initial object
1428 with C<< init_object => {....} >> the values in that object will be used instead
1429 of values provided in the field definition with 'default' or 'default_fieldname'.
1430 If you want defaults that override or supplement the item/init_object, you can use the form
1431 flags 'use_defaults_over_obj', 'use_init_obj_over_item', and
1432 'use_init_obj_when_no_accessor_in_item'.
1433  
1434 You could also put your defaults into your row or init_object instead.
1435  
1436 =item default_over_obj
1437  
1438 This is deprecated; look into using 'use_defaults_over_obj' or 'use_init_obj_over_item'
1439 flags instead. They allow using the standard 'default' attribute.
1440  
1441 Allows setting defaults which will override values provided with an item/init_object.
1442 (And only those. Will not be used for defaults without an item/init_object.)
1443  
1444 has_field 'quux' => ( default_over_obj => 'default quux' );
1445  
1446 At this time there is no equivalent of 'set_default', but the type of the attribute
1447 is not defined so you can provide default values in a variety of other ways,
1448 including providing a trait which does 'build_default_over_obj'. For examples,
1449 see tests in the distribution.
1450  
1451 =back
1452  
1453 =head1 Constraints and Validations
1454  
1455 See also L<HTML::FormHandler::Manual::Validation>.
1456  
1457 =head2 Constraints set in attributes
1458  
1459 =over
1460  
1461 =item required
1462  
1463 Flag indicating whether this field must have a value
1464  
1465 =item unique
1466  
1467 For DB field - check for uniqueness. Action is performed by
1468 the DB model.
1469  
1470 =item messages
1471  
1472 messages => { required => '...', unique => '...' }
1473  
1474 Set messages created by FormHandler by setting in the 'messages'
1475 hashref. Some field subclasses have additional settable messages.
1476  
1477 required: Error message text added to errors if required field is not present.
1478 The default is "Field <field label> is required".
1479  
1480 =item range_start
1481  
1482 =item range_end
1483  
1484 Field values are validated against the specified range if one
1485 or both of range_start and range_end are set and the field
1486 does not have 'options'.
1487  
1488 The IntRange field uses this range to create a select list
1489 with a range of integers.
1490  
1491 In a FormHandler field_list:
1492  
1493 age => {
1494 type => 'Integer',
1495 range_start => 18,
1496 range_end => 120,
1497 }
1498  
1499 =item not_nullable
1500  
1501 Fields that contain 'empty' values such as '' are changed to undef in the validation process.
1502 If this flag is set, the value is not changed to undef. If your database column requires
1503 an empty string instead of a null value (such as a NOT NULL column), set this attribute.
1504  
1505 has_field 'description' => (
1506 type => 'TextArea',
1507 not_nullable => 1,
1508 );
1509  
1510 This attribute is also used when you want an empty array to stay an empty array and not
1511 be set to undef.
1512  
1513 It's also used when you have a compound field and you want the 'value' returned
1514 to contain subfields with undef, instead of the whole field to be undef.
1515  
1516 =back
1517  
1518 =head2 apply
1519  
1520 Use the 'apply' keyword to specify an ArrayRef of constraints and coercions to
1521 be executed on the field at validate_field time.
1522  
1523 has_field 'test' => (
1524 apply => [ 'MooseType',
1525 { check => sub {...}, message => { } },
1526 { transform => sub { ... lc(shift) ... } }
1527 ],
1528 );
1529  
1530 See more documentation in L<HTML::FormHandler::Manual::Validation>.
1531  
1532 =head2 trim
1533  
1534 An action to trim the field. By default
1535 this contains a transform to strip beginning and trailing spaces.
1536 Set this attribute to null to skip trimming, or supply a different
1537 transform.
1538  
1539 trim => { transform => sub {
1540 my $string = shift;
1541 $string =~ s/^\s+//;
1542 $string =~ s/\s+$//;
1543 return $string;
1544 } }
1545 trim => { type => MyTypeConstraint }
1546  
1547 Trimming is performed before any other defined actions.
1548  
1549 =head2 Inflation/deflation
1550  
1551 There are a number of methods to provide finely tuned inflation and deflation:
1552  
1553 =over 4
1554  
1555 =item inflate_method
1556  
1557 Inflate to a data format desired for validation.
1558  
1559 =item deflate_method
1560  
1561 Deflate to a string format for presenting in HTML.
1562  
1563 =item inflate_default_method
1564  
1565 Modify the 'default' provided by an 'item' or 'init_object'.
1566  
1567 =item deflate_value_method
1568  
1569 Modify the value returned by C<< $form->value >>.
1570  
1571 =item deflation
1572  
1573 Another way of providing a deflation method.
1574  
1575 =item transform
1576  
1577 Another way of providing an inflation method.
1578  
1579 =back
1580  
1581 Normally if you have a deflation, you will need a matching inflation.
1582 There are two different flavors of inflation/deflation: one for inflating values
1583 to a format needed for validation and deflating for output, the other for
1584 inflating the initial provided values (usually from a database row) and deflating
1585 them for the 'values' returned.
1586  
1587 See L<HTML::FormHandler::Manual::InflationDeflation>.
1588  
1589 =head1 Processing and validating the field
1590  
1591 =head2 validate_field
1592  
1593 This is the base class validation routine. Most users will not
1594 do anything with this. It might be useful for method modifiers,
1595 if you want code that executed before or after the validation
1596 process.
1597  
1598 =head2 validate
1599  
1600 This field method can be used in addition to or instead of 'apply' actions
1601 in custom field classes.
1602 It should validate the field data and set error messages on
1603 errors with C<< $field->add_error >>.
1604  
1605 sub validate {
1606 my $field = shift;
1607 my $value = $field->value;
1608 return $field->add_error( ... ) if ( ... );
1609 }
1610  
1611 =head2 validate_method, set_validate
1612  
1613 Supply a coderef (which will be a method on the field) with 'validate_method'
1614 or the name of a form method with 'set_validate' (which will be a method on
1615 the form). If not specified and a form method with a name of
1616 C<< validate_<field_name> >> exists, it will be used.
1617  
1618 Periods in field names will be replaced by underscores, so that the field
1619 'addresses.city' will use the 'validate_addresses_city' method for validation.
1620  
1621 has_field 'my_foo' => ( validate_method => \&my_foo_validation );
1622 sub my_foo_validation { ... }
1623 has_field 'title' => ( isa => 'Str', set_validate => 'check_title' );
1624  
1625 =head1 AUTHOR
1626  
1627 FormHandler Contributors - see HTML::FormHandler
1628  
1629 =head1 COPYRIGHT AND LICENSE
1630  
1631 This software is copyright (c) 2017 by Gerda Shank.
1632  
1633 This is free software; you can redistribute it and/or modify it under
1634 the same terms as the Perl 5 programming language system itself.
1635  
1636 =cut
« FormHandler/Blocks.pm ↑ Summary FormHandler/Fields.pm »