FormHandler/Field.pm

filter: Statementstmt 83.6% 454 / 543 Branchbran 69.2% 187 / 270 Conditioncond 62.7% 96 / 153 MC/DCmcdc 40.0% 36 / 90 Subroutinesub 84.0% 95 / 113 Podpod 13.1% 11 / 84 totaltotal 70.1% 879 / 1253 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 149 $HTML::FormHandler::Field::VERSION = '0.410002';
4 149 ▶use HTML::FormHandler::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 149 ▶use HTML::FormHandler::Field::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 149 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 149 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 149 ▶use HTML::FormHandler::Merge ('merge');
Subroutine BEGIN: called CC=1 SCAR=0.0
9 149 ▶use HTML::FormHandler::Render::Util('cc_widget', 'ucc_widget');
Subroutine BEGIN: called CC=1 SCAR=0.0
10 149 ▶use Sub::Name;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 149 with 'HTML::FormHandler::Traits';
13 149 with 'HTML::FormHandler::Validate';
14 149 with 'HTML::FormHandler::Widget::ApplyRole';
15 149 with 'HTML::FormHandler::TraitFor::Types';
16  
17  
18 149 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 149 has 'parent' => ( is => 'rw', predicate => 'has_parent', weak_ref => 1 );
21 505 ▶sub has_fields { }
Subroutine has_fields: called CC=1 SCAR=0.0
Pod undocumented
22 149 has 'input_without_param' => (
23 is => 'rw',
24 predicate => 'has_input_without_param'
25 );
26 149 has 'not_nullable' => ( is => 'rw', isa => 'Bool' );
27 149 has 'no_value_if_empty' => ( is => 'rw', isa => 'Bool' );
28 149 has 'validate_when_empty' => ( is => 'rw', isa => 'Bool' );
29 149 has 'init_value' => ( is => 'rw', clearer => 'clear_init_value', predicate => 'has_init_value' );
30 149 has 'default' => ( is => 'rw' );
31 149 has 'default_over_obj' => ( is => 'rw', builder => 'build_default_over_obj' );
32 1184 ▶sub build_default_over_obj { }
Subroutine build_default_over_obj: called CC=1 SCAR=0.0
Pod undocumented
33 149 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 149 has '_pin_result' => ( is => 'ro', reader => '_get_pin_result', writer => '_set_pin_result' );
48  
49 4793 ▶sub has_input {
Subroutine has_input: called CC=3 SCAR=12.5
Pod undocumented
50 4793 my $self = shift;
51 4793 ▶ return unless $self->has_result and $self->result;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_result and $self->result 0 4793 4793
Condition33%1/3
$self->has_result and $self->result
!ll&&!rl&&r
004793
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 4793 return $self->result->has_input;
53 }
54  
55 2402 ▶sub has_value {
Subroutine has_value: called CC=3 SCAR=12.5
Pod undocumented
56 2402 my $self = shift;
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 13 ▶sub reset_result {
Subroutine reset_result: called CC=1 SCAR=0.0
Pod undocumented
63 13 my $self = shift;
64 13 $self->clear_result;
65 13 $self->build_result;
66 }
67 53 ▶sub build_result {
Subroutine build_result: called CC=3 SCAR=11.6
Pod undocumented
68 53 my $self = shift;
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 1891 ▶sub input {
Subroutine input: called CC=5 SCAR=16.2
Pod documented
82 1891 my $self = shift;
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 7804 ▶sub value {
Subroutine value: called CC=5 SCAR=16.2
Pod documented
93 7804 my $self = shift;
94  
95 # allow testing fields individually by creating result if no form
96 7804 ▶ return undef unless $self->has_result || !$self->form;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_result or not $self->form 10 7794 7804
Condition66%2/3
$self->has_result or not $self->form
l!l&&r!l&&!r
7794010
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 7794 my $result = $self->result;
98 7794 ▶ return undef unless $result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 7794 7794
99 7794 ▶ return $result->_set_value(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 8 7786 7794
100 7786 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 519 ▶sub clear_data {
Subroutine clear_data: called CC=1 SCAR=0.0
Pod undocumented
106 519 my $self = shift;
107 519 $self->clear_result;
108 519 $self->clear_active;
109 }
110 # this is a kludge to allow testing field deflation
111 2 ▶sub _deflate_and_set_value {
Subroutine _deflate_and_set_value: called CC=2 SCAR=7.0
112 2 my ( $self, $value ) = @_;
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 1465 ▶sub is_repeatable { }
Subroutine is_repeatable: called CC=1 SCAR=0.0
Pod undocumented
120  
121 149 has 'fif_from_value' => ( isa => 'Str', is => 'ro' );
122  
123 1546 ▶sub fif {
Subroutine fif: called CC=18 SCAR=29.2
Pod documented
124 1546 my ( $self, $result ) = @_;
125  
126 1546 ▶ return if ( $self->inactive && !$self->_active );
Branch: 1 branch
BranchTrueFalseTotal
if $self->inactive and not $self->_active 0 1546 1546
Condition66%2/3
$self->inactive and not $self->_active
!ll&&!rl&&r
153970
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 1546 ▶ return '' if $self->password;
Branch: 1 branch
BranchTrueFalseTotal
if $self->password 8 1538 1546
128 1538 ▶ return unless $result || $self->has_result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result or $self->has_result 1 1537 1538
Condition100%3/3
$result or $self->has_result
l!l&&r!l&&!r
13461911
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 1537 ▶ my $lresult = $result || $self->result;
Condition66%2/3
$result || $self->result
l!l&&r!l&&!r
13461910
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 1537 ▶ return unless $lresult;
Branch: 1 branch
BranchTrueFalseTotal
unless $lresult 0 1537 1537
131 1537 ▶ 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 863 1537
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
6740863
$self->has_result and $self->has_input and not $self->fif_from_value
!ll&&!rl&&r
8585674
$self->has_result and $self->has_input
!ll&&!rl&&r
38820679
$self->fif_from_value and not defined $lresult->value
!ll&&!rl&&r
85760
MC/DC60%3/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 table50%5/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 863 ▶ if ( $lresult->has_value ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($lresult->has_value) { } 286 577 863
elsif (defined $self->value) { } 9 568 577
137 286 my $value;
138 286 ▶ if( $self->_can_deflate ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_can_deflate) { } 109 177 286
139 109 $value = $self->_apply_deflation($lresult->value);
140 }
141 else {
142 177 $value = $lresult->value;
143 }
144 286 ▶ return ( defined $value ? $value : '' );
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 286 0 286
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 568 return '';
152 }
153  
154 has 'accessor' => (
155 isa => 'Str',
156 is => 'rw',
157 lazy => 1,
158 746 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
159 746 my $self = shift;
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 149 );
165 149 has 'is_contains' => ( is => 'rw', isa => 'Bool' );
166 149 has 'temp' => ( is => 'rw' );
167  
168 3012 ▶sub has_flag {
Subroutine has_flag: called CC=2 SCAR=6.9
Pod undocumented
169 3012 my ( $self, $flag_name ) = @_;
170 3012 ▶ return unless $self->can($flag_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($flag_name) 1215 1797 3012
171 1797 return $self->$flag_name;
172 }
173  
174 149 has 'label' => (
175 isa => 'Maybe[Str]',
176 is => 'rw',
177 lazy => 1,
178 builder => 'build_label',
179 );
180 149 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 1186 ▶ default => sub { \&default_build_label },
Subroutine __ANON__: called CC=1 SCAR=0.0
184 149 );
185 384 ▶sub default_build_label {
Subroutine default_build_label: called CC=1 SCAR=0.0
Pod undocumented
186 384 my $self = shift;
187 384 my $label = $self->name;
188 384 $label =~ s/_/ /g;
189 384 $label = ucfirst($label);
190 384 return $label;
191 }
192 559 ▶sub loc_label {
Subroutine loc_label: called CC=1 SCAR=0.0
Pod undocumented
193 559 my $self = shift;
194 559 return $self->_localize($self->label);
195 }
196 149 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 149 has 'title' => ( isa => 'Str', is => 'rw' );
204 149 has 'style' => ( isa => 'Str', is => 'rw' );
205 149 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 149 has 'html_name' => (
213 isa => 'Str',
214 is => 'rw',
215 lazy => 1,
216 builder => 'build_html_name'
217 );
218  
219 514 ▶sub build_html_name {
Subroutine build_html_name: called CC=3 SCAR=12.5
Pod undocumented
220 514 my $self = shift;
221 514 ▶ my $prefix = ( $self->form && $self->form->html_prefix ) ? $self->form->name . "." : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->form && $self->form->html_prefix ? : 0 514 514
Condition33%1/3
$self->form and $self->form->html_prefix
!ll&&!rl&&r
05140
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 514 return $prefix . $self->full_name;
223 }
224 149 has 'widget' => ( isa => 'Str', is => 'rw' );
225 149 has 'widget_wrapper' => ( isa => 'Str', is => 'rw' );
226 149 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" 83 0 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" 16 0 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 149 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 1167 ▶sub build_wrapper_tags { {} }
Subroutine build_wrapper_tags: called CC=1 SCAR=0.0
Pod undocumented
243 149 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 1070 ▶sub build_tags {{}}
Subroutine build_tags: called CC=1 SCAR=0.0
Pod undocumented
257 20 ▶sub merge_tags {
Subroutine merge_tags: called CC=1 SCAR=0.0
Pod undocumented
258 20 my ( $self, $new ) = @_;
259 20 my $old = $self->tags;
260 20 $self->tags( merge($new, $old) );
261 }
262 6919 ▶sub get_tag {
Subroutine get_tag: called CC=6 SCAR=18.5
Pod undocumented
263 6919 my ( $self, $name ) = @_;
264 6919 ▶ return '' unless $self->tag_exists($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->tag_exists($name) 6798 121 6919
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 1187 ▶ default => sub {[]},
Subroutine __ANON__: called CC=1 SCAR=0.0
279 149 coerce => 1,
280 handles => {
281 push_widget_name_space => 'push',
282 },
283 );
284  
285 1117 ▶sub add_widget_name_space {
Subroutine add_widget_name_space: called CC=3 SCAR=12.0
Pod undocumented
286 1117 my ( $self, @ns ) = @_;
287 1117 ▶ @ns = @{$ns[0]}if( scalar @ns && ref $ns[0] eq 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @ns and ref $ns[0] eq "ARRAY" 1117 0 1117
Condition33%1/3
scalar @ns and ref $ns[0] eq "ARRAY"
!ll&&!rl&&r
001117
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 1117 $self->push_widget_name_space(@ns);
289 }
290  
291 149 has 'order' => ( isa => 'Int', is => 'rw', default => 0 );
292 # 'inactive' is set in the field declaration, and is static. Default status.
293 149 has 'inactive' => ( isa => 'Bool', is => 'rw', clearer => 'clear_inactive' );
294 # 'active' is cleared whenever the form is cleared. Ephemeral activation.
295 149 has '_active' => ( isa => 'Bool', is => 'rw', clearer => 'clear_active', predicate => 'has__active' );
296 2793 ▶sub is_active {
Subroutine is_active: called CC=1 SCAR=0.0
Pod documented
297 2793 my $self = shift;
298 2793 return ! $self->is_inactive;
299 }
300 4703 ▶sub is_inactive {
Subroutine is_inactive: called CC=5 SCAR=16.1
Pod documented
301 4703 my $self = shift;
302 4703 ▶ 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
5524646
$self->inactive and not $self->_active
!ll&&!rl&&r
46321655
not $self->inactive and $self->has__active and $self->_active == 0
!ll&&!rl&&r
464602
not $self->inactive and $self->has__active
!ll&&!rl&&r
1646302
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 149 has 'id' => ( isa => 'Str', is => 'rw', lazy => 1, builder => 'build_id' );
305 has 'build_id_method' => ( is => 'rw', isa => 'CodeRef', traits => ['Code'],
306 1183 ▶ default => sub { sub { shift->html_name } },
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
307 149 handles => { build_id => 'execute_method' },
308 );
309  
310 # html attributes
311 149 has 'password' => ( isa => 'Bool', is => 'rw' );
312 149 has 'disabled' => ( isa => 'Bool', is => 'rw' );
313 149 has 'readonly' => ( isa => 'Bool', is => 'rw' );
314 149 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 149 has 'type_attr' => ( is => 'rw', isa => 'Str', default => 'text' );
318 149 has 'html5_type_attr' => ( isa => 'Str', is => 'ro', default => 'text' );
319 385 ▶sub input_type {
Subroutine input_type: called CC=3 SCAR=11.0
Pod undocumented
320 385 my $self = shift;
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 149 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
336 149 foreach my $attr ('wrapper', 'element', 'label' ) {
337 # trigger to move 'class' set via _attr to the class slot
338 447 my $add_meth = "add_${attr}_class";
339 38 ▶ my $trigger_sub = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
340 38 my ( $self, $value ) = @_;
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 447 };
345 447 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 447 my $attr_builder = __PACKAGE__ . "::build_${attr}_attr";
358 845 ▶ *$attr_builder = subname $attr_builder, sub {{}};
Subroutine build_wrapper_attr: called CC=1 SCAR=0.0
Subroutine build_label_attr: called CC=1 SCAR=0.0
Pod undocumented
Pod undocumented
359 # create the 'class' slots
360 447 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 447 my $class_builder = __PACKAGE__ . "::build_${attr}_class";
371 729 ▶ *$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 447 my $add_to_class = __PACKAGE__ . "::add_${attr}_class";
374 447 my $_add_meth = __PACKAGE__ . "::_add_${attr}_class";
375 0 ▶ *$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 23 23
ref $_[0] eq 'ARRAY' ? : 4 21 25
376 447 }
377 }
378  
379 # we're assuming that the only attribute we want in an element wrapper is a class
380 149 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 1182 ▶sub build_element_wrapper_class { [] }
Subroutine build_element_wrapper_class: called CC=1 SCAR=0.0
Pod undocumented
392 24 ▶sub element_wrapper_attributes {
Subroutine element_wrapper_attributes: called CC=5 SCAR=16.6
Pod undocumented
393 24 my ( $self, $result ) = @_;
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 1 ▶sub add_standard_element_wrapper_classes {
Subroutine add_standard_element_wrapper_classes: called CC=1 SCAR=0.0
Pod undocumented
406 1 my ( $self, $result, $class ) = @_;
407 }
408  
409 14 ▶sub attributes { shift->element_attributes(@_) }
Subroutine attributes: called CC=1 SCAR=0.0
Pod documented
410 587 ▶sub element_attributes {
Subroutine element_attributes: called CC=15 SCAR=27.2
Pod undocumented
411 587 my ( $self, $result ) = @_;
412 587 ▶ $result ||= $self->result;
Condition66%2/3
$result ||= $self->result
l!l&&r!l&&!r
491960
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 587 my $attr = {};
414 # handle html5 attributes
415 587 ▶ if ($self->form && $self->form->has_flag('is_html5')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form and $self->form->has_flag("is_html5")) 28 559 587
Condition66%2/3
$self->form and $self->form->has_flag("is_html5")
!ll&&!rl&&r
055928
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 587 for my $dep_attr ( 'readonly', 'disabled' ) {
422 1174 ▶ $attr->{$dep_attr} = $dep_attr if $self->$dep_attr;
Branch: 1 branch
BranchTrueFalseTotal
if $self->$dep_attr 4 1170 1174
423 }
424 587 for my $dep_attr ( 'style', 'title', 'tabindex' ) {
425 1761 ▶ $attr->{$dep_attr} = $self->$dep_attr if defined $self->$dep_attr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->$dep_attr 24 1737 1761
426 }
427 587 $attr = {%$attr, %{$self->element_attr}};
428 587 my $class = [@{$self->element_class}];
429 587 $self->add_standard_element_classes($result, $class);
430 587 ▶ $attr->{class} = $class if @$class;
Branch: 1 branch
BranchTrueFalseTotal
if @$class 100 487 587
431 # call form hook
432 587 my $mod_attr;
433 587 ▶ $mod_attr = $self->form->html_attributes($self, 'element', $attr, $result) if $self->form;
Branch: 1 branch
BranchTrueFalseTotal
if $self->form 587 0 587
434 587 ▶ return ref($mod_attr) eq 'HASH' ? $mod_attr : $attr;
Branch: 1 branch
BranchTrueFalseTotal
ref $mod_attr eq 'HASH' ? : 587 0 587
435 }
436  
437 570 ▶sub add_standard_element_classes {
Subroutine add_standard_element_classes: called CC=4 SCAR=13.9
Pod undocumented
438 570 my ( $self, $result, $class ) = @_;
439 570 ▶ push @$class, 'error' if $result->has_errors;
Branch: 1 branch
BranchTrueFalseTotal
if $result->has_errors 29 541 570
440 570 ▶ push @$class, 'warning' if $result->has_warnings;
Branch: 1 branch
BranchTrueFalseTotal
if $result->has_warnings 2 568 570
441 570 ▶ push @$class, 'disabled' if $self->disabled;
Branch: 1 branch
BranchTrueFalseTotal
if $self->disabled 4 566 570
442 }
443  
444 521 ▶sub label_attributes {
Subroutine label_attributes: called CC=5 SCAR=16.3
Pod undocumented
445 521 my ( $self, $result ) = @_;
446 521 ▶ $result ||= $self->result;
Condition66%2/3
$result ||= $self->result
l!l&&r!l&&!r
426950
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 521 my $attr = {%{$self->label_attr}};
449 521 my $class = [@{$self->label_class}];
450 521 $self->add_standard_label_classes($result, $class);
451 521 ▶ $attr->{class} = $class if @$class;
Branch: 1 branch
BranchTrueFalseTotal
if @$class 10 511 521
452 # call form hook
453 521 my $mod_attr;
454 521 ▶ $mod_attr = $self->form->html_attributes($self, 'label', $attr, $result) if $self->form;
Branch: 1 branch
BranchTrueFalseTotal
if $self->form 521 0 521
455 521 ▶ return ref($mod_attr) eq 'HASH' ? $mod_attr : $attr;
Branch: 1 branch
BranchTrueFalseTotal
ref $mod_attr eq 'HASH' ? : 521 0 521
456 }
457  
458 508 ▶sub add_standard_label_classes {
Subroutine add_standard_label_classes: called CC=1 SCAR=0.0
Pod undocumented
459 508 my ( $self, $result, $class ) = @_;
460 }
461  
462 618 ▶sub wrapper_attributes {
Subroutine wrapper_attributes: called CC=8 SCAR=21.5
Pod undocumented
463 618 my ( $self, $result ) = @_;
464 618 ▶ $result ||= $self->result;
Condition66%2/3
$result ||= $self->result
l!l&&r!l&&!r
5101080
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 618 my $attr = {%{$self->wrapper_attr}};
467 618 my $class = [@{$self->wrapper_class}];
468 # add 'error' to class
469 618 $self->add_standard_wrapper_classes($result, $class);
470 618 ▶ $attr->{class} = $class if @$class;
Branch: 1 branch
BranchTrueFalseTotal
if @$class 92 526 618
471 # add id if compound field and id doesn't exist unless 'no_wrapper_id' tag
472 $attr->{id} = $self->id
473 618 ▶ 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 558 618
Condition50%3/6
$self->has_flag("is_compound") and not exists $attr->{"id"} && !$self->get_tag("no_wrapper_id")
!ll&&!rl&&r
558060
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 618 my $mod_attr;
476 618 ▶ $mod_attr = $self->form->html_attributes($self, 'wrapper', $attr, $result) if $self->form;
Branch: 1 branch
BranchTrueFalseTotal
if $self->form 618 0 618
477 618 ▶ return ref($mod_attr) eq 'HASH' ? $mod_attr : $attr;
Branch: 1 branch
BranchTrueFalseTotal
ref $mod_attr eq 'HASH' ? : 618 0 618
478 }
479  
480 598 ▶sub add_standard_wrapper_classes {
Subroutine add_standard_wrapper_classes: called CC=4 SCAR=13.9
Pod undocumented
481 598 my ( $self, $result, $class ) = @_;
482 598 ▶ 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 565 598
Condition100%3/3
$result->has_error_results or $result->has_errors
l!l&&r!l&&!r
429565
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 598 ▶ push @$class, 'warning' if $result->has_warnings;
Branch: 1 branch
BranchTrueFalseTotal
if $result->has_warnings 2 596 598
484 }
485  
486  
487 0 ▶sub wrapper_tag {
Subroutine wrapper_tag: not called CC=2 SCAR=17.9
Pod undocumented
488 0 my $self = shift;
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 0 ▶sub field_filename {
Subroutine field_filename: not called CC=2 SCAR=17.9
Pod undocumented
495 0 my $self = shift;
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 443 ▶sub label_tag {
Subroutine label_tag: called CC=2 SCAR=6.9
Pod undocumented
500 443 my $self = shift;
501 443 ▶ return $self->get_tag('label_tag') || 'label';
Condition100%2/2
$self->get_tag('label_tag') || 'label'
l!l
13430
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 149 has 'writeonly' => ( isa => 'Bool', is => 'rw' );
506 149 has 'noupdate' => ( isa => 'Bool', is => 'rw' );
507  
508 #==============
509 2481 ▶sub convert_full_name {
Subroutine convert_full_name: called CC=1 SCAR=0.0
Pod undocumented
510 2481 my $full_name = shift;
511 2481 $full_name =~ s/\.\d+\./_/g;
512 2481 $full_name =~ s/\./_/g;
513 2481 return $full_name;
514 }
515 149 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 149 has 'set_validate' => ( isa => 'Str', is => 'ro',);
524 1183 ▶sub build_validate_method {
Subroutine build_validate_method: called CC=5 SCAR=16.1
Pod undocumented
525 1183 my $self = shift;
526 1183 my $set_validate = $self->set_validate;
527 1183 ▶ $set_validate ||= "validate_" . convert_full_name($self->full_name);
Condition100%2/2
$set_validate ||= 'validate_' . convert_full_name($self->full_name)
l!l
11182
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 1183 ▶ 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 1163 1183
Condition83%5/6
$set_validate ne "validate_model" and $self->form and $self->form->can($set_validate)
!ll&&!rl&&r
70109320
$set_validate ne "validate_model" and $self->form
!ll&&!rl&&r
0701113
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 1163 ▶ return sub { };
Subroutine __ANON__: called CC=1 SCAR=0.0
531 }
532  
533 149 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 149 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 1187 ▶sub build_default_method {
Subroutine build_default_method: called CC=4 SCAR=13.9
Pod undocumented
544 1187 my $self = shift;
545 1187 my $set_default = $self->set_default;
546 1187 ▶ $set_default ||= "default_" . convert_full_name($self->full_name);
Condition50%1/2
$set_default ||= 'default_' . convert_full_name($self->full_name)
l!l
01187
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 1187 ▶ if ( $self->form && $self->form->can($set_default) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form and $self->form->can($set_default)) 7 1180 1187
Condition100%3/3
$self->form and $self->form->can($set_default)
!ll&&!rl&&r
7011107
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 1466 ▶sub get_default_value {
Subroutine get_default_value: called CC=3 SCAR=11.0
Pod undocumented
555 1466 my $self = shift;
556 1466 ▶ if ( $self->has_default_method ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->has_default_method) { } 13 1453 1466
elsif (defined $self->default) { } 67 1386 1453
557 13 return $self->_default;
558 }
559 elsif ( defined $self->default ) {
560 67 return $self->default;
561 }
562 1386 return;
563 }
564 {
565 # create inflation/deflation methods
566 149 foreach my $type ( 'inflate_default', 'deflate_value', 'inflate', 'deflate' ) {
567 596 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 149 has 'deflation' => (
579 is => 'rw',
580 predicate => 'has_deflation',
581 );
582 has 'trim' => (
583 is => 'rw',
584 1185 ▶ default => sub { { transform => \&default_trim } }
Subroutine __ANON__: called CC=1 SCAR=0.0
585 149 );
586  
587 953 ▶sub default_trim {
Subroutine default_trim: called CC=7 SCAR=19.5
Pod undocumented
588 953 my $value = shift;
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 149 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 450 ▶sub build_render_filter {
Subroutine build_render_filter: called CC=3 SCAR=11.0
Pod undocumented
608 450 my $self = shift;
609  
610 450 ▶ if( $self->form && $self->form->can('render_filter') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form and $self->form->can('render_filter')) { } 1 449 450
Condition100%3/3
$self->form and $self->form->can("render_filter")
!ll&&!rl&&r
14481
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 449 return \&default_render_filter;
616 }
617 }
618  
619 1686 ▶sub default_render_filter {
Subroutine default_render_filter: called CC=2 SCAR=7.0
Pod undocumented
620 1686 my $string = shift;
621 1686 ▶ return '' if (!defined $string);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 1686 1686
622 1686 $string =~ s/&/&/g;
623 1686 $string =~ s/</&lt;/g;
624 1686 $string =~ s/>/&gt;/g;
625 1686 $string =~ s/"/&quot;/g;
626 1686 return $string;
627 }
628  
629 149 has 'input_param' => ( is => 'rw', isa => 'Str' );
630  
631 149 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 866 ▶sub language_handle {
Subroutine language_handle: called CC=6 SCAR=19.7
Pod undocumented
640 866 my ( $self, $value ) = @_;
641 866 ▶ if( $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) 0 866 866
642 0 $self->set_language_handle($value);
643 0 return;
644 }
645 866 ▶ return $self->get_language_handle if( $self->has_language_handle );
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_language_handle 56 810 866
646 # if language handle isn't set use form language handle if possible
647 810 ▶ return $self->form->language_handle if ( $self->has_form );
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_form 782 28 810
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 149 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 525 ▶sub build_localize_meth {
Subroutine build_localize_meth: called CC=3 SCAR=12.7
Pod undocumented
677 525 my $self = shift;
678  
679 525 ▶ if( $self->form && $self->form->can('localize_meth') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form and $self->form->can('localize_meth')) { } 0 525 525
Condition66%2/3
$self->form and $self->form->can("localize_meth")
!ll&&!rl&&r
284970
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 525 return \&default_localize;
685 }
686 }
687  
688 866 ▶sub default_localize {
Subroutine default_localize: called CC=1 SCAR=0.0
Pod undocumented
689 866 my ($self, @message) = @_;
690 866 my $message = $self->language_handle->maketext(@message);
691 866 return $message;
692 }
693  
694 has 'messages' => ( is => 'rw',
695 isa => 'HashRef',
696 traits => ['Hash'],
697 1184 ▶ default => sub {{}},
Subroutine __ANON__: called CC=1 SCAR=0.0
698 149 handles => {
699 '_get_field_message' => 'get',
700 '_has_field_message' => 'exists',
701 'set_message' => 'set',
702 },
703 );
704  
705 149 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 135 ▶sub get_class_messages {
Subroutine get_class_messages: called CC=3 SCAR=11.0
Pod undocumented
719 135 my $self = shift;
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 139 ▶sub get_message {
Subroutine get_message: called CC=4 SCAR=13.9
Pod undocumented
729 139 my ( $self, $msg ) = @_;
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 0 ▶sub all_messages {
Subroutine all_messages: not called CC=4 SCAR=30.0
Pod undocumented
741 0 my $self = shift;
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 1187 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=3 SCAR=11.3
Pod documented
749 1187 my $class = shift;
750  
751 # for backwards compatibility; these will be removed eventually
752 1187 my @new;
753 push @new, ('element_attr', {@_}->{html_attr} )
754 1187 ▶ if( exists {@_}->{html_attr} );
Branch: 1 branch
BranchTrueFalseTotal
if exists {@_}->{"html_attr"} 0 1187 1187
755 push @new, ('do_label', !{@_}->{no_render_label} )
756 1187 ▶ if( exists {@_}->{no_render_label} );
Branch: 1 branch
BranchTrueFalseTotal
if exists {@_}->{"no_render_label"} 0 1187 1187
757 1187 return $class->SUPER::BUILDARGS(@_, @new);
758 }
759  
760 1187 ▶sub BUILD {
Subroutine BUILD: called CC=5 SCAR=16.1
Pod undocumented
761 1187 my ( $self, $params ) = @_;
762  
763 # temporary, for compatibility. move widget_tags to tags
764 1187 ▶ $self->merge_tags($self->wrapper_tags) if $self->has_wrapper_tags;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_wrapper_tags 20 1167 1187
765 # run default method builder
766 1187 $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 1187 $self->validate_method;
770 # merge form widget_name_space
771 1187 ▶ $self->add_widget_name_space( $self->form->widget_name_space ) if $self->form;
Branch: 1 branch
BranchTrueFalseTotal
if $self->form 1117 70 1187
772 # handle apply actions
773 1187 ▶ $self->add_action( $self->trim ) if $self->trim;
Branch: 1 branch
BranchTrueFalseTotal
if $self->trim 1186 1 1187
774 1187 $self->_build_apply_list;
775 1187 ▶ $self->add_action( @{ $params->{apply} } ) if $params->{apply};
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"apply"} 70 1117 1187
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 1197 ▶sub _result_from_fields {
Subroutine _result_from_fields: called CC=8 SCAR=20.9
781 1197 my ( $self, $result ) = @_;
782  
783 1197 ▶ if ( $self->disabled && $self->has_init_value ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->disabled and $self->has_init_value) { } 4 1193 1197
elsif (my(@values) = $self->get_default_value) { } 68 1125 1193
Condition100%3/3
$self->disabled and $self->has_init_value
!ll&&!rl&&r
118854
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 1197 $self->_set_result($result);
795 1197 $result->_set_field_def($self);
796 1197 return $result;
797 }
798  
799 765 ▶sub _result_from_input {
Subroutine _result_from_input: called CC=6 SCAR=17.9
800 765 my ( $self, $result, $input, $exists ) = @_;
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 257 ▶sub _result_from_object {
Subroutine _result_from_object: called CC=3 SCAR=11.8
822 257 my ( $self, $result, $value ) = @_;
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 5792 ▶sub full_name {
Subroutine full_name: called CC=4 SCAR=13.9
Pod documented
839 5792 my $field = shift;
840  
841 5792 my $name = $field->name;
842 5792 my $parent_name;
843 # field should always have a parent unless it's a standalone field test
844 5792 ▶ if ( $field->parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->parent) 5619 173 5792
845 5619 $parent_name = $field->parent->full_name;
846 }
847 5792 ▶ return $name unless defined $parent_name && length $parent_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parent_name and length $parent_name 4392 1400 5792
Condition100%3/3
defined $parent_name and length $parent_name
!ll&&!rl&&r
17342191400
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 2 ▶sub full_accessor {
Subroutine full_accessor: called CC=6 SCAR=19.1
Pod documented
852 2 my $field = shift;
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 194 ▶sub add_error {
Subroutine add_error: called CC=4 SCAR=13.9
Pod documented
869 194 my ( $self, @message ) = @_;
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 194 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
896 194 $out = $self->_localize(@message);
897 }
898 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
899 0 die "Error occurred localizing error message for " . $self->label . ". Check brackets. $_";
900 194 };
901 194 return $self->push_errors($out);;
902 }
903  
904 194 ▶sub push_errors {
Subroutine push_errors: called CC=2 SCAR=6.9
Pod undocumented
905 194 my $self = shift;
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 111 ▶sub _apply_deflation {
Subroutine _apply_deflation: called CC=3 SCAR=11.0
914 111 my ( $self, $value ) = @_;
915  
916 111 ▶ if ( $self->has_deflation ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->has_deflation) { } 1 110 111
elsif ($self->has_deflate_method) { } 110 0 110
917 1 $value = $self->deflation->($value);
918 }
919 elsif ( $self->has_deflate_method ) {
920 110 $value = $self->deflate($value);
921 }
922 111 return $value;
923 }
924 288 ▶sub _can_deflate {
Subroutine _can_deflate: called CC=2 SCAR=6.9
925 288 my $self = shift;
926 288 ▶ return $self->has_deflation || $self->has_deflate_method;
Condition100%3/3
$self->has_deflation || $self->has_deflate_method
l!l&&r!l&&!r
1110177
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 665 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod undocumented
931 665 my ( $self, %params ) = @_;
932 665 $self->meta->clone_object( $self, %params );
933 }
934  
935 0 ▶sub value_changed {
Subroutine value_changed: not called CC=6 SCAR=37.4
Pod undocumented
936 0 my ($self) = @_;
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 1045 ▶sub input_defined {
Subroutine input_defined: called CC=2 SCAR=7.1
Pod undocumented
952 1045 my ($self) = @_;
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 0 ▶sub dump {
Subroutine dump: not called CC=8 SCAR=42.8
Pod documented
958 0 my $self = shift;
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 0 ▶sub apply_rendering_widgets {
Subroutine apply_rendering_widgets: not called CC=6 SCAR=37.4
Pod undocumented
982 0 my $self = shift;
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 0 ▶sub peek {
Subroutine peek: not called CC=6 SCAR=37.4
Pod undocumented
999 0 my ( $self, $indent ) = @_;
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 1206 ▶sub has_some_value {
Subroutine has_some_value: called CC=11 SCAR=24.5
Pod undocumented
1021 1206 my $x = shift;
1022  
1023 1206 ▶ return unless defined $x;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $x 10 1196 1206
1024 1196 ▶ return $x =~ /\S/ if !ref $x;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $x 1035 161 1196
1025 161 ▶ if ( ref $x eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x eq "ARRAY") 40 121 161
1026 40 for my $elem (@$x) {
1027 33 ▶ return 1 if has_some_value($elem);
Branch: 1 branch
BranchTrueFalseTotal
if has_some_value($elem) 29 4 33
1028 }
1029 11 return 0;
1030 }
1031 121 ▶ if ( ref $x eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x eq "HASH") 118 3 121
1032 118 for my $key ( keys %$x ) {
1033 126 ▶ return 1 if has_some_value( $x->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
if has_some_value($x->{$key}) 108 18 126
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 1 ▶sub apply_traits {
Subroutine apply_traits: called CC=1 SCAR=0.0
Pod undocumented
1043 1 my ($class, @traits) = @_;
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 149 __PACKAGE__->meta->make_immutable;
1051 149 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
1052 149 1;
1053  
1054 __END__
« FormHandler/Blocks.pm ↑ Summary FormHandler/Fields.pm »