blib/lib/Rose/HTML/Form/Field.pm

filter: Statementstmt 89.5% 421 / 470 Branchbran 74.1% 181 / 244 Conditioncond 62.0% 72 / 116 MC/DCmcdc 36.9% 24 / 65 Subroutinesub 95.6% 88 / 92 Podpod 71.2% 47 / 66 totaltotal 79.1% 833 / 1053 CC 164 SCAR 22.3
CC
164
Cov
81%
locale
31.1
field_depth
30.0
localizer
28.2
CRAP 9.3
« blib/lib/Rose/HTML/Form/Field/Collection.pm ↑ Summary blib/lib/Rose/HTML/Object/Error.pm »
1 package Rose::HTML::Form::Field;
2  
3 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 35 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 35 ▶use Scalar::Util();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 35 ▶use Rose::HTML::Util();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 35 ▶use Rose::HTML::Label;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 35 ▶use Rose::HTML::Object::Errors qw(:field);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 35 ▶use Rose::HTML::Object::Messages qw(:field);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 35 ▶use base 'Rose::HTML::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 35 ▶use constant HTML_ERROR_SEP => "<br>\n";
Subroutine BEGIN: called CC=1 SCAR=0.0
17 35 ▶use constant XHTML_ERROR_SEP => "<br />\n";
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 35 ▶use Rose::HTML::Form::Constants qw(FF_SEPARATOR);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 35 our $VERSION = '0.617';
22  
23 #our $Debug = 0;
24  
25 use Rose::HTML::Object::MakeMethods::Localization
26 35 ▶(
Subroutine BEGIN: called CC=1 SCAR=0.0
27 35 localized_message =>
28 [
29 qw(_error_label label description)
30 ],
31 35 );
32  
33 use Rose::Object::MakeMethods::Generic
34 35 ▶(
Subroutine BEGIN: called CC=1 SCAR=0.0
35 35 scalar => [ qw(rank type) ],
36  
37 boolean => [ qw(required is_cleared has_partial_value) ],
38 boolean =>
39 [
40 trim_spaces => { default => 1 },
41 empty_is_ok => { default => 0 },
42 ],
43  
44 'scalar --get_set_init' =>
45 [
46 qw(html_prefix html_suffix html_error_separator xhtml_error_separator
47 local_moniker apply_error_class)
48 ],
49 35 );
50  
51 35 __PACKAGE__->add_valid_html_attrs(qw(
52 name
53 value
54 onblur
55 onfocus
56 accesskey
57 tabindex
58 autofocus
59 ));
60  
61 20 ▶sub is_button { 0 }
Subroutine is_button: called CC=1 SCAR=0.0
Pod undocumented
62  
63 35 *label_id = \&label_message_id;
64  
65 sub error_label
66 61 ▶{
Subroutine error_label: called CC=4 SCAR=13.9
Pod documented
67 61 my($self) = shift;
68  
69 61 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 59 61
70 {
71 2 return $self->_error_label(@_);
72 }
73  
74 59 my $label = $self->_error_label;
75  
76 35 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
77 59 ▶ return (defined $label) ? (length $label ? $label : undef) : $self->label;
Branch: 2 branches
BranchTrueFalseTotal
defined $label ? : 6 53 59
length $label ? : 5 1 6
78 }
79  
80 sub error_label_id
81 128 ▶{
Subroutine error_label_id: called CC=4 SCAR=17.9
Pod documented
82 128 my($self) = shift;
83  
84 128 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 128 0 128
85 {
86 128 return $self->_error_label_message_id(@_);
87 }
88  
89 0 my $label = $self->_error_label_message_id;
90  
91 35 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
92 0 ▶ return (defined $label) ? (length $label ? $label : undef) : $self->label;
Branch: 2 branches
BranchTrueFalseTotal
defined $label ? : 0 0 0
length $label ? : 0 0 0
93 }
94  
95 302 ▶sub init_apply_error_class { 1 }
Subroutine init_apply_error_class: called CC=1 SCAR=0.0
Pod undocumented
96  
97 sub auto_invalidate_parent
98 3182 ▶{
Subroutine auto_invalidate_parent: called CC=4 SCAR=16.1
Pod documented
99 3182 my($self) = shift;
100  
101 3182 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 3182 3182
102 {
103 0 ▶ return $self->{'auto_invalidate_parent'} = $_[0] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 0 0
104 }
105  
106 return defined($self->{'auto_invalidate_parent'}) ?
107 $self->{'auto_invalidate_parent'} :
108 3182 ▶ ($self->{'auto_invalidate_parent'} = 1);
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'auto_invalidate_parent'} ? : 3108 74 3182
109 }
110  
111 sub invalidate_value
112 89 ▶{
Subroutine invalidate_value: called CC=1 SCAR=0.0
Pod documented
113 89 $_[0]->{'input_value'} = undef;
114 89 $_[0]->{'internal_value'} = undef;
115 89 $_[0]->{'output_value'} = undef;
116 }
117  
118 sub invalidate_output_value
119 1 ▶{
Subroutine invalidate_output_value: called CC=1 SCAR=0.0
Pod documented
120 1 $_[0]->{'output_value'} = undef;
121 }
122  
123 sub parent_group
124 5397 ▶{
Subroutine parent_group: called CC=3 SCAR=11.2
Pod documented
125 5397 my($self) = shift;
126  
127 5397 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 250 5147 5397
128 {
129 250 ▶ if(ref $_[0])
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 250 0 250
130 {
131 250 Scalar::Util::weaken($self->{'parent_group'} = shift);
132 250 return $self->{'parent_group'};
133 }
134 else
135 {
136 0 return $self->{'parent_group'} = shift;
137 }
138 }
139  
140 5147 return $self->{'parent_group'};
141 }
142  
143 sub parent_field
144 32882 ▶{
Subroutine parent_field: called CC=3 SCAR=11.2
Pod documented
145 32882 my($self) = shift;
146  
147 32882 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 317 32565 32882
148 {
149 317 ▶ if(ref $_[0])
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 317 0 317
150 {
151 317 Scalar::Util::weaken($self->{'parent_field'} = shift);
152 317 return $self->{'parent_field'};
153 }
154 else
155 {
156 0 return $self->{'parent_field'} = shift;
157 }
158 }
159  
160 32565 return $self->{'parent_field'};
161 }
162  
163 sub parent_form
164 39570 ▶{
Subroutine parent_form: called CC=3 SCAR=11.2
Pod documented
165 39570 my($self) = shift;
166  
167 39570 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 330 39240 39570
168 {
169 330 ▶ if(ref $_[0])
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 330 0 330
170 {
171 330 Scalar::Util::weaken($self->{'parent_form'} = shift);
172 330 return $self->{'parent_form'};
173 }
174 else
175 {
176 0 return $self->{'parent_form'} = shift;
177 }
178 }
179  
180 39240 return $self->{'parent_form'};
181 }
182  
183 sub field_depth
184 0 ▶{
Subroutine field_depth: not called CC=5 SCAR=34.0
Pod undocumented
185 0 my($self) = shift;
186  
187 0 ▶ my $parent = $self->parent_field || $self->parent_form;
Condition0%0/3
$self->parent_field || $self->parent_form
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->parent_field || $self->parent_form
$self->parent_field $self->parent_form
Truth table0%0/3
A || B
A= $self->parent_fieldB= $self->parent_form
ABresult
1X1
011
000
188  
189 0 ▶ return 0 unless($parent);
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
190  
191 0 my $depth = 1;
192 0 ▶ $depth++ while($parent = $parent->parent_field || $parent->parent_form);
Branch: 1 branch
BranchTrueFalseTotal
$parent = $parent->parent_field || $parent->parent_form and do { ++$depth } 0 0 0
Condition0%0/3
$parent->parent_field || $parent->parent_form
l!l&&r!l&&!r
000
MC/DC0%0/2
$parent->parent_field || $parent->parent_form
$parent->parent_field $parent->parent_form
Truth table0%0/3
A || B
A= $parent->parent_fieldB= $parent->parent_form
ABresult
1X1
011
000
193  
194 0 return $depth;
195 }
196  
197 sub fq_name
198 11862 ▶{
Subroutine fq_name: called CC=1 SCAR=0.0
Pod undocumented
199 11862 my($self) = shift;
200 11862 return join(FF_SEPARATOR, grep { defined } $self->form_context_name,
201 $self->field_context_name,
202 $self->local_name);
203 }
204  
205 sub fq_moniker
206 1802 ▶{
Subroutine fq_moniker: called CC=1 SCAR=0.0
Pod undocumented
207 1802 my($self) = shift;
208  
209 1802 return join(FF_SEPARATOR, grep { defined } $self->form_context_name,
210 $self->field_context_name,
211 $self->local_moniker);
212 }
213  
214 44 ▶sub init_local_moniker { shift->local_name }
Subroutine init_local_moniker: called CC=1 SCAR=0.0
Pod undocumented
215  
216 sub form_context_name
217 15108 ▶{
Subroutine form_context_name: called CC=2 SCAR=6.9
Pod undocumented
218 15108 my($self) = shift;
219 15108 ▶ my $parent_form = $self->parent_form or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $parent_form = $self->parent_form or return undef 6086 9022 15108
220 6086 return $parent_form->fq_form_name;
221 }
222  
223 sub field_context_name
224 15108 ▶{
Subroutine field_context_name: called CC=3 SCAR=11.0
Pod undocumented
225 15108 my($self) = shift;
226 15108 ▶ my $parent_field = $self->parent_field or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $parent_field = $self->parent_field or return undef 6099 9009 15108
227 6099 ▶ my $name = $parent_field->fq_name or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $name = $parent_field->fq_name or return undef 6099 0 6099
228 6099 return $name;
229 }
230  
231 11 ▶sub is_flat_group { 0 }
Subroutine is_flat_group: called CC=1 SCAR=0.0
Pod undocumented
232  
233 32 ▶sub init_html_prefix { '' }
Subroutine init_html_prefix: called CC=1 SCAR=0.0
Pod undocumented
234 32 ▶sub init_html_suffix { '' }
Subroutine init_html_suffix: called CC=1 SCAR=0.0
Pod undocumented
235  
236 5 ▶sub init_html_error_separator { HTML_ERROR_SEP }
Subroutine init_html_error_separator: called CC=1 SCAR=0.0
Pod undocumented
237 4 ▶sub init_xhtml_error_separator { XHTML_ERROR_SEP }
Subroutine init_xhtml_error_separator: called CC=1 SCAR=0.0
Pod undocumented
238  
239 sub value
240 167 ▶{
Subroutine value: called CC=2 SCAR=7.6
Pod documented
241 167 my($self) = shift;
242  
243 167 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 167 0 167
244 {
245 167 return $self->input_value($self->html_attr('value', shift));
246 }
247 else
248 {
249 0 return $self->html_attr('value');
250 }
251 }
252  
253 sub resync_name
254 3294 ▶{
Subroutine resync_name: called CC=3 SCAR=11.4
Pod undocumented
255 3294 my($self) = shift;
256  
257 3294 $self->html_attr('name', undef);
258 3294 ▶ $self->name if($self->parent_field || $self->parent_form);
Branch: 1 branch
BranchTrueFalseTotal
if $self->parent_field or $self->parent_form 3294 0 3294
Condition66%2/3
$self->parent_field or $self->parent_form
l!l&&r!l&&!r
204812460
MC/DC0%0/2
$self->parent_field or $self->parent_form
$self->parent_field $self->parent_form
Truth table66%2/3
A or B
A= $self->parent_fieldB= $self->parent_form
ABresult
1X1
011
000
259 #$self->name($self->fq_name);
260 }
261  
262 sub local_name
263 14656 ▶{
Subroutine local_name: called CC=9 SCAR=22.3
Pod documented
264 14656 my($self) = shift;
265  
266 14656 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1530 13126 14656
267 {
268 1530 my $name = shift;
269  
270 35 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
271 1530 ▶ if(index($name, FF_SEPARATOR) >= 0 && !$self->isa('Rose::HTML::Form::Field::Hidden'))
Branch: 1 branch
BranchTrueFalseTotal
if (index($name, ".") != -1 and not $self->isa("Rose::HTML::Form::Field::Hidden")) 0 1530 1530
Condition66%2/3
index($name, ".") != -1 and not $self->isa("Rose::HTML::Form::Field::Hidden")
!ll&&!rl&&r
1492380
MC/DC0%0/2
index($name, ".") != -1 and not $self->isa("Rose::HTML::Form::Field::Hidden")
index($name, ".") != -1 not $self->isa("Rose::HTML::Form::Field::Hidden")
Truth table66%2/3
A and not(B)
A= index($name, ".") != -1B= not $self->isa("Rose::HTML::Form::Field::Hidden")
ABresult
0X0
100
111
272 {
273 0 Carp::croak "Invalid local field name: $name";
274 }
275  
276 1530 my $old_name = $self->{'local_name'};
277 1530 $self->{'local_name'} = $name;
278  
279 1530 ▶ if(defined $old_name && $name ne $old_name)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old_name and $name ne $old_name) 3 1527 1530
Condition100%3/3
defined $old_name and $name ne $old_name
!ll&&!rl&&r
6019263
MC/DC100%2/2
defined $old_name and $name ne $old_name
defined $old_name $name ne $old_name
Truth table100%3/3
A and B
A= defined $old_nameB= $name ne $old_name
ABresult
0X0
100
111
280 {
281 3 ▶ if(my $parent_form = $self->parent_form)
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent_form = $self->parent_form) 1 2 3
282 {
283 1 $parent_form->delete_field($old_name);
284 1 $parent_form->add_field($name => $self);
285 }
286  
287 3 ▶ if(my $parent_field = $self->parent_field)
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent_field = $self->parent_field) 0 3 3
288 {
289 0 $parent_field->delete_field($old_name);
290 0 $parent_field->add_field($name => $self);
291 }
292 }
293  
294 1530 return $name;
295 }
296  
297 13126 my $name = $self->{'local_name'};
298 13126 ▶ return $name if(defined $name);
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 12673 453 13126
299 453 return $self->{'local_name'} = $self->{'local_moniker'};
300 }
301  
302 sub name
303 8218 ▶{
Subroutine name: called CC=3 SCAR=11.0
Pod documented
304 8218 my($self) = shift;
305  
306 8218 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 560 7658 8218
307 {
308 560 $self->local_name(shift);
309 560 return $self->html_attr('name', $self->fq_name);
310 }
311  
312 7658 my $name = $self->html_attr('name');
313  
314 # The name HTML attr will be an empty string if it's a required attr,
315 # so use length() and not defined()
316 35 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
317 7658 ▶ unless(length $name)
Branch: 1 branch
BranchTrueFalseTotal
unless (length $name) 2668 4990 7658
318 {
319 2668 return $self->html_attr('name', $self->fq_name);
320 }
321  
322 4990 return $name;
323 }
324  
325 sub moniker
326 759 ▶{
Subroutine moniker: called CC=3 SCAR=11.0
Pod undocumented
327 759 my($self) = shift;
328  
329 759 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 258 501 759
330 {
331 258 return $self->fq_moniker($self->{'moniker'} = shift);
332 }
333 else
334 {
335 501 ▶ return $self->{'moniker'} if(defined $self->{'moniker'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"moniker"} 444 57 501
336 57 return $self->{'moniker'} = $self->fq_moniker;
337 }
338 }
339  
340 sub default_value
341 4819 ▶{
Subroutine default_value: called CC=2 SCAR=6.9
Pod documented
342 4819 my($self) = shift;
343  
344 4819 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 550 4269 4819
345 {
346 550 $self->{'internal_value'} = undef;
347 550 $self->{'output_value'} = undef;
348 550 return $self->{'default_value'} = shift;
349 }
350  
351 4269 return $self->{'default_value'};
352 }
353  
354 30 ▶sub default { shift->default_value(@_) }
Subroutine default: called CC=1 SCAR=0.0
Pod documented
355  
356 1554 ▶sub inflate_value { $_[1] }
Subroutine inflate_value: called CC=1 SCAR=0.0
Pod documented
357 254 ▶sub deflate_value { $_[1] }
Subroutine deflate_value: called CC=1 SCAR=0.0
Pod documented
358  
359 sub input_value
360 5948 ▶{
Subroutine input_value: called CC=11 SCAR=24.1
Pod documented
361 5948 my($self) = shift;
362  
363 5948 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2921 3027 5948
364 {
365 2921 $self->{'is_cleared'} = 0;
366 2921 $self->{'internal_value'} = undef;
367 2921 $self->{'output_value'} = undef;
368 2921 $self->{'errors'} = undef;
369 2921 $self->{'input_value'} = shift;
370  
371 2921 ▶ if(my $parent = $self->parent_field)
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent = $self->parent_field) 1211 1710 2921
372 {
373 1211 ▶ $parent->is_cleared(0) if(!$parent->{'in_init'} && $parent->_is_full);
Branch: 1 branch
BranchTrueFalseTotal
if not $parent->{"in_init"} and $parent->_is_full 165 1046 1211
Condition100%3/3
not $parent->{"in_init"} and $parent->_is_full
!ll&&!rl&&r
111035165
MC/DC100%2/2
not $parent->{"in_init"} and $parent->_is_full
not $parent->{"in_init"} $parent->_is_full
Truth table100%3/3
not(A) and B
A= not $parent->{"in_init"}B= $parent->_is_full
ABresult
0X0
100
111
374  
375 1211 ▶ if($self->auto_invalidate_parent)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->auto_invalidate_parent) 54 1157 1211
376 {
377 54 $parent->invalidate_value;
378 }
379 }
380  
381 2921 return $self->{'input_value'};
382 }
383  
384 3027 ▶ return undef if($self->is_cleared || $self->has_partial_value);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_cleared or $self->has_partial_value 69 2958 3027
Condition100%3/3
$self->is_cleared or $self->has_partial_value
l!l&&r!l&&!r
11582958
MC/DC100%2/2
$self->is_cleared or $self->has_partial_value
$self->is_cleared $self->has_partial_value
Truth table100%3/3
A or B
A= $self->is_clearedB= $self->has_partial_value
ABresult
1X1
011
000
385  
386 my $value =
387 2958 ▶ (defined $self->{'input_value'}) ? $self->{'input_value'} :
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'input_value'} ? : 872 2086 2958
388 $self->default_value;
389  
390 2958 ▶ if(wantarray && ref $value eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray and ref $value eq "ARRAY") 0 2958 2958
Condition33%1/3
wantarray and ref $value eq "ARRAY"
!ll&&!rl&&r
295800
MC/DC0%0/2
wantarray and ref $value eq "ARRAY"
wantarray ref $value eq "ARRAY"
Truth table33%1/3
A and B
A= wantarrayB= ref $value eq "ARRAY"
ABresult
0X0
100
111
391 {
392 0 return @$value;
393 }
394  
395 2958 return $value;
396 }
397  
398 sub _set_input_value
399 2462 ▶{
Subroutine _set_input_value: called CC=1 SCAR=0.0
400 # XXX: Evil, but I can't bear to add 3 method calls to
401 # XXX: save and then restore this value.
402 2462 local $_[0]->{'auto_invalidate_parent'} = 0;
403 2462 shift->input_value(@_);
404 }
405  
406 sub _is_full
407 1314 ▶{
Subroutine _is_full: called CC=2 SCAR=6.9
408 1314 my($self) = shift;
409  
410 1314 ▶ if($self->is_full(@_))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_full(@_)) 198 1116 1314
411 {
412 198 $self->has_partial_value(0);
413 198 return 1;
414 }
415  
416 1116 return 0;
417 }
418  
419 sub input_value_filtered
420 78 ▶{
Subroutine input_value_filtered: called CC=2 SCAR=6.9
Pod documented
421 78 my($self) = shift;
422  
423 78 my $value = $self->input_value;
424  
425 78 $value = $self->input_prefilter($value);
426  
427 78 ▶ if(my $input_filter = $self->input_filter)
Branch: 1 branch
BranchTrueFalseTotal
if (my $input_filter = $self->input_filter) 4 74 78
428 {
429 4 local $_ = $value;
430 4 $value = $input_filter->($self, $value);
431 }
432  
433 78 return $value;
434 }
435  
436 sub internal_value
437 7302 ▶{
Subroutine internal_value: called CC=12 SCAR=24.9
Pod documented
438 7302 my($self) = shift;
439  
440 7302 ▶ Carp::croak "Cannot set the internal value. Use input_value() instead." if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 7302 7302
441  
442 7302 ▶ return undef if($self->is_cleared || $self->has_partial_value);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_cleared or $self->has_partial_value 3979 3323 7302
Condition100%3/3
$self->is_cleared or $self->has_partial_value
l!l&&r!l&&!r
3931483323
MC/DC100%2/2
$self->is_cleared or $self->has_partial_value
$self->is_cleared $self->has_partial_value
Truth table100%3/3
A or B
A= $self->is_clearedB= $self->has_partial_value
ABresult
1X1
011
000
443  
444 3323 ▶ if(defined $self->{'internal_value'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"internal_value"}) 1273 2050 3323
445 {
446 1273 ▶ if(wantarray && ref $self->{'internal_value'} eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray and ref $self->{"internal_value"} eq "ARRAY") 2 1271 1273
Condition100%3/3
wantarray and ref $self->{"internal_value"} eq "ARRAY"
!ll&&!rl&&r
8014702
MC/DC100%2/2
wantarray and ref $self->{"internal_value"} eq "ARRAY"
wantarray ref $self->{"internal_value"} eq "ARRAY"
Truth table100%3/3
A and B
A= wantarrayB= ref $self->{"internal_value"} eq "ARRAY"
ABresult
0X0
100
111
447 {
448 2 return @{$self->{'internal_value'}};
449 }
450  
451 1271 return $self->{'internal_value'};
452 }
453  
454 2050 my $value = $self->input_value;
455  
456 2050 my($using_default, $final_value);
457  
458 2050 ▶ unless(defined $value)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 1367 683 2050
459 {
460 1367 $value = $self->default_value;
461 1367 $using_default++;
462 }
463  
464 2050 $value = $self->input_prefilter($value);
465  
466 2050 ▶ if(my $input_filter = $self->input_filter)
Branch: 1 branch
BranchTrueFalseTotal
if (my $input_filter = $self->input_filter) { } 29 2021 2050
467 {
468 29 local $_ = $value;
469 29 $final_value = $input_filter->($self, $value);
470 }
471 2021 else { $final_value = $value }
472  
473 2050 $final_value = $self->inflate_value($final_value);
474  
475 2050 ▶ $self->{'internal_value'} = $final_value unless($using_default);
Branch: 1 branch
BranchTrueFalseTotal
unless $using_default 683 1367 2050
476  
477 2050 ▶ if(wantarray && ref $final_value eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray and ref $final_value eq "ARRAY") 2 2048 2050
Condition100%3/3
wantarray and ref $final_value eq "ARRAY"
!ll&&!rl&&r
10509982
MC/DC100%2/2
wantarray and ref $final_value eq "ARRAY"
wantarray ref $final_value eq "ARRAY"
Truth table100%3/3
A and B
A= wantarrayB= ref $final_value eq "ARRAY"
ABresult
0X0
100
111
478 {
479 2 return @$final_value;
480 }
481  
482 2048 return $final_value;
483 }
484  
485 0 ▶sub internal_value_singular { shift->internal_value(@_) }
Subroutine internal_value_singular: not called CC=1 SCAR=6.9
Pod undocumented
486  
487 sub output_value
488 554 ▶{
Subroutine output_value: called CC=7 SCAR=19.9
Pod documented
489 554 my($self) = shift;
490  
491 554 ▶ Carp::croak "Cannot set the output value. Use input_value() instead." if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 554 554
492  
493 554 ▶ return undef if($self->is_cleared);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_cleared 56 498 554
494  
495 498 ▶ return $self->{'output_value'} if(defined $self->{'output_value'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"output_value"} 176 322 498
496  
497 322 my $value = $self->deflate_value(scalar $self->internal_value);
498  
499 322 ▶ if(my $output_filter = $self->output_filter)
Branch: 1 branch
BranchTrueFalseTotal
if (my $output_filter = $self->output_filter) { } 22 300 322
500 {
501 22 local $_ = $value;
502 22 $self->{'output_value'} = $output_filter->($self, $value);
503 }
504 300 else { $self->{'output_value'} = $value }
505  
506 322 ▶ if(wantarray && ref $self->{'output_value'} eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray and ref $self->{"output_value"} eq "ARRAY") 0 322 322
Condition66%2/3
wantarray and ref $self->{"output_value"} eq "ARRAY"
!ll&&!rl&&r
532690
MC/DC0%0/2
wantarray and ref $self->{"output_value"} eq "ARRAY"
wantarray ref $self->{"output_value"} eq "ARRAY"
Truth table66%2/3
A and B
A= wantarrayB= ref $self->{"output_value"} eq "ARRAY"
ABresult
0X0
100
111
507 {
508 0 return @{$self->{'output_value'}};
509 }
510  
511 322 return $self->{'output_value'};
512 }
513  
514 sub is_empty
515 3605 ▶{
Subroutine is_empty: called CC=4 SCAR=14.2
Pod documented
516 3605 my($self) = shift;
517  
518 3605 my $value = $self->internal_value;
519  
520 35 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
521 3605 ▶ return ($value =~ /\S/ || (!$self->trim_spaces && length $value)) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$value =~ /\S/ || !$self->trim_spaces && length $value ? : 300 3305 3605
Condition50%3/6
$value =~ /\S/ or not $self->trim_spaces and length $value
l!l&&r!l&&!r
30003305
not $self->trim_spaces and length $value
!ll&&!rl&&r
330500
MC/DC33%1/3
$value =~ /\S/ or not $self->trim_spaces and length $value
$value =~ /\S/ not $self->trim_spaces length $value
Truth table50%2/4
A or not(B) and C
A= $value =~ /\S/B= not $self->trim_spacesC= length $value
ABCresult
1XX1
0111
00X0
0100
522 }
523  
524 0 ▶sub is_full { !shift->is_empty }
Subroutine is_full: not called CC=1 SCAR=6.9
Pod documented
525  
526 sub input_prefilter
527 2128 ▶{
Subroutine input_prefilter: called CC=5 SCAR=16.1
Pod documented
528 2128 my($self, $value) = @_;
529  
530 2128 ▶ return undef unless(defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1391 737 2128
531  
532 737 ▶ unless(ref $value)
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $value) 700 37 737
533 {
534 700 for($value)
535 {
536 35 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
537  
538 700 ▶ if($self->trim_spaces)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->trim_spaces) 698 2 700
539 {
540 698 s/^\s+//;
541 698 s/\s+$//;
542 }
543 }
544 }
545  
546 737 return $value;
547 }
548  
549 sub input_filter
550 2139 ▶{
Subroutine input_filter: called CC=2 SCAR=6.9
Pod documented
551 2139 my($self) = shift;
552  
553 2139 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 11 2128 2139
554 {
555 11 $self->{'internal_value'} = undef;
556 11 $self->{'output_value'} = undef;
557 11 return $self->{'input_filter'} = shift;
558 }
559  
560 2128 return $self->{'input_filter'};
561 }
562  
563 sub output_filter
564 337 ▶{
Subroutine output_filter: called CC=2 SCAR=6.9
Pod documented
565 337 my($self) = shift;
566  
567 337 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 14 323 337
568 {
569 14 $self->{'output_value'} = undef;
570 14 return $self->{'output_filter'} = shift;
571 }
572  
573 323 return $self->{'output_filter'};
574 }
575  
576 sub filter
577 1 ▶{
Subroutine filter: called CC=4 SCAR=15.0
Pod documented
578 1 my($self) = shift;
579  
580 1 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 0 1
581 {
582 1 my $filter = shift;
583 1 $self->{'input_filter'} = $filter;
584 1 $self->{'output_filter'} = $filter;
585 }
586  
587 1 my $input_filter = $self->{'input_filter'};
588  
589 1 ▶ if(ref $input_filter && $input_filter eq $self->output_filter)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_filter and $input_filter eq $self->output_filter) 1 0 1
Condition33%1/3
ref $input_filter and $input_filter eq $self->output_filter
!ll&&!rl&&r
001
MC/DC0%0/2
ref $input_filter and $input_filter eq $self->output_filter
ref $input_filter $input_filter eq $self->output_filter
Truth table33%1/3
A and B
A= ref $input_filterB= $input_filter eq $self->output_filter
ABresult
0X0
100
111
590 {
591 1 return $input_filter;
592 }
593  
594 0 return;
595 }
596  
597 sub clear
598 1808 ▶{
Subroutine clear: called CC=1 SCAR=0.0
Pod documented
599 1808 my($self) = shift;
600  
601 1808 $self->_set_input_value(undef);
602 1808 $self->error(undef);
603 1808 $self->has_partial_value(0);
604 1808 $self->is_cleared(1);
605 }
606  
607 sub reset
608 66 ▶{
Subroutine reset: called CC=1 SCAR=0.0
Pod documented
609 66 my($self) = shift;
610  
611 66 $self->_set_input_value(undef);
612 66 $self->error(undef);
613 66 $self->has_partial_value(0);
614 66 $self->is_cleared(0);
615 66 return 1;
616 }
617  
618 sub hidden_fields
619 115 ▶{
Subroutine hidden_fields: called CC=3 SCAR=14.2
Pod documented
620 115 my($self) = shift;
621  
622 115 my $hidden_field_class = ref($self)->object_type_class_loaded('hidden');
623  
624 35 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
625 115 ▶ unless(@{$hidden_field_class . '::ISA'})
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$hidden_field_class . '::ISA';}) 0 115 115
626 {
627 0 my $error;
628  
629 TRY:
630 {
631 0 local $@;
632 0 eval "use $hidden_field_class";
633 0 $error = $@;
634 }
635  
636 0 ▶ Carp::croak "Could not load hidden field class '$hidden_field_class' - $error"
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
637 if($error);
638 }
639  
640 return
641 115 $hidden_field_class->new(
642 name => $self->html_attr('name'),
643 id => $self->html_attr('id'),
644 class => $self->html_attr('class'),
645 value => $self->output_value);
646 }
647  
648 86 ▶sub hidden_field { shift->hidden_fields(@_) }
Subroutine hidden_field: called CC=1 SCAR=0.0
Pod documented
649  
650 sub html_hidden_fields
651 12 ▶{
Subroutine html_hidden_fields: called CC=3 SCAR=11.1
Pod documented
652 12 my($self) = shift;
653  
654 12 my @html;
655  
656 12 foreach my $field ($self->hidden_fields)
657 {
658 18 push(@html, $field->html_field);
659 }
660  
661 12 ▶ return (wantarray) ? @html : join("\n", @html);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 12 12
662 }
663  
664 8 ▶sub html_hidden_field { shift->html_hidden_fields(@_) }
Subroutine html_hidden_field: called CC=1 SCAR=0.0
Pod documented
665  
666 sub xhtml_hidden_fields
667 7 ▶{
Subroutine xhtml_hidden_fields: called CC=3 SCAR=11.1
Pod documented
668 7 my($self) = shift;
669  
670 7 my @xhtml;
671  
672 7 foreach my $field ($self->hidden_fields)
673 {
674 9 push(@xhtml, $field->xhtml_field);
675 }
676  
677 7 ▶ return (wantarray) ? @xhtml : join("\n", @xhtml);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 7 7
678 }
679  
680 3 ▶sub xhtml_hidden_field { shift->xhtml_hidden_fields(@_) }
Subroutine xhtml_hidden_field: called CC=1 SCAR=0.0
Pod documented
681  
682 sub element
683 0 ▶{
Subroutine element: not called CC=2 SCAR=17.9
Pod documented
684 0 my($self) = shift;
685 0 ▶ Carp::croak "Cannot set element for ", ref($self) if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
686 0 return $self->html_element;
687 }
688  
689 sub html_tag
690 943 ▶{
Subroutine html_tag: called CC=4 SCAR=13.9
Pod documented
691 943 my($self) = shift;
692  
693 943 ▶ if($self->html_element && $self->apply_error_class && defined $self->error)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->html_element and $self->apply_error_class and defined $self->error) { } 2 941 943
Condition83%5/6
$self->html_element and $self->apply_error_class and defined $self->error
!ll&&!rl&&r
49372
$self->html_element and $self->apply_error_class
!ll&&!rl&&r
40939
MC/DC66%2/3
$self->html_element and $self->apply_error_class and defined $self->error
$self->html_element $self->apply_error_class defined $self->error
Truth table75%3/4
A and B and C
A= $self->html_elementB= $self->apply_error_classC= defined $self->error
ABCresult
0XX0
10X0
1100
1111
694 {
695 2 $self->add_class('error');
696  
697 2 my $html = $self->Rose::HTML::Object::html_tag(@_);
698  
699 2 $self->delete_class('error');
700  
701 2 return $html;
702 }
703 else
704 {
705 941 $self->SUPER::html_tag(@_);
706 }
707 }
708  
709 sub xhtml_tag
710 453 ▶{
Subroutine xhtml_tag: called CC=4 SCAR=13.9
Pod documented
711 453 my($self) = shift;
712  
713 453 ▶ if($self->html_element && $self->apply_error_class && defined $self->error)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->html_element and $self->apply_error_class and defined $self->error) { } 2 451 453
Condition83%5/6
$self->html_element and $self->apply_error_class and defined $self->error
!ll&&!rl&&r
44472
$self->html_element and $self->apply_error_class
!ll&&!rl&&r
40449
MC/DC66%2/3
$self->html_element and $self->apply_error_class and defined $self->error
$self->html_element $self->apply_error_class defined $self->error
Truth table75%3/4
A and B and C
A= $self->html_elementB= $self->apply_error_classC= defined $self->error
ABCresult
0XX0
10X0
1100
1111
714 {
715 2 $self->add_class('error');
716  
717 2 my $html = $self->Rose::HTML::Object::xhtml_tag(@_);
718  
719 2 $self->delete_class('error');
720  
721 2 return $html;
722 }
723 else
724 {
725 451 $self->SUPER::xhtml_tag(@_);
726 }
727 }
728  
729 35 *html_field = \&html_tag;
730 35 *xhtml_field = \&xhtml_tag;
731  
732 sub html
733 50 ▶{
Subroutine html: called CC=2 SCAR=6.9
Pod documented
734 50 my($self) = shift;
735  
736 50 my($field, $error);
737  
738 50 $field = $self->html_field;
739 50 $error = $self->html_error;
740  
741 50 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 5 45 50
742 {
743 5 return $field . $self->html_error_separator . $error;
744 }
745  
746 45 return $field;
747 }
748  
749 sub xhtml
750 32 ▶{
Subroutine xhtml: called CC=2 SCAR=6.9
Pod documented
751 32 my($self) = shift;
752  
753 32 my($field, $error);
754  
755 32 $field = $self->xhtml_field;
756 32 $error = $self->xhtml_error;
757  
758 32 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 4 28 32
759 {
760 4 return $field . $self->xhtml_error_separator . $error;
761 }
762  
763 28 return $field;
764 }
765  
766 # sub label
767 # {
768 #
769 # }
770  
771 sub label_object
772 406 ▶{
Subroutine label_object: called CC=8 SCAR=22.1
Pod documented
773 406 my($self) = shift;
774 406 ▶ my $label = $self->{'label_object'} ||= ref($self)->object_type_class_loaded('label')->new();
Condition66%2/3
$self->{"label_object"} ||= ref($self)->object_type_class_loaded("label")->new
l!l&&r!l&&!r
369370
MC/DC0%0/2
$self->{"label_object"} ||= ref($self)->object_type_class_loaded("label")->new
$self->{"label_object"} ref($self)->object_type_class_loaded("label")->new
Truth table66%2/3
A ||= B
A= $self->{"label_object"}B= ref($self)->object_type_class_loaded("label")->new
ABresult
1X1
011
000
775  
776 406 ▶ $label->contents($self->escape_html ? __escape_html($self->label) :
Branch: 1 branch
BranchTrueFalseTotal
$self->escape_html ? : 396 10 406
777 $self->label);
778  
779 406 ▶ if($self->html_attr_exists('id'))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->html_attr_exists("id")) 26 380 406
780 {
781 26 $label->for($self->html_attr('id'));
782 }
783  
784 $self->required ?
785 406 ▶ $label->add_class('required') :
Branch: 1 branch
BranchTrueFalseTotal
$self->required ? : 10 396 406
786 $label->delete_class('required');
787  
788 406 ▶ defined $self->error ?
Branch: 1 branch
BranchTrueFalseTotal
defined $self->error ? : 7 399 406
789 $label->add_class('error') :
790 $label->delete_class('error');
791  
792 406 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 406 406
793 {
794 0 my %args = @_;
795  
796 0 ▶ while(my($k, $v) = each(%args))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 0 0 0
797 {
798 0 $label->html_attr($k => $v);
799 }
800 }
801  
802 406 return $label;
803 }
804  
805 sub html_label
806 400 ▶{
Subroutine html_label: called CC=2 SCAR=6.9
Pod documented
807 400 my($self) = shift;
808 35 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
809 400 ▶ return '' unless(length $self->label);
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->label 8 392 400
810 392 return $self->label_object(@_)->html_tag;
811 }
812  
813 sub xhtml_label
814 25 ▶{
Subroutine xhtml_label: called CC=2 SCAR=6.9
Pod documented
815 25 my($self) = shift;
816 35 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
817 25 ▶ return '' unless(length $self->label);
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->label 14 11 25
818 11 return $self->label_object(@_)->xhtml_tag;
819 }
820  
821 sub validate
822 214 ▶{
Subroutine validate: called CC=12 SCAR=25.7
Pod documented
823 214 my($self) = shift;
824  
825 214 $self->error(undef);
826  
827 214 my $value = $self->internal_value;
828  
829 214 ▶ if($self->required &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->required and !ref($value) && (!defined($value) || $self->trim_spaces && !($value =~ /\S/)) || ref $value eq "ARRAY" && !@$value) 21 193 214
Condition72%13/18
$self->required and !ref($value) && (!defined($value) || $self->trim_spaces && !($value =~ /\S/)) || ref $value eq "ARRAY" && !@$value
!ll&&!rl&&r
1593421
not ref $value and !defined($value) || $self->trim_spaces && !($value =~ /\S/) or ref $value eq "ARRAY" and not @$value
l!l&&r!l&&!r
21034
not ref $value and !defined($value) || $self->trim_spaces && !($value =~ /\S/)
!ll&&!rl&&r
03421
not defined $value or $self->trim_spaces and not $value =~ /\S/
l!l&&r!l&&!r
19234
$self->trim_spaces and not $value =~ /\S/
!ll&&!rl&&r
0342
ref $value eq "ARRAY" and not @$value
!ll&&!rl&&r
3400
MC/DC42%3/7
$self->required and !ref($value) && (!defined($value) || $self->trim_spaces && !($value =~ /\S/)) || ref $value eq "ARRAY" && !@$value
$self->required not ref $value not defined $value $self->trim_spaces not $value =~ /\S/ ref $value eq "ARRAY" not @$value
Truth table33%4/12
A and not(B) and not(C) or D and not(E) or F and not(G)
A= $self->requiredB= not ref $valueC= not defined $valueD= $self->trim_spacesE= not $value =~ /\S/F= ref $value eq "ARRAY"G= not @$value
ABCDEFGresult
0XXXXXX0
10XXX0X0
10XXX100
1100X0X0
1100X100
110100X0
11010100
111XXXX1
11011XX1
10XXX111
1100X111
11010111
830 ((!ref $value && (!defined $value || ($self->trim_spaces && $value !~ /\S/))) ||
831 (ref $value eq 'ARRAY' && !@$value)))
832 {
833 21 ▶ unless($self->is_empty && $self->empty_is_ok)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_empty and $self->empty_is_ok) 21 0 21
Condition33%1/3
$self->is_empty and $self->empty_is_ok
!ll&&!rl&&r
0210
MC/DC0%0/2
$self->is_empty and $self->empty_is_ok
$self->is_empty $self->empty_is_ok
Truth table33%1/3
A and B
A= $self->is_emptyB= $self->empty_is_ok
ABresult
0X0
100
111
834 {
835 21 my $label = $self->error_label;
836  
837 21 ▶ if(defined $label)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $label) { } 7 14 21
838 {
839 #$self->add_error_id(FIELD_REQUIRED, $label);
840 #$self->add_error_id(FIELD_REQUIRED, [ $label ]);
841 7 $self->add_error_id(FIELD_REQUIRED, { label => $label });
842 }
843 else
844 {
845 14 $self->add_error_id(FIELD_REQUIRED);
846 }
847  
848 21 return 0;
849 }
850 }
851  
852 193 ▶ return $self->validate_with_validator($value) if($self->validator);
Branch: 1 branch
BranchTrueFalseTotal
if $self->validator 2 191 193
853  
854 191 return 1;
855 }
856  
857 sub validate_with_validator
858 2 ▶{
Subroutine validate_with_validator: called CC=5 SCAR=16.6
Pod undocumented
859 2 my($self, $value) = @_;
860  
861 2 ▶ my $code = $self->validator or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $code = $self->validator or return 1 2 0 2
862  
863 2 local $_ = $value;
864 #$Debug && warn "running $code->($self)\n";
865 2 my $ok = $code->($self);
866  
867 2 ▶ if(!$ok && !$self->has_errors)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok or $self->has_errors) 1 1 2
Condition66%2/3
$ok or $self->has_errors
l!l&&r!l&&!r
101
MC/DC50%1/2
$ok or $self->has_errors
$ok $self->has_errors
Truth table66%2/3
A or B
A= $okB= $self->has_errors
ABresult
1X1
011
000
868 {
869 1 my $label = $self->label;
870  
871 1 ▶ if(defined $label)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $label) { } 0 1 1
872 {
873 0 $self->add_error_id(FIELD_INVALID, { label => $label })
874 }
875 else
876 {
877 1 $self->add_error_id(FIELD_INVALID);
878 }
879 }
880  
881 2 return $ok;
882 }
883  
884 sub validator
885 214 ▶{
Subroutine validator: called CC=3 SCAR=11.2
Pod documented
886 214 my($self) = shift;
887  
888 214 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 212 214
889 {
890 2 my $code = shift;
891  
892 2 ▶ if(ref $code eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $code eq 'CODE') { } 2 0 2
893 {
894 2 return $self->{'validator'} = $code;
895 }
896 else
897 {
898 0 Carp::croak ref($self), "::validator() - argument must be a code reference";
899 }
900 }
901  
902 212 return $self->{'validator'};
903 }
904  
905 35 *__escape_html = \&Rose::HTML::Util::escape_html;
906  
907 sub message_for_error_id
908 90 ▶{
Subroutine message_for_error_id: called CC=13 SCAR=27.7
Pod documented
909 90 my($self, %args) = @_;
910  
911 90 my $error_id = $args{'error_id'};
912 90 ▶ my $msg_class = $args{'msg_class'} || $self->localizer->message_class;
Condition66%2/3
$args{'msg_class'} || $self->localizer->message_class
l!l&&r!l&&!r
8820
MC/DC0%0/2
$args{'msg_class'} || $self->localizer->message_class
$args{'msg_class'} $self->localizer->message_class
Truth table66%2/3
A || B
A= $args{'msg_class'}B= $self->localizer->message_class
ABresult
1X1
011
000
913 90 ▶ my $args = $args{'args'} || [];
Condition100%2/2
$args{'args'} || []
l!l
5139
MC/DC100%1/1
$args{'args'} || []
$args{'args'}
Truth table100%2/2
A
A= $args{'args'}
Aresult
11
00
914  
915 35 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
916 90 ▶ if($error_id == FIELD_REQUIRED)
Branch: 2 branches
BranchTrueFalseTotal
if ($error_id == 3) { } 25 65 90
elsif ($error_id == 9) { } 1 64 65
917 {
918 25 my $msg = $msg_class->new(args => $args);
919  
920 25 ▶ if((ref $args eq 'HASH' && keys %$args) || (ref $args eq 'ARRAY' && @$args))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args eq 'HASH' and keys %$args or ref $args eq 'ARRAY' and @$args) { } 6 19 25
Condition55%5/9
ref $args eq "HASH" and keys %$args or ref $args eq "ARRAY" and @$args
l!l&&r!l&&!r
6019
ref $args eq "HASH" and keys %$args
!ll&&!rl&&r
1906
ref $args eq "ARRAY" and @$args
!ll&&!rl&&r
0190
MC/DC25%1/4
ref $args eq "HASH" and keys %$args or ref $args eq "ARRAY" and @$args
ref $args eq "HASH" keys %$args ref $args eq "ARRAY" @$args
Truth table28%2/7
A and B or C and D
A= ref $args eq "HASH"B= keys %$argsC= ref $args eq "ARRAY"D= @$args
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
921 {
922 6 $msg->id(FIELD_REQUIRED_LABELLED);
923 }
924 else
925 {
926 19 $msg->id(FIELD_REQUIRED_GENERIC);
927 }
928  
929 25 return $msg;
930 }
931 elsif($error_id == FIELD_INVALID)
932 {
933 1 my $msg = $msg_class->new(args => $args);
934  
935 1 ▶ if((ref $args eq 'HASH' && keys %$args) || (ref $args eq 'ARRAY' && @$args))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args eq 'HASH' and keys %$args or ref $args eq 'ARRAY' and @$args) { } 0 1 1
Condition33%3/9
ref $args eq "HASH" and keys %$args or ref $args eq "ARRAY" and @$args
l!l&&r!l&&!r
001
ref $args eq "HASH" and keys %$args
!ll&&!rl&&r
100
ref $args eq "ARRAY" and @$args
!ll&&!rl&&r
010
MC/DC0%0/4
ref $args eq "HASH" and keys %$args or ref $args eq "ARRAY" and @$args
ref $args eq "HASH" keys %$args ref $args eq "ARRAY" @$args
Truth table14%1/7
A and B or C and D
A= ref $args eq "HASH"B= keys %$argsC= ref $args eq "ARRAY"D= @$args
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
936 {
937 0 $msg->id(FIELD_INVALID_LABELLED);
938 }
939 else
940 {
941 1 $msg->id(FIELD_INVALID_GENERIC);
942 }
943  
944 1 return $msg;
945 }
946  
947 64 return undef;
948 }
949  
950 1 ▶sub localize_label { shift->label_message_id(FIELD_LABEL) }
Subroutine localize_label: called CC=1 SCAR=0.0
Pod undocumented
951 1 ▶sub localize_description { shift->description_message_id(FIELD_DESCRIPTION) }
Subroutine localize_description: called CC=1 SCAR=0.0
Pod undocumented
952  
953 # XXX: Ths sub contains a lame hack to work around an incompatibility with
954 # XXX: Scalar::Defer 0.11 - it manually detects and evaluates code refs.
955 sub localizer
956 5455 ▶{
Subroutine localizer: called CC=14 SCAR=33.4
Pod documented
957 5455 my($invocant) = shift;
958  
959 # Called as object method
960 5455 ▶ if(my $class = ref $invocant)
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = ref $invocant) { } 5311 144 5455
961 {
962 5311 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 5311 5311
963 {
964 0 $invocant->{'localizer'} = shift;
965  
966 0 ▶ if(ref $invocant->{'localizer'} eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $invocant->{'localizer'} eq 'CODE') { } 0 0 0
967 {
968 0 return $invocant->{'localizer'}->();
969 }
970 else
971 {
972 0 return $invocant->{'localizer'};
973 }
974 }
975  
976 5311 my $localizer = $invocant->{'localizer'};
977  
978 5311 ▶ unless($localizer)
Branch: 1 branch
BranchTrueFalseTotal
unless ($localizer) 5311 0 5311
979 {
980 5311 ▶ if(my $parent_field = $invocant->parent_field)
Branch: 2 branches
BranchTrueFalseTotal
if (my $parent_field = $invocant->parent_field) { } 21 5290 5311
elsif (my $parent_form = $invocant->parent_form) { } 183 5107 5290
981 {
982 21 ▶ if(my $localizer = $parent_field->localizer)
Branch: 1 branch
BranchTrueFalseTotal
if (my $localizer = $parent_field->localizer) 21 0 21
983 {
984 21 ▶ return (ref $localizer eq 'CODE') ? $localizer->() : $localizer;
Branch: 1 branch
BranchTrueFalseTotal
ref $localizer eq 'CODE' ? : 0 21 21
985 }
986 }
987 elsif(my $parent_form = $invocant->parent_form)
988 {
989 183 ▶ if(my $localizer = $parent_form->localizer)
Branch: 1 branch
BranchTrueFalseTotal
if (my $localizer = $parent_form->localizer) 183 0 183
990 {
991 183 ▶ return (ref $localizer eq 'CODE') ? $localizer->() : $localizer;
Branch: 1 branch
BranchTrueFalseTotal
ref $localizer eq 'CODE' ? : 0 183 183
992 }
993 }
994 5107 else { return $class->default_localizer }
995 }
996  
997 0 ▶ if(ref $localizer eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $localizer eq "CODE") 0 0 0
998 {
999 0 return $localizer->();
1000 }
1001  
1002 0 ▶ return $localizer || $class->default_localizer;
Condition0%0/3
$localizer || $class->default_localizer
l!l&&r!l&&!r
000
MC/DC0%0/2
$localizer || $class->default_localizer
$localizer $class->default_localizer
Truth table0%0/3
A || B
A= $localizerB= $class->default_localizer
ABresult
1X1
011
000
1003 }
1004 else # Called as class method
1005 {
1006 144 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 143 144
1007 {
1008 1 return $invocant->default_localizer(shift);
1009 }
1010  
1011 143 return $invocant->default_localizer;
1012 }
1013 }
1014  
1015 # XXX: Ths sub contains a lame hack to work around an incompatibility with
1016 # XXX: Scalar::Defer 0.11 - it manually detects and evaluates code refs.
1017 sub locale
1018 4064 ▶{
Subroutine locale: called CC=19 SCAR=34.4
Pod documented
1019 4064 my($invocant) = shift;
1020  
1021 # Called as object method
1022 4064 ▶ if(my $class = ref $invocant)
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = ref $invocant) { } 4064 0 4064
1023 {
1024 4064 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 20 4044 4064
1025 {
1026 20 $invocant->{'locale'} = shift;
1027  
1028 20 ▶ if(ref $invocant->{'locale'} eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $invocant->{'locale'} eq 'CODE') { } 0 20 20
1029 {
1030 0 return $invocant->{'locale'}->();
1031 }
1032 else
1033 {
1034 20 return $invocant->{'locale'};
1035 }
1036 }
1037  
1038 4044 my $locale = $invocant->{'locale'};
1039  
1040 4044 ▶ if($locale)
Branch: 1 branch
BranchTrueFalseTotal
if ($locale) 48 3996 4044
1041 {
1042 48 ▶ return (ref $locale eq 'CODE') ? $locale->() : $locale;
Branch: 1 branch
BranchTrueFalseTotal
ref $locale eq 'CODE' ? : 0 48 48
1043 }
1044  
1045 3996 ▶ if(my $parent_field = $invocant->parent_field)
Branch: 3 branches
BranchTrueFalseTotal
if (my $parent_field = $invocant->parent_field) { } 17 3979 3996
elsif (my $parent_form = $invocant->parent_form) { } 301 3678 3979
elsif ($invocant->can('parent_group') and my $parent_group = $invocant->parent_group) { } 1599 2079 3678
1046 {
1047 17 ▶ if(my $locale = $parent_field->locale)
Branch: 1 branch
BranchTrueFalseTotal
if (my $locale = $parent_field->locale) 17 0 17
1048 {
1049 17 ▶ return (ref $locale eq 'CODE') ? $locale->() : $locale;
Branch: 1 branch
BranchTrueFalseTotal
ref $locale eq 'CODE' ? : 0 17 17
1050 }
1051 }
1052 elsif(my $parent_form = $invocant->parent_form)
1053 {
1054 301 ▶ if(my $locale = $parent_form->locale)
Branch: 1 branch
BranchTrueFalseTotal
if (my $locale = $parent_form->locale) 301 0 301
1055 {
1056 301 ▶ return (ref $locale eq 'CODE') ? $locale->() : $locale;
Branch: 1 branch
BranchTrueFalseTotal
ref $locale eq 'CODE' ? : 0 301 301
1057 }
1058 }
1059 ▶ elsif($invocant->can('parent_group') && (my $parent_group = $invocant->parent_group))
Condition66%2/3
$invocant->can("parent_group") and my $parent_group = $invocant->parent_group
!ll&&!rl&&r
020791599
MC/DC50%1/2
$invocant->can("parent_group") and my $parent_group = $invocant->parent_group
$invocant->can("parent_group") my $parent_group = $invocant->parent_group
Truth table66%2/3
A and B
A= $invocant->can("parent_group")B= my $parent_group = $invocant->parent_group
ABresult
0X0
100
111
1060 {
1061 1599 ▶ if(my $locale = $parent_group->locale)
Branch: 1 branch
BranchTrueFalseTotal
if (my $locale = $parent_group->locale) 1599 0 1599
1062 {
1063 1599 ▶ return (ref $locale eq 'CODE') ? $locale->() : $locale;
Branch: 1 branch
BranchTrueFalseTotal
ref $locale eq 'CODE' ? : 0 1599 1599
1064 }
1065 }
1066 else
1067 {
1068 2079 my $locale = $invocant->localizer->locale;
1069  
1070 2079 ▶ if(ref $locale eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $locale eq "CODE") 0 2079 2079
1071 {
1072 0 return $locale->();
1073 }
1074  
1075 2079 ▶ return $locale || $class->default_locale;
Condition33%1/3
$locale || $class->default_locale
l!l&&r!l&&!r
207900
MC/DC0%0/2
$locale || $class->default_locale
$locale $class->default_locale
Truth table33%1/3
A || B
A= $localeB= $class->default_locale
ABresult
1X1
011
000
1076 }
1077 }
1078 else # Called as class method
1079 {
1080 0 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1081 {
1082 0 return $invocant->default_locale(shift);
1083 }
1084  
1085 0 return $invocant->default_locale;
1086 }
1087 }
1088  
1089 103 ▶sub prepare { }
Subroutine prepare: called CC=1 SCAR=0.0
Pod documented
1090  
1091 35 ▶if(__PACKAGE__->localizer->auto_load_messages)
Branch: 1 branch
BranchTrueFalseTotal
if (__PACKAGE__->localizer->auto_load_messages) 1 34 35
1092 {
1093 1 __PACKAGE__->localizer->load_all_messages;
1094 }
1095  
1096 35 ▶use utf8; # The __DATA__ section contains UTF-8 text
Subroutine BEGIN: called CC=1 SCAR=0.0
1097  
1098 35 1;
1099  
1100 __DATA__
« blib/lib/Rose/HTML/Form/Field/Collection.pm ↑ Summary blib/lib/Rose/HTML/Object/Error.pm »