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

filter: Statementstmt 83.3% 230 / 276 Branchbran 63.0% 87 / 138 Conditioncond 42.3% 11 / 26 MC/DCmcdc 23.5% 4 / 17 Subroutinesub 87.2% 41 / 47 Podpod 9.3% 3 / 32 totaltotal 70.1% 376 / 536 CC 92 SCAR 22.6
CC
92
Cov
75%
find_parent_field
56.0
add_prepare_hook
20.7
children
20.0
CRAP 9.6
« blib/lib/Rose/HTML/Form/Repeatable.pm ↑ Summary blib/lib/Rose/HTML/Form/Field.pm »
1 package Rose::HTML::Form::Field::Collection;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 12 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 12 ▶use Rose::HTML::Form::Field::Hidden;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 ▶use base 'Rose::HTML::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 12 ▶use Rose::HTML::Form::Constants qw(FF_SEPARATOR);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # Variables for use in regexes
15 12 our $FF_SEPARATOR_RE = quotemeta FF_SEPARATOR;
16  
17 12 our $VERSION = '0.606';
18  
19 #
20 # Object data
21 #
22  
23 use Rose::Object::MakeMethods::Generic
24 (
25 12 boolean => 'coalesce_hidden_fields',
26  
27 'scalar --get_set_init' =>
28 [
29 'field_rank_counter',
30 ],
31  
32 array =>
33 [
34 'before_prepare_hooks' => {},
35 'add_before_prepare_hooks' => { interface => 'push', hash_key => 'before_prepare_hooks' },
36  
37 'after_prepare_hooks' => {},
38 'add_after_prepare_hooks' => { interface => 'push', hash_key => 'after_prepare_hooks' },
39 'clear_prepare_hooks' => { interface => 'clear', hash_key => 'after_prepare_hooks' },
40 ],
41 12 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 12 *add_before_prepare_hook = \&add_before_prepare_hooks;
44 12 *add_after_prepare_hook = \&add_after_prepare_hooks;
45  
46 #
47 # Class methods
48 #
49  
50 sub prepare
51 {
52 56 ▶ my($self) = shift;
Subroutine prepare: called CC=6 SCAR=18.1
Pod undocumented
53  
54 56 foreach my $hook ($self->before_prepare_hooks)
55 {
56 0 $hook->($self, @_);
57 }
58  
59 56 my %args = @_;
60  
61 56 ▶ unless($args{'form_only'})
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"form_only"}) 31 25 56
62 {
63 31 foreach my $field ($self->fields)
64 {
65 103 $field->prepare(@_);
66 }
67 }
68  
69 56 foreach my $form ($self->forms)
70 {
71 25 $form->prepare(form_only => 1, @_);
72 }
73  
74 56 foreach my $hook ($self->after_prepare_hooks)
75 {
76 0 $hook->($self, @_);
77 }
78 }
79  
80 sub add_prepare_hook
81 {
82 0 ▶ my($self) = shift;
Subroutine add_prepare_hook: not called CC=5 SCAR=30.3
Pod undocumented
83  
84 0 ▶ if(@_ == 1)
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
elsif (@_ == 2) { } 0 0 0
85 {
86 0 $self->add_before_prepare_hook(@_);
87 }
88 elsif(@_ == 2)
89 {
90 0 my $where = shift;
91  
92 0 ▶ unless($where eq 'before' || $where eq 'after')
Branch: 1 branch
BranchTrueFalseTotal
unless ($where eq "before" or $where eq "after") 0 0 0
Condition0%0/3
$where eq "before" or $where eq "after"
l!l&&r!l&&!r
000
MC/DC0%0/2
$where eq "before" or $where eq "after"
$where eq "before" $where eq "after"
Truth table0%0/3
A or B
A= $where eq "before"B= $where eq "after"
ABresult
1X1
011
000
93 {
94 0 Carp::croak "Illegal prepare hook position: $where";
95 }
96  
97 0 my $method = "add_${where}_prepare_hook";
98  
99 12 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
100 0 $self->$method(@_);
101 }
102 else
103 {
104 0 Carp::croak "Incorrect number of arguments to add_prepare_hook()";
105 }
106 }
107  
108 sub prepare_hook
109 {
110 0 ▶ my($self) = shift;
Subroutine prepare_hook: not called CC=1 SCAR=6.9
Pod undocumented
111 0 $self->clear_prepare_hooks;
112 0 $self->add_prepare_hook(@_);
113 }
114  
115 BEGIN
116 {
117 12 ▶ *add_field_type_classes = \&Rose::HTML::Object::add_object_type_classes;
Subroutine BEGIN: called CC=1 SCAR=0.0
118 12 *field_type_classes = \&Rose::HTML::Object::object_type_classes;
119 12 *field_type_class = \&Rose::HTML::Object::object_type_class;
120 12 *delete_field_type_class = \&Rose::HTML::Object::delete_object_type_class;
121 }
122  
123 #
124 # Object methods
125 #
126  
127 sub html
128 {
129 1 ▶ my($self) = shift;
Subroutine html: called CC=4 SCAR=14.6
Pod documented
130  
131 12 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
132  
133 1 ▶ if($self->has_children || !$self->is_self_closing)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_children or not $self->is_self_closing) 1 0 1
Condition33%1/3
$self->has_children or not $self->is_self_closing
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->has_children or not $self->is_self_closing
$self->has_children not $self->is_self_closing
Truth table33%1/3
A or not(B)
A= $self->has_childrenB= not $self->is_self_closing
ABresult
1X1
011
000
134 {
135 return '<' . $self->html_element . $self->html_attrs_string . '>' .
136 join('', map
137 {
138 1 ▶ $_->isa('Rose::HTML::Form::Field') ?
Branch: 1 branch
BranchTrueFalseTotal
$_->isa('Rose::HTML::Form::Field') ? : 2 2 4
139 '<div class="field-with-label">' . $_->html_label .
140 '<div class="field">' . $_->html . '</div></div>' :
141 $_->html
142 }
143 $self->children) .
144 '</' . $self->html_element . '>';
145 }
146  
147 0 return '<' . $self->html_element . $self->html_attrs_string . '>';
148 }
149  
150 sub xhtml
151 {
152 1 ▶ my($self) = shift;
Subroutine xhtml: called CC=4 SCAR=14.6
Pod documented
153  
154 12 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
155  
156 1 ▶ if($self->has_children || !$self->is_self_closing)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_children or not $self->is_self_closing) 1 0 1
Condition33%1/3
$self->has_children or not $self->is_self_closing
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->has_children or not $self->is_self_closing
$self->has_children not $self->is_self_closing
Truth table33%1/3
A or not(B)
A= $self->has_childrenB= not $self->is_self_closing
ABresult
1X1
011
000
157 {
158 return '<' . $self->xhtml_element . $self->xhtml_attrs_string . '>' .
159 join('', map
160 {
161 1 ▶ $_->isa('Rose::HTML::Form::Field') ?
Branch: 1 branch
BranchTrueFalseTotal
$_->isa('Rose::HTML::Form::Field') ? : 2 2 4
162 '<div class="field-with-label">' . $_->xhtml_label .
163 '<div class="field">' . $_->xhtml . '</div></div>' :
164 $_->xhtml
165 }
166 $self->children) .
167 '</' . $self->xhtml_element . '>';
168 }
169  
170 0 return '<' . $self->xhtml_element . $self->xhtml_attrs_string . ' />';
171 }
172  
173 151 ▶sub init_field_rank_counter { 1 }
Subroutine init_field_rank_counter: called CC=1 SCAR=0.0
Pod undocumented
174  
175 sub increment_field_rank_counter
176 {
177 472 ▶ my($self) = shift;
Subroutine increment_field_rank_counter: called CC=1 SCAR=0.0
Pod undocumented
178 472 my $rank = $self->field_rank_counter;
179 472 $self->field_rank_counter($rank + 1);
180 472 return $rank;
181 }
182  
183 sub make_field
184 {
185 624 ▶ my($self, $name, $value) = @_;
Subroutine make_field: called CC=10 SCAR=23.5
Pod undocumented
186  
187 624 ▶ return $value if(UNIVERSAL::isa($value, 'Rose::HTML::Form::Field'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($value, "Rose::HTML::Form::Field") 222 402 624
188  
189 402 my($type, $args);
190  
191 402 ▶ if(ref $value eq 'HASH')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'HASH') { } 330 72 402
elsif (not ref $value) { } 72 0 72
192 {
193 330 ▶ $type = delete $value->{'type'} or Carp::croak "Missing field type";
Branch: 1 branch
BranchTrueFalseTotal
$type = delete $value->{"type"} or Carp::croak("Missing field type") 0 330 330
194 330 $args = $value;
195 }
196 elsif(!ref $value)
197 {
198 72 $type = $value;
199 72 $args = {};
200 }
201 else
202 {
203 0 Carp::croak "Not a Rose::HTML::Form::Field object or hash ref: $value";
204 }
205  
206 402 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
40200
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
207  
208 402 ▶ my $field_class = $class->field_type_class($type)
Branch: 1 branch
BranchTrueFalseTotal
my $field_class = $class->field_type_class($type) or Carp::croak("No field class found for field type '${type}'") 0 402 402
209 or Carp::croak "No field class found for field type '$type'";
210  
211 402 ▶ unless($field_class->can('new'))
Branch: 1 branch
BranchTrueFalseTotal
unless ($field_class->can("new")) 8 394 402
212 {
213 8 my $error;
214  
215 TRY:
216 {
217 8 local $@;
218 8 eval "require $field_class";
219 8 $error = $@;
220 }
221  
222 8 ▶ Carp::croak "Failed to load field class $field_class - $error" if($error);
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 8 8
223 }
224  
225 # Compound fields require a name
226 402 ▶ if(UNIVERSAL::isa($field_class, 'Rose::HTML::Form::Field::Compound'))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($field_class, "Rose::HTML::Form::Field::Compound")) 46 356 402
227 {
228 46 $args->{'name'} = $name;
229 }
230  
231 402 return $field_class->new(%$args);
232 }
233  
234 sub invalidate_field_caches
235 {
236 625 ▶ my($self) = shift;
Subroutine invalidate_field_caches: called CC=1 SCAR=0.0
Pod undocumented
237  
238 625 $self->{'field_cache'} = {};
239 }
240  
241 sub field
242 {
243 3539 ▶ my($self, $name, $field) = @_;
Subroutine field: called CC=9 SCAR=23.7
Pod undocumented
244  
245 3539 ▶ if(@_ == 3)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 3) 254 3285 3539
246 {
247 254 ▶ unless(UNIVERSAL::isa($field, 'Rose::HTML::Form::Field'))
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($field, "Rose::HTML::Form::Field")) 0 254 254
248 {
249 0 $field = $self->make_field($name, $field);
250 }
251  
252 254 $field->local_moniker($name);
253  
254 254 ▶ if($self->isa('Rose::HTML::Form'))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa('Rose::HTML::Form')) { } 0 254 254
255 {
256 0 $field->parent_form($self);
257 }
258 else
259 {
260 254 $field->parent_field($self);
261 }
262  
263 254 $self->_clear_field_generated_values;
264  
265 254 ▶ unless(defined $field->rank)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $field->rank) 0 254 254
266 {
267 0 $field->rank($self->increment_field_rank_counter);
268 }
269  
270 254 return $self->{'fields'}{$name} = $self->{'field_cache'}{$name} = $field;
271 }
272  
273 3285 ▶ if($self->{'fields'}{$name})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"fields"}{$name}) 3252 33 3285
274 {
275 3252 return $self->{'fields'}{$name};
276 }
277  
278 33 my $sep_pos;
279  
280 # Non-hierarchical name
281 33 ▶ if(($sep_pos = index($name, FF_SEPARATOR)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (($sep_pos = index($name, ".")) < 0) 0 33 33
282 {
283 0 return undef; # $self->local_field($name, @_);
284 }
285  
286 # Check if it's a local compound field
287 33 my $prefix = substr($name, 0, $sep_pos);
288 33 my $rest = substr($name, $sep_pos + 1);
289 33 $field = $self->field($prefix);
290  
291 33 ▶ if(UNIVERSAL::isa($field, 'Rose::HTML::Form::Field::Compound'))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($field, "Rose::HTML::Form::Field::Compound")) 33 0 33
292 {
293 33 $field = $field->field($rest);
294 33 ▶ return ($self->{'field_cache'}{$name} = $field) if($field);
Branch: 1 branch
BranchTrueFalseTotal
if $field 33 0 33
295 }
296  
297 0 return undef;
298 }
299  
300 sub find_parent_field
301 {
302 0 ▶ my($self, $name) = @_;
Subroutine find_parent_field: not called CC=7 SCAR=40.3
Pod undocumented
303  
304 # Non-hierarchical name
305 0 ▶ if(index($name, FF_SEPARATOR) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (index($name, ".") == -1) 0 0 0
306 {
307 0 ▶ return $self->local_form($name) ? ($self, $name) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->local_form($name) ? : 0 0 0
308 }
309  
310 0 my $parent_form;
311  
312 0 ▶ while($name =~ s/^([^$FF_SEPARATOR_RE]+)$FF_SEPARATOR_RE//o)
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ s/^([^$Rose::HTML::Form::Field::Collection::FF_SEPARATOR_RE]+)$Rose::HTML::Form::Field::Collection::FF_SEPARATOR_RE//o) 0 0 0
313 {
314 0 my $parent_name = $1;
315 0 ▶ last if($parent_form = $self->local_form($parent_name));
Branch: 1 branch
BranchTrueFalseTotal
if $parent_form = $self->local_form($parent_name) 0 0 0
316 }
317  
318 0 ▶ return unless(defined $parent_form);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parent_form 0 0 0
319 0 ▶ return wantarray ? ($parent_form, $name) : $parent_form;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
320 }
321  
322 sub add_fields
323 {
324 199 ▶ my($self) = shift;
Subroutine add_fields: called CC=16 SCAR=28.0
Pod undocumented
325  
326 199 my @added_fields;
327  
328 199 ▶ @_ = @{$_[0]} if(@_ == 1 && ref $_[0] eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and ref $_[0] eq "ARRAY" 4 195 199
Condition100%3/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
19234
MC/DC100%2/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table100%3/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
329  
330 199 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 477 198 675
331 {
332 477 my $arg = shift;
333  
334 477 ▶ if(UNIVERSAL::isa($arg, 'Rose::HTML::Form::Field'))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($arg, 'Rose::HTML::Form::Field')) { } 5 472 477
335 {
336 5 my $field = $arg;
337  
338 5 ▶ if(refaddr($field) eq refaddr($self))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::refaddr($field) eq builtin::refaddr($self)) 0 5 5
339 {
340 0 Carp::croak "Cannot nest a field within itself";
341 }
342  
343 5 $field->local_name($field->name);
344  
345 5 ▶ if($self->can('form') && $self->form($field->local_name))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("form") and $self->form($field->local_name)) 0 5 5
Condition33%1/3
$self->can("form") and $self->form($field->local_name)
!ll&&!rl&&r
050
MC/DC0%0/2
$self->can("form") and $self->form($field->local_name)
$self->can("form") $self->form($field->local_name)
Truth table33%1/3
A and B
A= $self->can("form")B= $self->form($field->local_name)
ABresult
0X0
100
111
346 {
347 0 Carp::croak "Cannot add field with the same name as an existing sub-form: ",
348 $field->local_name;
349 }
350  
351 5 ▶ unless(defined $field->rank)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $field->rank) 4 1 5
352 {
353 4 $field->rank($self->increment_field_rank_counter);
354 }
355  
356 5 $self->field($field->local_name => $field);
357 5 push(@added_fields, $field);
358 }
359 else
360 {
361 472 my $field = shift;
362  
363 472 ▶ if($self->can('form') && $self->form($arg))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("form") and $self->form($arg)) 1 471 472
Condition100%3/3
$self->can("form") and $self->form($arg)
!ll&&!rl&&r
2542171
MC/DC100%2/2
$self->can("form") and $self->form($arg)
$self->can("form") $self->form($arg)
Truth table100%3/3
A and B
A= $self->can("form")B= $self->form($arg)
ABresult
0X0
100
111
364 {
365 1 Carp::croak "Cannot add field with the same name as an existing sub-form: $arg";
366 }
367  
368 471 ▶ if(UNIVERSAL::isa($field, 'Rose::HTML::Form::Field'))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($field, 'Rose::HTML::Form::Field')) { } 105 366 471
369 {
370 105 ▶ if(refaddr($field) eq refaddr($self))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::refaddr($field) eq builtin::refaddr($self)) 0 105 105
371 {
372 0 Carp::croak "Cannot nest a field within itself";
373 }
374 }
375 else
376 {
377 366 $field = $self->make_field($arg, $field);
378 }
379  
380 471 $field->local_moniker($arg);
381  
382 471 ▶ unless(defined $field->rank)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $field->rank) 468 3 471
383 {
384 468 $field->rank($self->increment_field_rank_counter);
385 }
386  
387 471 $self->field($arg => $field);
388 471 push(@added_fields, $field);
389 }
390 }
391  
392 198 $self->_clear_field_generated_values;
393 198 $self->resync_field_names;
394  
395 198 ▶ return unless(defined wantarray);
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 160 38 198
396 38 ▶ return wantarray ? @added_fields : $added_fields[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 36 2 38
397 }
398  
399 23 ▶sub add_field { shift->add_fields(@_) }
Subroutine add_field: called CC=1 SCAR=0.0
Pod undocumented
400  
401 sub compare_fields
402 {
403 3555 ▶ my($self, $one, $two) = @_;
Subroutine compare_fields: called CC=1 SCAR=0.0
Pod undocumented
404 12 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
405 3555 $one->name cmp $two->name;
406 }
407  
408 sub resync_field_names
409 {
410 826 ▶ my($self) = shift;
Subroutine resync_field_names: called CC=3 SCAR=11.0
Pod undocumented
411  
412 826 foreach my $field ($self->fields)
413 {
414 2390 $field->resync_name;
415 2390 ▶ $field->resync_field_names if($field->isa('Rose::HTML::Form::Field::Compound'));
Branch: 1 branch
BranchTrueFalseTotal
if $field->isa("Rose::HTML::Form::Field::Compound") 206 2184 2390
416 #$field->name; # Pull the new name through to the name HTML attribute
417 }
418 }
419  
420 sub children
421 {
422 0 ▶ Carp::croak "Cannot set children() for a pseudo-group ($_[0])" if(@_ > 1);
Subroutine children: not called CC=4 SCAR=30.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 0 0
423 0 ▶ return wantarray ? shift->fields() : (shift->fields() || []);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
Condition0%0/2
(shift())->fields or []
l!l
00
MC/DC0%0/1
(shift())->fields or []
(shift())->fields
Truth table0%0/2
A
A= (shift())->fields
Aresult
11
00
424 }
425  
426 sub field_value
427 {
428 8 ▶ my($self, $name) = (shift, shift);
Subroutine field_value: called CC=3 SCAR=11.0
Pod undocumented
429  
430 8 ▶ my $field = $self->field($name)
Branch: 1 branch
BranchTrueFalseTotal
my $field = $self->field($name) or Carp::croak("No field named '${name}' in $self") 0 8 8
431 or Carp::croak "No field named '$name' in $self";
432  
433 8 ▶ return $field->input_value(@_) if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 7 8
434 7 return $field->internal_value;
435 }
436  
437 12 *subfield_value = \&field_value;
438  
439 sub subfield_names
440 {
441 20 ▶ my($self) = shift;
Subroutine subfield_names: called CC=4 SCAR=13.9
Pod undocumented
442  
443 20 my @names;
444  
445 20 foreach my $field ($self->fields)
446 {
447 41 ▶ push(@names, $field->name, ($field->can('_subfield_names') ? $field->_subfield_names : ()));
Branch: 1 branch
BranchTrueFalseTotal
$field->can('_subfield_names') ? : 38 3 41
448 }
449  
450 20 ▶ return wantarray ? @names : \@names;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 20 0 20
451 }
452  
453 sub _subfield_names
454 {
455 38 ▶ map { $_->can('subfield_names') ? $_->subfield_names : $_->name } shift->fields;
Subroutine _subfield_names: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$_->can('subfield_names') ? : 0 133 133
456 }
457  
458 sub fields
459 {
460 2351 ▶ my($self) = shift;
Subroutine fields: called CC=4 SCAR=13.9
Pod undocumented
461  
462 2351 ▶ if(my $fields = $self->{'field_list'})
Branch: 1 branch
BranchTrueFalseTotal
if (my $fields = $self->{"field_list"}) 2183 168 2351
463 {
464 2183 ▶ return wantarray ? @$fields : $fields;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2178 5 2183
465 }
466  
467 168 my $fields = $self->{'fields'};
468  
469 168 $self->{'field_list'} = [ grep { defined } map { $fields->{$_} } $self->field_monikers ];
470  
471 168 ▶ return wantarray ? @{$self->{'field_list'}} : $self->{'field_list'};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 168 0 168
472 }
473  
474 sub fields_as_children
475 {
476 13 ▶ my($self) = shift;
Subroutine fields_as_children: called CC=5 SCAR=16.2
Pod undocumented
477  
478 13 ▶ Carp::croak "Cannot directly set children() for a ", ref($self),
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 13 13
479 ". Use fields(), push_children(), pop_children(), etc." if(@_);
480  
481 13 my @children;
482  
483 13 foreach my $field ($self->fields)
484 {
485 12 ▶ if($field->is_flat_group)
Branch: 1 branch
BranchTrueFalseTotal
if ($field->is_flat_group) { } 1 11 12
486 {
487 1 push(@children, $field->items);
488 }
489 else
490 {
491 11 push(@children, $field);
492 }
493 }
494  
495 13 ▶ return wantarray ? @children : \@children;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 13 0 13
496 }
497  
498 12 *immutable_children = \&fields_as_children;
499  
500 sub num_fields
501 {
502 5 ▶ my $fields = shift->fields;
Subroutine num_fields: called CC=3 SCAR=13.1
Pod undocumented
503 5 ▶ return $fields && @$fields ? scalar @$fields : 0;
Branch: 1 branch
BranchTrueFalseTotal
$fields && @$fields ? : 5 0 5
Condition33%1/3
$fields and @$fields
!ll&&!rl&&r
005
MC/DC0%0/2
$fields and @$fields
$fields @$fields
Truth table33%1/3
A and B
A= $fieldsB= @$fields
ABresult
0X0
100
111
504 }
505  
506 sub field_monikers
507 {
508 216 ▶ my($self) = shift;
Subroutine field_monikers: called CC=5 SCAR=16.1
Pod undocumented
509  
510 216 ▶ if(my $names = $self->{'field_monikers'})
Branch: 1 branch
BranchTrueFalseTotal
if (my $names = $self->{"field_monikers"}) 48 168 216
511 {
512 48 ▶ return wantarray ? @$names : $names;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 48 0 48
513 }
514  
515 168 my @info;
516  
517 168 ▶ while(my($name, $field) = each %{$self->{'fields'}})
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"fields"};}) 254 168 422
518 {
519 254 push(@info, [ $name, $field ]);
520 }
521  
522 $self->{'field_monikers'} =
523 168 [ map { $_->[0] } sort { $self->compare_fields($a->[1], $b->[1]) } @info ];
524  
525 168 ▶ return wantarray ? @{$self->{'field_monikers'}} : $self->{'field_monikers'};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 168 0 168
526 }
527  
528 sub delete_fields
529 {
530 0 ▶ my($self) = shift;
Subroutine delete_fields: not called CC=1 SCAR=6.9
Pod undocumented
531 0 $self->_clear_field_generated_values;
532 0 $self->{'fields'} = {};
533 0 $self->field_rank_counter(undef);
534 0 return;
535 }
536  
537 sub delete_field
538 {
539 0 ▶ my($self, $name) = @_;
Subroutine delete_field: not called CC=2 SCAR=17.9
Pod undocumented
540  
541 0 ▶ $name = $name->name if(UNIVERSAL::isa($name, 'Rose::HTML::Form::Field'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($name, "Rose::HTML::Form::Field") 0 0 0
542  
543 0 $self->_clear_field_generated_values;
544  
545 0 delete $self->{'field_cache'}{$name};
546 0 delete $self->{'fields'}{$name};
547 }
548  
549 sub clear_fields
550 {
551 493 ▶ my($self) = shift;
Subroutine clear_fields: called CC=2 SCAR=6.9
Pod undocumented
552  
553 493 foreach my $field ($self->fields)
554 {
555 1787 $field->clear();
556 }
557 }
558  
559 sub reset_fields
560 {
561 16 ▶ my($self) = shift;
Subroutine reset_fields: called CC=2 SCAR=6.9
Pod undocumented
562  
563 16 foreach my $field ($self->fields)
564 {
565 54 $field->reset();
566 }
567 }
568  
569 sub _clear_field_generated_values
570 {
571 625 ▶ my($self) = shift;
Subroutine _clear_field_generated_values: called CC=2 SCAR=6.9
572 625 $self->{'field_list'} = undef;
573 625 $self->{'field_monikers'} = undef;
574 625 $self->invalidate_field_caches;
575  
576 # XXX: This is super-incestuous
577 625 ▶ if(my $parent_form = $self->parent_form)
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent_form = $self->parent_form) 69 556 625
578 {
579 69 $parent_form->_clear_field_generated_values;
580 }
581 }
582  
583 sub hidden_field
584 {
585 12 ▶ my($self) = shift;
Subroutine hidden_field: called CC=1 SCAR=0.0
Pod undocumented
586  
587 12 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
588 12 my $name = $self->fq_name;
589  
590 return
591 12 ref($self)->object_type_class_loaded('hidden')->new(
592 name => $name,
593 value => $self->output_value);
594 }
595  
596 sub hidden_fields
597 {
598 22 ▶ my($self) = shift;
Subroutine hidden_fields: called CC=5 SCAR=16.1
Pod undocumented
599  
600 22 my @hidden;
601  
602 22 ▶ if($self->coalesce_hidden_fields)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->coalesce_hidden_fields) { } 6 16 22
603 {
604 6 foreach my $field ($self->fields)
605 {
606 24 push(@hidden, $field->hidden_field);
607 }
608 }
609 else
610 {
611 16 foreach my $field ($self->fields)
612 {
613 48 push(@hidden, $field->hidden_fields);
614 }
615 }
616  
617 22 ▶ return (wantarray) ? @hidden : \@hidden;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 22 0 22
618 }
619  
620 sub html_hidden_field
621 {
622 4 ▶ my($self) = shift;
Subroutine html_hidden_field: called CC=2 SCAR=6.9
Pod undocumented
623  
624 4 ▶ if(defined $self->output_value)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->output_value) 3 1 4
625 {
626 3 return $self->hidden_field->html_field;
627 }
628  
629 1 return $self->html_hidden_fields;
630 }
631  
632 sub xhtml_hidden_field
633 {
634 4 ▶ my($self) = shift;
Subroutine xhtml_hidden_field: called CC=2 SCAR=6.9
Pod undocumented
635  
636 4 ▶ if(defined $self->output_value)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->output_value) 3 1 4
637 {
638 3 return $self->hidden_field->xhtml_field;
639 }
640  
641 1 return $self->xhtml_hidden_fields;
642 }
643  
644 sub html_hidden_fields
645 {
646 10 ▶ my($self) = shift;
Subroutine html_hidden_fields: called CC=3 SCAR=11.1
Pod undocumented
647  
648 10 my @html;
649  
650 10 foreach my $field ($self->hidden_fields(@_))
651 {
652 46 push(@html, $field->html_field);
653 }
654  
655 10 ▶ return (wantarray) ? @html : join("\n", @html);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 10 10
656 }
657  
658 sub xhtml_hidden_fields
659 {
660 6 ▶ my($self) = shift;
Subroutine xhtml_hidden_fields: called CC=3 SCAR=11.1
Pod undocumented
661  
662 6 my @xhtml;
663  
664 6 foreach my $field ($self->hidden_fields(@_))
665 {
666 24 push(@xhtml, $field->xhtml_field);
667 }
668  
669 6 ▶ return (wantarray) ? @xhtml : join("\n", @xhtml);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 6 6
670 }
671  
672 12 1;
« blib/lib/Rose/HTML/Form/Repeatable.pm ↑ Summary blib/lib/Rose/HTML/Form/Field.pm »