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

filter: Statementstmt 92.2% 154 / 167 Branchbran 86.0% 74 / 86 Conditioncond 75.0% 15 / 20 MC/DCmcdc 53.8% 7 / 13 Subroutinesub 96.1% 25 / 26 Podpod 25.0% 5 / 20 totaltotal 84.3% 280 / 332 CC 68 SCAR 19.9
CC
68
Cov
89%
input_value
16.3
init_items
12.0
defaults
7.9
CRAP 7.3
« blib/lib/Rose/HTML/Object/Message/Localized.pm ↑ Summary blib/lib/Rose/HTML/Form/Field/Numeric.pm »
1 package Rose::HTML::Form::Field::Group::OnOff;
2  
3 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 13 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 13 ▶use Rose::HTML::Util();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 13 ▶use base 'Rose::HTML::Form::Field::Group';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 13 our $VERSION = '0.606';
12  
13 13 our $Debug = undef;
14  
15 sub resync_name
16 597 ▶{
Subroutine resync_name: called CC=2 SCAR=6.9
Pod undocumented
17 597 my($self) = shift;
18  
19 597 $self->SUPER::resync_name();
20  
21 # Resync item names too
22 597 my $name = $self->local_name;
23  
24 597 foreach my $item ($self->items)
25 {
26 954 $item->name($name);
27 }
28 }
29  
30 sub name
31 3210 ▶{
Subroutine name: called CC=4 SCAR=13.9
Pod documented
32 3210 my($self) = shift;
33  
34 3210 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 50 3160 3210
35 {
36 50 $self->local_name(shift);
37  
38 50 my $name = $self->local_name;
39  
40 # All items in the group must have the same name
41 50 foreach my $item ($self->items)
42 {
43 0 $item->name($name);
44 }
45 }
46  
47 3210 my $name = $self->html_attr('name');
48  
49 # The name HTML attr will be an empty string if it's a required attr,
50 # so use length() and not defined()
51 13 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
52 3210 ▶ unless(length $name)
Branch: 1 branch
BranchTrueFalseTotal
unless (length $name) 680 2530 3210
53 {
54 680 return $self->html_attr('name', $self->fq_name);
55 }
56  
57 2530 return $name;
58 }
59  
60 sub defaults
61 73 ▶{
Subroutine defaults: called CC=6 SCAR=20.7
Pod undocumented
62 73 my($self) = shift;
63  
64 73 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 73 0 73
65 {
66 73 ▶ if(@_ == 1 && ref $_[0] eq 'ARRAY')
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY') { } 0 73 73
elsif (defined $_[0]) { } 70 3 73
Condition33%1/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
0730
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
67 {
68 0 $self->{'defaults'} = { map { $_ => 1 } @{$_[0]} };
69 }
70 elsif(defined $_[0])
71 {
72 70 $self->{'defaults'} = { map { $_ => 1 } @_ };
73 }
74 else
75 {
76 3 $self->{'defaults'} = { };
77 }
78  
79 73 $self->init_items;
80 }
81  
82 0 ▶ return (wantarray) ? sort keys %{$self->{'defaults'}} : [ sort keys %{$self->{'defaults'}} ];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 73 73
83 }
84  
85 13 *default = \&defaults;
86 13 *default_value = \&defaults;
87 13 *default_values = \&defaults;
88  
89 0 ▶sub default_values_hash { (wantarray) ? %{$_[0]->{'defaults'}} : $_[0]->{'defaults'} }
Subroutine default_values_hash: called CC=2 SCAR=9.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 179 179
90  
91 sub _args_to_items
92 37 ▶{
Subroutine _args_to_items: called CC=3 SCAR=11.0
93 37 my($self) = shift;
94  
95 37 my $items = $self->SUPER::_args_to_items(@_);
96  
97 # All items in the group must have the same name
98 37 foreach my $item (@$items)
99 {
100 87 $item->name($self->local_name);
101 #$item->name($self->name);
102 }
103  
104 37 ▶ return (wantarray) ? @$items : $items;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 32 37
105 }
106  
107 sub item
108 70 ▶{
Subroutine item: called CC=6 SCAR=17.9
Pod undocumented
109 70 my($self, $value) = @_;
110  
111 70 my $group_class = $self->_item_group_class;
112  
113 # Dumb linear search for now
114 70 foreach my $item ($self->items)
115 {
116 168 ▶ if($item->isa($group_class))
Branch: 1 branch
BranchTrueFalseTotal
if ($item->isa($group_class)) { } 6 162 168
117 {
118 6 foreach my $subitem ($item->items)
119 {
120 12 ▶ return $subitem if($subitem->html_attr('value') eq $value);
Branch: 1 branch
BranchTrueFalseTotal
if $subitem->html_attr("value") eq $value 4 8 12
121 }
122 }
123 else
124 {
125 162 ▶ return $item if($item->html_attr('value') eq $value);
Branch: 1 branch
BranchTrueFalseTotal
if $item->html_attr("value") eq $value 62 100 162
126 }
127 }
128  
129 4 return undef;
130 }
131  
132 sub item_group
133 3 ▶{
Subroutine item_group: called CC=4 SCAR=14.2
Pod undocumented
134 3 my($self, $label) = @_;
135  
136 3 my $group_class = $self->_item_group_class;
137  
138 # Dumb linear search for now
139 3 foreach my $item ($self->items)
140 {
141 12 ▶ return $item if($item->isa($group_class) && $item->label eq $label);
Branch: 1 branch
BranchTrueFalseTotal
if $item->isa($group_class) and $item->label eq $label 3 9 12
Condition66%2/3
$item->isa($group_class) and $item->label eq $label
!ll&&!rl&&r
903
MC/DC50%1/2
$item->isa($group_class) and $item->label eq $label
$item->isa($group_class) $item->label eq $label
Truth table66%2/3
A and B
A= $item->isa($group_class)B= $item->label eq $label
ABresult
0X0
100
111
142 }
143  
144 0 return undef;
145 }
146  
147 sub is_selected
148 19 ▶{
Subroutine is_selected: called CC=4 SCAR=13.9
Pod undocumented
149 19 my($self, $value) = @_;
150  
151 # Dumb linear search for now
152 19 foreach my $item ($self->items)
153 {
154 52 ▶ if($item->html_attr('value') eq $value && $item->internal_value)
Branch: 1 branch
BranchTrueFalseTotal
if ($item->html_attr("value") eq $value and $item->internal_value) 8 44 52
Condition100%3/3
$item->html_attr("value") eq $value and $item->internal_value
!ll&&!rl&&r
3868
MC/DC100%2/2
$item->html_attr("value") eq $value and $item->internal_value
$item->html_attr("value") eq $value $item->internal_value
Truth table100%3/3
A and B
A= $item->html_attr("value") eq $valueB= $item->internal_value
ABresult
0X0
100
111
155 {
156 8 return 1;
157 }
158 }
159  
160 11 return 0;
161 }
162  
163 13 *is_checked = \&is_selected;
164  
165 sub is_empty
166 6 ▶{
Subroutine is_empty: called CC=3 SCAR=11.0
Pod documented
167 6 my($self) = shift;
168  
169 6 foreach my $item ($self->items)
170 {
171 13 ▶ return 0 if($item->is_on);
Branch: 1 branch
BranchTrueFalseTotal
if $item->is_on 5 8 13
172 }
173  
174 1 return 1;
175 }
176  
177 sub add_values
178 13 ▶{
Subroutine add_values: called CC=1 SCAR=0.0
Pod undocumented
179 13 my($self) = shift;
180  
181 13 $self->input_value($self->internal_value, @_);
182 }
183  
184 8 ▶sub add_value { shift->add_values(@_) }
Subroutine add_value: called CC=1 SCAR=0.0
Pod undocumented
185  
186 sub input_value
187 132 ▶{
Subroutine input_value: called CC=16 SCAR=27.9
Pod documented
188 132 my($self) = shift;
189  
190 132 my %values;
191  
192 132 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 119 13 132
193 {
194 119 $self->clear();
195 119 $self->is_cleared(0);
196  
197 119 ▶ if(@_ == 1 && ref $_[0] eq 'ARRAY')
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY') { } 0 119 119
elsif (@_ and defined $_[0]) { } 94 25 119
Condition66%2/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
191000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
198 {
199 0 %values = map { $_ => 1 } @{$_[0]};
200 }
201 ▶ elsif(@_ && defined $_[0])
Condition66%2/3
@_ and defined $_[0]
!ll&&!rl&&r
02594
MC/DC50%1/2
@_ and defined $_[0]
@_ defined $_[0]
Truth table66%2/3
A and B
A= @_B= defined $_[0]
ABresult
0X0
100
111
202 {
203 94 %values = map { $_ => 1 } @_;
204 }
205  
206 119 ▶ unless(%values)
Branch: 1 branch
BranchTrueFalseTotal
if (%values) { } 94 25 119
207 {
208 25 $self->clear();
209 25 $self->is_cleared(0);
210 }
211 else
212 {
213 94 $self->{'values'} = \%values;
214 94 $self->init_items;
215 }
216  
217 119 ▶ if(my $parent = $self->parent_field)
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent = $self->parent_field) 25 94 119
218 {
219 25 ▶ if($parent->_is_full)
Branch: 1 branch
BranchTrueFalseTotal
if ($parent->_is_full) 14 11 25
220 {
221 14 $parent->is_cleared(0);
222 }
223  
224 25 ▶ if($self->auto_invalidate_parent)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->auto_invalidate_parent) 8 17 25
225 {
226 8 $parent->invalidate_value;
227 }
228 }
229 }
230 else
231 {
232 13 ▶ if(keys %{$self->{'values'}})
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$self{"values"};}) 12 1 13
233 {
234 12 my $group_class = $self->_item_group_class;
235  
236 12 foreach my $item ($self->items)
237 {
238 56 ▶ if($item->isa($group_class))
Branch: 1 branch
BranchTrueFalseTotal
if ($item->isa($group_class)) { } 4 52 56
239 {
240 4 foreach my $value ($item->internal_value)
241 {
242 4 $values{$value} = 1;
243 }
244 }
245 else
246 {
247 52 ▶ if($item->is_on)
Branch: 1 branch
BranchTrueFalseTotal
if ($item->is_on) 16 36 52
248 {
249 16 $values{$item->html_attr('value')} = 1;
250 }
251 }
252 }
253 }
254 }
255  
256 132 ▶ return (wantarray) ? sort keys %values : [ sort keys %values ];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 129 132
257 }
258  
259 sub value_labels
260 2 ▶{
Subroutine value_labels: called CC=4 SCAR=14.2
Pod undocumented
261 2 my($self) = shift;
262  
263 2 my @labels;
264  
265 2 foreach my $value ($self->internal_value)
266 {
267 2 ▶ next unless(defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 2 2
268 2 push(@labels, $self->item($value)->label);
269 }
270  
271 2 ▶ return wantarray ? @labels : \@labels;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2 2
272 }
273  
274 sub value_label
275 5 ▶{
Subroutine value_label: called CC=6 SCAR=18.7
Pod undocumented
276 5 my($self) = shift;
277  
278 5 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 2 3 5
279 {
280 2 return $self->value_labels->[0];
281 }
282  
283 3 my $value = shift;
284  
285 # Dumb linear search for now
286 3 foreach my $item ($self->items)
287 {
288 3 ▶ if($item->html_attr('value') eq $value)
Branch: 1 branch
BranchTrueFalseTotal
if ($item->html_attr("value") eq $value) 3 0 3
289 {
290 3 ▶ return $item-label(@_) if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 3 3
291 3 ▶ return ($item->label) ? $item->label : $value;
Branch: 1 branch
BranchTrueFalseTotal
$item->label ? : 3 0 3
292 }
293 }
294  
295 0 return undef;
296 }
297  
298 #sub value_label { shift->value_labels->[0] }
299  
300 5 ▶sub value { shift->input_value(@_) }
Subroutine value: called CC=1 SCAR=0.0
Pod documented
301 8 ▶sub values { shift->input_value(@_) }
Subroutine values: called CC=1 SCAR=0.0
Pod undocumented
302  
303 0 ▶sub is_on { Carp::croak "Override in subclass!" }
Subroutine is_on: not called CC=1 SCAR=6.9
Pod undocumented
304  
305 sub internal_value
306 758 ▶{
Subroutine internal_value: called CC=6 SCAR=17.9
Pod documented
307 758 my($self) = shift;
308  
309 758 my @values;
310  
311 758 my $group_class = $self->_item_group_class;
312  
313 758 foreach my $item ($self->items)
314 {
315 2374 ▶ if($item->isa($group_class))
Branch: 1 branch
BranchTrueFalseTotal
if ($item->isa($group_class)) { } 6 2368 2374
316 {
317 6 ▶ push(@values, $item->internal_value) if(defined $item->internal_value);
Branch: 1 branch
BranchTrueFalseTotal
if defined $item->internal_value 6 0 6
318 }
319 else
320 {
321 2368 ▶ push(@values, $item->value) if($item->is_on);
Branch: 1 branch
BranchTrueFalseTotal
if $item->is_on 325 2043 2368
322 }
323 }
324  
325 758 @values = sort @values; # Makes tests easier to write... :-/
326  
327 758 ▶ return wantarray ? @values : \@values;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 727 31 758
328 }
329  
330 13 *output_value = \&internal_value;
331  
332 0 ▶sub input_values_hash { (wantarray) ? %{$_[0]->{'values'}} : $_[0]->{'values'} }
Subroutine input_values_hash: called CC=2 SCAR=9.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 679 679
333  
334 sub has_value
335 19 ▶{
Subroutine has_value: called CC=3 SCAR=11.0
Pod undocumented
336 19 my($self, $find_value) = @_;
337  
338 19 foreach my $value ($self->output_value)
339 {
340 28 ▶ return 1 if($value eq $find_value);
Branch: 1 branch
BranchTrueFalseTotal
if $value eq $find_value 8 20 28
341 }
342  
343 11 return 0;
344 }
345  
346 sub init_items
347 679 ▶{
Subroutine init_items: called CC=12 SCAR=24.8
Pod undocumented
348 679 my($self) = shift;
349  
350 679 ▶ my $values = $self->input_values_hash || {};
Condition100%2/2
$self->input_values_hash || {}
l!l
259420
MC/DC100%1/1
$self->input_values_hash || {}
$self->input_values_hash
Truth table100%2/2
A
A= $self->input_values_hash
Aresult
11
00
351  
352 679 ▶ if(%$values)
Branch: 2 branches
BranchTrueFalseTotal
if (%$values) { } 107 572 679
elsif (not $self->is_cleared) { } 179 393 572
353 {
354 107 my $group_class = $self->_item_group_class;
355  
356 107 foreach my $item ($self->items)
357 {
358 401 local $item->{'auto_invalidate_parent'} = $self->auto_invalidate_parent;
359  
360 401 ▶ if($item->isa($group_class))
Branch: 1 branch
BranchTrueFalseTotal
if ($item->isa($group_class)) { } 4 397 401
361 {
362 4 foreach my $subitem ($item->items)
363 {
364 8 ▶ if(exists $values->{$subitem->html_attr('value')})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$values{$subitem->html_attr('value')}) { } 3 5 8
365 {
366 3 $subitem->input_value(1);
367 }
368 else
369 {
370 5 $subitem->input_value(0);
371 }
372 }
373 }
374 else
375 {
376 397 ▶ if(exists $values->{$item->html_attr('value')})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$values{$item->html_attr('value')}) { } 126 271 397
377 {
378 126 $item->input_value(1);
379 }
380 else
381 {
382 271 $item->input_value(0);
383 }
384 }
385 }
386 }
387 elsif(!$self->is_cleared)
388 {
389 179 my $defaults = $self->default_values_hash;
390  
391 179 foreach my $item ($self->items)
392 {
393 502 my $value = $item->html_attr('value');
394  
395 502 ▶ if(defined $value && exists $defaults->{$value})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and exists $defaults->{$value}) { } 81 421 502
Condition100%3/3
defined $value and exists $defaults->{$value}
!ll&&!rl&&r
441781
MC/DC100%2/2
defined $value and exists $defaults->{$value}
defined $value exists $defaults->{$value}
Truth table100%3/3
A and B
A= defined $valueB= exists $defaults->{$value}
ABresult
0X0
100
111
396 {
397 81 $item->default_value(1);
398 }
399 else
400 {
401 421 $item->default_value(0);
402 }
403 }
404 }
405 }
406  
407 13 1;
« blib/lib/Rose/HTML/Object/Message/Localized.pm ↑ Summary blib/lib/Rose/HTML/Form/Field/Numeric.pm »