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

filter: Statementstmt 82.1% 92 / 112 Branchbran 75.0% 24 / 32 Conditioncond 76.0% 19 / 25 MC/DCmcdc 46.1% 6 / 13 Subroutinesub 53.1% 17 / 32 Podpod 77.2% 17 / 22 totaltotal 74.1% 175 / 236 CC 28 SCAR 14.0
CC
28
Cov
80%
input_value
9.1
delete_child_at_index
6.5
child
6.0
CRAP 4.1
« blib/lib/Rose/HTML/Object/Repeatable.pm ↑ Summary blib/lib/Rose/HTML/Form/Field/PhoneNumber/US/Split.pm »
1 package Rose::HTML::Form::Field::Option::Container;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 11 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 ▶use base 'Rose::HTML::Form::Field::Group::OnOff';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 11 ▶use Rose::HTML::Form::Field::Group;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 require Rose::HTML::Form::Field::Option;
12 11 require Rose::HTML::Form::Field::OptionGroup;
13  
14 11 our $VERSION = '0.606';
15  
16 63 ▶sub _item_class { shift->object_type_class_loaded('option') }
Subroutine _item_class: called CC=1 SCAR=0.0
17 916 ▶sub _item_group_class { shift->object_type_class_loaded('option group') }
Subroutine _item_group_class: called CC=1 SCAR=0.0
18 0 ▶sub _item_name { 'option' }
Subroutine _item_name: not called CC=1 SCAR=6.9
19 0 ▶sub _item_name_plural { 'options' }
Subroutine _item_name_plural: not called CC=1 SCAR=6.9
20  
21 11 *options = \&Rose::HTML::Form::Field::Group::items;
22 11 *options_localized = \&Rose::HTML::Form::Field::Group::items_localized;
23 11 *option = \&Rose::HTML::Form::Field::Group::OnOff::item;
24 11 *option_group = \&Rose::HTML::Form::Field::Group::OnOff::item_group;
25 11 *visible_options = \&Rose::HTML::Form::Field::Group::visible_items;
26  
27 11 *add_options = \&Rose::HTML::Form::Field::Group::add_items;
28 11 *add_option = \&add_options;
29 11 *add_options_localized = \&Rose::HTML::Form::Field::Group::add_items_localized;
30 11 *add_option_localized = \&add_options_localized;
31  
32 11 *add_options_localized = \&Rose::HTML::Form::Field::Group::add_items_localized;
33 11 *add_option_localized = \&Rose::HTML::Form::Field::Group::add_item_localized;
34  
35 11 *choices = \&options;
36 11 *choices_localized = \&options_localized;
37  
38 11 *_args_to_items = \&Rose::HTML::Form::Field::Group::_args_to_items;
39  
40 11 *show_all_options = \&Rose::HTML::Form::Field::Group::show_all_items;
41 11 *hide_all_options = \&Rose::HTML::Form::Field::Group::hide_all_items;
42  
43 11 *delete_option = \&Rose::HTML::Form::Field::Group::delete_item;
44 11 *delete_options = \&Rose::HTML::Form::Field::Group::delete_items;
45  
46 11 *delete_option_group = \&Rose::HTML::Form::Field::Group::delete_item_group;
47 11 *delete_option_groups = \&Rose::HTML::Form::Field::Group::delete_item_groups;
48  
49 0 ▶sub html_element { 'select' }
Subroutine html_element: not called CC=1 SCAR=6.9
Pod documented
50 0 ▶sub xhtml_element { 'select' }
Subroutine xhtml_element: not called CC=1 SCAR=6.9
Pod documented
51  
52 #sub name { shift->html_attr('name', @_) }
53  
54 0 ▶sub is_flat_group { 0 }
Subroutine is_flat_group: not called CC=1 SCAR=6.9
Pod undocumented
55  
56 sub is_empty
57 503 ▶{
Subroutine is_empty: called CC=2 SCAR=6.9
Pod documented
58 11 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
59 503 ▶ return (grep { /\S/ } shift->internal_value) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
grep({/\S/;} (shift())->internal_value) ? : 16 487 503
60 }
61  
62 sub children
63 12 ▶{
Subroutine children: called CC=2 SCAR=7.1
Pod documented
64 12 my($self) = shift;
65 12 ▶ Carp::croak "Cannot set children() for an option container ($_[0]). Use options() instead." if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 12 12
66 12 return $self->options;
67 }
68  
69 0 ▶sub push_children { shift->add_items(@_) }
Subroutine push_children: not called CC=1 SCAR=6.9
Pod documented
70 0 ▶sub push_child { shift->add_item(@_) }
Subroutine push_child: not called CC=1 SCAR=6.9
Pod documented
71  
72 0 ▶sub pop_children { shift->pop_items(@_) }
Subroutine pop_children: not called CC=1 SCAR=6.9
Pod documented
73 0 ▶sub pop_child { shift->pop_item(@_) }
Subroutine pop_child: not called CC=1 SCAR=6.9
Pod documented
74  
75 0 ▶sub shift_children { shift->add_items(@_) }
Subroutine shift_children: not called CC=1 SCAR=6.9
Pod documented
76 0 ▶sub shift_child { shift->add_item(@_) }
Subroutine shift_child: not called CC=1 SCAR=6.9
Pod documented
77  
78 0 ▶sub unshift_children { shift->unshift_items(@_) }
Subroutine unshift_children: not called CC=1 SCAR=6.9
Pod documented
79 0 ▶sub unshift_child { shift->unshift_item(@_) }
Subroutine unshift_child: not called CC=1 SCAR=6.9
Pod documented
80  
81 sub child
82 0 ▶{
Subroutine child: not called CC=2 SCAR=17.9
Pod documented
83 0 my($self, $index) = @_;
84 0 ▶ my $items = $self->items || [];
Condition0%0/2
$self->items || []
l!l
00
MC/DC0%0/1
$self->items || []
$self->items
Truth table0%0/2
A
A= $self->items
Aresult
11
00
85 0 return $items->[$index];
86 }
87  
88 sub delete_child_at_index
89 0 ▶{
Subroutine delete_child_at_index: not called CC=3 SCAR=18.7
Pod undocumented
90 0 my($self) = shift;
91 0 ▶ Carp::croak "Missing array index" unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
92 0 ▶ my $items = $self->items || [];
Condition0%0/2
$self->items || []
l!l
00
MC/DC0%0/1
$self->items || []
$self->items
Truth table0%0/2
A
A= $self->items
Aresult
11
00
93 11 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
94 0 splice(@$items, $_[0], 1);
95 }
96  
97 sub html_field
98 105 ▶{
Subroutine html_field: called CC=4 SCAR=13.9
Pod documented
99 105 my($self) = shift;
100  
101 105 my $html;
102  
103 105 ▶ if($self->apply_error_class && defined $self->error)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->apply_error_class and defined $self->error) { } 2 103 105
Condition100%3/3
$self->apply_error_class and defined $self->error
!ll&&!rl&&r
33702
MC/DC100%2/2
$self->apply_error_class and defined $self->error
$self->apply_error_class defined $self->error
Truth table100%3/3
A and B
A= $self->apply_error_classB= defined $self->error
ABresult
0X0
100
111
104 {
105 2 my $class = $self->html_attr('class');
106 2 ▶ $self->html_attr(class => $class ? "$class error" : 'error');
Branch: 1 branch
BranchTrueFalseTotal
$class ? : 0 2 2
107 $html = $self->start_html . "\n" .
108 2 join("\n", map { $_->html_field } $self->visible_items) . "\n" .
109 $self->end_html;
110 2 $self->html_attr(class => $class);
111 2 return $html;
112 }
113 else
114 {
115 return $self->start_html . "\n" .
116 103 join("\n", map { $_->html_field } $self->visible_items) . "\n" .
117 $self->end_html;
118 }
119 }
120  
121 sub xhtml_field
122 43 ▶{
Subroutine xhtml_field: called CC=4 SCAR=13.9
Pod documented
123 43 my($self) = shift;
124  
125 43 my $xhtml;
126  
127 43 ▶ if($self->apply_error_class && defined $self->error)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->apply_error_class and defined $self->error) { } 2 41 43
Condition100%3/3
$self->apply_error_class and defined $self->error
!ll&&!rl&&r
16252
MC/DC100%2/2
$self->apply_error_class and defined $self->error
$self->apply_error_class defined $self->error
Truth table100%3/3
A and B
A= $self->apply_error_classB= defined $self->error
ABresult
0X0
100
111
128 {
129 2 my $class = $self->html_attr('class');
130 2 ▶ $self->html_attr(class => $class ? "$class error" : 'error');
Branch: 1 branch
BranchTrueFalseTotal
$class ? : 0 2 2
131 $xhtml = $self->start_xhtml . "\n" .
132 2 join("\n", map { $_->xhtml_field } $self->visible_items) . "\n" .
133 $self->end_xhtml;
134 2 $self->html_attr(class => $class);
135 2 return $xhtml;
136 }
137 else
138 {
139 return $self->start_xhtml . "\n" .
140 41 join("\n", map { $_->xhtml_field } $self->visible_items) . "\n" .
141 $self->end_xhtml;
142 }
143 }
144  
145 # sub html_field
146 # {
147 # my($self) = shift;
148 # $self->contents("\n" . join("\n", map { $_->html_field } $self->visible_options) . "\n");
149 # return $self->_html_tag(@_);
150 # }
151 #
152 # sub xhtml_field
153 # {
154 # my($self) = shift;
155 # $self->contents("\n" . join("\n", map { $_->xhtml_field } $self->visible_options) . "\n");
156 # return $self->_xhtml_tag(@_);
157 # }
158  
159 sub input_value
160 85 ▶{
Subroutine input_value: called CC=9 SCAR=22.1
Pod documented
161 85 my($self) = shift;
162  
163 85 ▶ if(@_ && (@_ > 1 || (ref $_[0] eq 'ARRAY' && @{$_[0]} > 1)) && !$self->multiple)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and @_ > 1 || ref $_[0] eq "ARRAY" && @{$_[0];} > 1 and not $self->multiple) 1 84 85
Condition91%11/12
@_ and @_ > 1 || ref $_[0] eq "ARRAY" && @{$_[0];} > 1 and not $self->multiple
!ll&&!rl&&r
71131
@_ and @_ > 1 || ref $_[0] eq "ARRAY" && @{$_[0];} > 1
!ll&&!rl&&r
96214
@_ > 1 or ref $_[0] eq "ARRAY" and @{$_[0];} > 1
l!l&&r!l&&!r
13162
ref $_[0] eq "ARRAY" and @{$_[0];} > 1
!ll&&!rl&&r
6201
MC/DC40%2/5
@_ and @_ > 1 || ref $_[0] eq "ARRAY" && @{$_[0];} > 1 and not $self->multiple
@_ @_ > 1 ref $_[0] eq "ARRAY" @{$_[0];} > 1 not $self->multiple
Truth table57%4/7
A and B or C and D and not(E)
A= @_B= @_ > 1C= ref $_[0] eq "ARRAY"D= @{$_[0];} > 1E= not $self->multiple
ABCDEresult
0XXXX0
100XX0
1010X0
11XX00
101100
11XX11
101111
164 {
165 1 Carp::croak "Attempt to select multiple values in a non-multiple " . ref($self);
166 }
167  
168 84 my $values = $self->SUPER::input_value(@_);
169  
170 84 ▶ Carp::croak "Non-multiple ", ref($self), " has multiple values: ", join(', ', @$values)
Branch: 1 branch
BranchTrueFalseTotal
if @$values > 1 and not $self->multiple 0 84 84
Condition66%2/3
@$values > 1 and not $self->multiple
!ll&&!rl&&r
65190
MC/DC0%0/2
@$values > 1 and not $self->multiple
@$values > 1 not $self->multiple
Truth table66%2/3
A and not(B)
A= @$values > 1B= not $self->multiple
ABresult
0X0
100
111
171 if(@$values > 1 && !$self->multiple);
172  
173 84 ▶ return wantarray ? @$values : $values;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 81 84
174 }
175  
176 sub hidden_fields
177 28 ▶{
Subroutine hidden_fields: called CC=5 SCAR=16.3
Pod documented
178 28 my($self) = shift;
179  
180 28 my @hidden;
181  
182 28 foreach my $item ($self->items)
183 {
184 156 ▶ if(defined $item->internal_value)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $item->internal_value) 42 114 156
185 {
186 # Derek Watson suggests this conditional modifier, but
187 # I've yet to see the error is works around...
188 42 ▶ $hidden[-1]->name($self->name)
Branch: 1 branch
BranchTrueFalseTotal
if push @hidden, $item->hidden_field 42 0 42
189 if(push(@hidden, $item->hidden_field));
190 }
191 }
192  
193 28 ▶ return (wantarray) ? @hidden : \@hidden;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 28 0 28
194 }
195  
196 sub hidden
197 40 ▶{
Subroutine hidden: called CC=5 SCAR=16.1
Pod undocumented
198 40 my($self) = shift;
199  
200 40 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 6 34 40
201 {
202 6 ▶ if($self->{'_hidden'} = shift(@_) ? 1 : 0)
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{"_hidden"} = shift @_ ? 1 : 0) 3 3 6
shift @_ ? : 3 3 6
203 {
204 3 foreach my $option ($self->options)
205 {
206 6 $option->selected(undef);
207 }
208 }
209 }
210  
211 40 return $self->{'_hidden'};
212 }
213  
214 1 ▶sub hide { shift->hidden(1) }
Subroutine hide: called CC=1 SCAR=0.0
Pod undocumented
215 1 ▶sub show { shift->hidden(0) }
Subroutine show: called CC=1 SCAR=0.0
Pod undocumented
216  
217 11 1;
218  
« blib/lib/Rose/HTML/Object/Repeatable.pm ↑ Summary blib/lib/Rose/HTML/Form/Field/PhoneNumber/US/Split.pm »