FormHandler/Field/Select.pm

filter: Statementstmt 92.9% 170 / 183 Branchbran 79.7% 75 / 94 Conditioncond 72.3% 47 / 65 MC/DCmcdc 55.5% 20 / 36 Subroutinesub 92.0% 23 / 25 Podpod 15.3% 2 / 13 totaltotal 81.0% 337 / 416 CC 77 SCAR 23.7
CC
77
Cov
85%
select_widget
42.0
_inner_validate_field
15.0
_load_options
13.4
CRAP 10.7
« FormHandler/Widget/Field/CheckboxGroup.pm ↑ Summary FormHandler/Widget/Field/HorizCheckboxGroup.pm »
1 package HTML::FormHandler::Field::Select;
2 # ABSTRACT: select fields
3 43 $HTML::FormHandler::Field::Select::VERSION = '0.410002';
4 43 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 43 extends 'HTML::FormHandler::Field';
6 43 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 43 has 'options' => (
10 isa => 'HFH::SelectOptions',
11 is => 'rw',
12 coerce => 1,
13 traits => ['Array'],
14 auto_deref => 1,
15 handles => {
16 all_options => 'elements',
17 reset_options => 'clear',
18 clear_options => 'clear',
19 has_options => 'count',
20 num_options => 'count',
21 },
22 lazy => 1,
23 builder => 'build_options'
24 );
25 2 ▶sub options_ref { [shift->options] }
Subroutine options_ref: called CC=1 SCAR=0.0
Pod undocumented
26 # this is used for rendering
27 43 has 'options_index' => ( traits => ['Counter'], isa => 'Num',
28 is => 'rw', default => 0,
29 handles => { inc_options_index => 'inc', dec_options_index => 'dec',
30 reset_options_index => 'reset' },
31 );
32 61 ▶sub clear_data {
Subroutine clear_data: called CC=1 SCAR=0.0
Pod undocumented
33 61 my $self = shift;
34 61 $self->next::method();
35 61 $self->reset_options_index;
36 }
37  
38 63 ▶sub build_options { [] }
Subroutine build_options: called CC=1 SCAR=0.0
Pod undocumented
39 43 has 'options_from' => ( isa => 'Str', is => 'rw', default => 'none' );
40 43 has 'do_not_reload' => ( isa => 'Bool', is => 'ro' );
41 43 has 'no_option_validation' => ( isa => 'Bool', is => 'rw' );
42 43 has 'option_wrapper' => ( is => 'rw' );
43  
44 107 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.0
Pod undocumented
45 107 my $self = shift;
46  
47 107 $self->build_options_method;
48 107 ▶ if( $self->options && $self->has_options ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->options and $self->has_options) 44 63 107
Condition66%2/3
$self->options and $self->has_options
!ll&&!rl&&r
06344
MC/DC50%1/2
$self->options and $self->has_options
$self->options $self->has_options
Truth table66%2/3
A and B
A= $self->optionsB= $self->has_options
ABresult
0X0
100
111
49 44 $self->options_from('build');
50 44 $self->default_from_options([$self->options]);
51 }
52 107 $self->input_without_param; # vivify
53 }
54  
55 43 has 'options_method' => (
56 traits => ['Code'],
57 is => 'ro',
58 isa => 'CodeRef',
59 writer => '_set_options_method',
60 predicate => 'has_options_method',
61 handles => { 'get_options' => 'execute_method' },
62 );
63  
64 107 ▶sub build_options_method {
Subroutine build_options_method: called CC=6 SCAR=18.0
Pod undocumented
65 107 my $self = shift;
66  
67 107 my $set_options = $self->set_options;
68 107 ▶ $set_options ||= "options_" . HTML::FormHandler::Field::convert_full_name($self->full_name);
Condition50%1/2
$set_options ||= 'options_' . HTML::FormHandler::Field::convert_full_name($self->full_name)
l!l
0107
MC/DC0%0/1
$set_options ||= 'options_' . HTML::FormHandler::Field::convert_full_name($self->full_name)
$set_options
Truth table50%1/2
A
A= $set_options
Aresult
11
00
69 107 ▶ if ( $self->form && $self->form->can($set_options) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form and $self->form->can($set_options)) 55 52 107
Condition100%3/3
$self->form and $self->form->can($set_options)
!ll&&!rl&&r
124055
MC/DC100%2/2
$self->form and $self->form->can($set_options)
$self->form $self->form->can($set_options)
Truth table100%3/3
A and B
A= $self->formB= $self->form->can($set_options)
ABresult
0X0
100
111
70 55 my $attr = $self->form->meta->find_method_by_name( $set_options );
71 55 ▶ if ( $attr and $attr->isa('Moose::Meta::Method::Accessor') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr and $attr->isa('Moose::Meta::Method::Accessor')) { } 2 53 55
Condition66%2/3
$attr and $attr->isa("Moose::Meta::Method::Accessor")
!ll&&!rl&&r
0532
MC/DC50%1/2
$attr and $attr->isa("Moose::Meta::Method::Accessor")
$attr $attr->isa("Moose::Meta::Method::Accessor")
Truth table66%2/3
A and B
A= $attrB= $attr->isa("Moose::Meta::Method::Accessor")
ABresult
0X0
100
111
72 2 ▶ $self->_set_options_method( sub { my $self = shift; $self->form->$set_options; } );
Subroutine __ANON__: called CC=1 SCAR=0.0
73 }
74 else {
75 53 ▶ $self->_set_options_method( sub { my $self = shift; $self->form->$set_options($self); } );
Subroutine __ANON__: called CC=1 SCAR=0.0
76 }
77 }
78 }
79  
80 43 has 'sort_options_method' => (
81 traits => ['Code'],
82 is => 'rw',
83 isa => 'CodeRef',
84 predicate => 'has_sort_options_method',
85 handles => {
86 sort_options => 'execute_method',
87 },
88 );
89  
90 43 has 'set_options' => ( isa => 'Str', is => 'ro');
91  
92 43 has 'multiple' => ( isa => 'Bool', is => 'rw', default => '0' );
93 # following is for unusual case where a multiple select is a has_many type relation
94 43 has 'has_many' => ( isa => 'Str', is => 'rw' );
95 43 has 'size' => ( isa => 'Int|Undef', is => 'rw' );
96 43 has 'label_column' => ( isa => 'Str', is => 'rw', default => 'name' );
97 43 has 'localize_labels' => ( isa => 'Bool', is => 'rw' );
98 43 has 'active_column' => ( isa => 'Str', is => 'rw', default => 'active' );
99 43 has 'auto_widget_size' => ( isa => 'Int', is => 'rw', default => '0' );
100 43 has 'sort_column' => ( isa => 'Str|ArrayRef[Str]', is => 'rw' );
101 43 has '+widget' => ( default => 'Select' );
102 0 ▶sub html_element { 'select' }
Subroutine html_element: not called CC=1 SCAR=6.9
Pod undocumented
103 43 has '+type_attr' => ( default => 'select' );
104 43 has 'empty_select' => ( isa => 'Str', is => 'rw' );
105 107 ▶has '+deflate_method' => ( default => sub { \&select_deflate } );
Subroutine __ANON__: called CC=1 SCAR=0.0
106 43 has '+input_without_param' => ( lazy => 1, builder => 'build_input_without_param' );
107 107 ▶sub build_input_without_param {
Subroutine build_input_without_param: called CC=2 SCAR=6.9
Pod undocumented
108 107 my $self = shift;
109 107 ▶ if( $self->multiple ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->multiple) { } 39 68 107
110 39 $self->not_nullable(1);
111 39 return [];
112 }
113 else {
114 68 return '';
115 }
116 }
117 43 has 'value_when_empty' => ( is => 'ro', lazy => 1, builder => 'build_value_when_empty' );
118 28 ▶sub build_value_when_empty {
Subroutine build_value_when_empty: called CC=2 SCAR=8.1
Pod undocumented
119 28 my $self = shift;
120 28 ▶ return [] if $self->multiple;
Branch: 1 branch
BranchTrueFalseTotal
if $self->multiple 28 0 28
121 0 return undef;
122 }
123  
124 43 our $class_messages = {
125 'select_not_multiple' => 'This field does not take multiple values',
126 'select_invalid_value' => '\'[_1]\' is not a valid value',
127 };
128  
129 28 ▶sub get_class_messages {
Subroutine get_class_messages: called CC=1 SCAR=0.0
Pod undocumented
130 28 my $self = shift;
131 return {
132 28 %{ $self->next::method },
133 %$class_messages,
134 }
135 }
136  
137 0 ▶sub select_widget {
Subroutine select_widget: not called CC=6 SCAR=37.4
Pod documented
138 0 my $field = shift;
139  
140 0 my $size = $field->auto_widget_size;
141 0 ▶ return $field->widget unless $field->widget eq 'Select' && $size;
Branch: 1 branch
BranchTrueFalseTotal
unless $field->widget eq "Select" and $size 0 0 0
Condition0%0/3
$field->widget eq "Select" and $size
!ll&&!rl&&r
000
MC/DC0%0/2
$field->widget eq "Select" and $size
$field->widget eq "Select" $size
Truth table0%0/3
A and B
A= $field->widget eq "Select"B= $size
ABresult
0X0
100
111
142 0 ▶ my $options = $field->options || [];
Condition0%0/2
$field->options || []
l!l
00
MC/DC0%0/1
$field->options || []
$field->options
Truth table0%0/2
A
A= $field->options
Aresult
11
00
143 0 ▶ return 'Select' if @$options > $size;
Branch: 1 branch
BranchTrueFalseTotal
if @$options > $size 0 0 0
144 0 ▶ return $field->multiple ? 'checkbox_group' : 'radio_group';
Branch: 1 branch
BranchTrueFalseTotal
$field->multiple ? : 0 0 0
145 }
146  
147 4 ▶sub as_label {
Subroutine as_label: called CC=11 SCAR=25.4
Pod documented
148 4 my ( $self, $value ) = @_;
149  
150 4 ▶ $value = $self->value unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 3 1 4
151 4 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 4 4
152 4 ▶ if ( $self->multiple ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->multiple) { } 4 0 4
153 4 ▶ unless ( ref($value) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $value eq "ARRAY") 1 3 4
154 1 ▶ if( $self->has_inflate_default_method ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_inflate_default_method) { } 1 0 1
155 1 my @values = $self->inflate_default($value);
156 1 $value = \@values;
157 }
158 else {
159 # not sure under what circumstances this would happen, but
160 # just in case
161 0 return $value;
162 }
163 }
164 4 my @labels;
165 my %value_hash;
166 4 @value_hash{@$value} = ();
167 4 for ( $self->options ) {
168 12 ▶ if ( exists $value_hash{$_->{value}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $value_hash{$_->{"value"}}) 8 4 12
169 8 push @labels, $_->{label};
170 8 delete $value_hash{$_->{value}};
171 8 ▶ last unless keys %value_hash;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %value_hash 4 4 8
172 }
173 }
174 4 my $str = join(', ', @labels);
175 4 return $str;
176 }
177 else {
178 0 for ( $self->options ) {
179 0 ▶ return $_->{label} if $_->{value} eq $value;
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"value"} eq $value 0 0 0
180 }
181 }
182 0 return;
183 }
184  
185 115 ▶sub _inner_validate_field {
Subroutine _inner_validate_field: called CC=15 SCAR=27.1
186 115 my ($self) = @_;
187  
188 115 my $value = $self->value;
189 115 ▶ return unless defined $value; # nothing to check
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 115 115
190  
191 115 ▶ if ( ref $value eq 'ARRAY' &&
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'ARRAY' and not $self->can('multiple') && $self->multiple) { } 2 113 115
elsif (ref $value ne 'ARRAY' and $self->multiple) { } 1 131 132
Condition83%5/6
ref $value eq "ARRAY" and not $self->can("multiple") && $self->multiple
!ll&&!rl&&r
94192
$self->can('multiple') && $self->multiple
!ll&&!rl&&r
0219
MC/DC66%2/3
ref $value eq "ARRAY" and not $self->can("multiple") && $self->multiple
ref $value eq "ARRAY" $self->can('multiple') $self->multiple
Truth table75%3/4
A and not(B && C)
A= ref $value eq "ARRAY"B= $self->can('multiple')C= $self->multiple
ABCresult
0XX0
1110
10X1
1101
192 !( $self->can('multiple') && $self->multiple ) )
193 {
194 2 $self->add_error( $self->get_message('select_not_multiple') );
195 2 return;
196 }
197 ▶ elsif ( ref $value ne 'ARRAY' && $self->multiple ) {
Condition100%3/3
ref $value ne "ARRAY" and $self->multiple
!ll&&!rl&&r
19931
MC/DC100%2/2
ref $value ne "ARRAY" and $self->multiple
ref $value ne "ARRAY" $self->multiple
Truth table100%3/3
A and B
A= ref $value ne "ARRAY"B= $self->multiple
ABresult
0X0
100
111
198 1 $value = [$value];
199 1 $self->_set_value($value);
200 }
201  
202 113 ▶ return if $self->no_option_validation;
Branch: 1 branch
BranchTrueFalseTotal
if $self->no_option_validation 1 112 113
203  
204 # create a lookup hash
205 112 my %options;
206 112 foreach my $opt ( @{ $self->options } ) {
207 1433 ▶ if ( exists $opt->{group} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opt->{'group'}) { } 12 1421 1433
208 12 foreach my $group_opt ( @{ $opt->{options} } ) {
209 36 $options{$group_opt->{value}} = 1;
210 }
211 }
212 else {
213 1421 $options{$opt->{value}} = 1;
214 }
215 }
216 112 ▶ if( $self->has_many ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_many) 2 110 112
217 2 $value = [map { $_->{$self->has_many} } @$value];
218 }
219 112 ▶ for my $value ( ref $value eq 'ARRAY' ? @$value : ($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 19 93 112
220 125 ▶ unless ( $options{$value} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{$value}) 26 99 125
221 26 $self->add_error($self->get_message('select_invalid_value'), $value);
222 26 return;
223 }
224 }
225 86 return 1;
226 }
227  
228 20 ▶sub _result_from_object {
Subroutine _result_from_object: called CC=3 SCAR=11.8
229 20 my ( $self, $result, $item ) = @_;
230  
231 20 $result = $self->next::method( $result, $item );
232 20 $self->_load_options;
233 20 ▶ $result->_set_value($self->default)
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->default and not $result->has_value 0 20 20
Condition33%1/3
defined $self->default and not $result->has_value
!ll&&!rl&&r
2000
MC/DC0%0/2
defined $self->default and not $result->has_value
defined $self->default not $result->has_value
Truth table33%1/3
A and not(B)
A= defined $self->defaultB= not $result->has_value
ABresult
0X0
100
111
234 if( defined $self->default && not $result->has_value );
235 20 return $result;
236 }
237  
238 135 ▶sub _result_from_fields {
Subroutine _result_from_fields: called CC=3 SCAR=11.0
239 135 my ( $self, $result ) = @_;
240  
241 135 $result = $self->next::method($result);
242 135 $self->_load_options;
243 135 ▶ $result->_set_value($self->default)
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->default and not $result->has_value 1 134 135
Condition100%3/3
defined $self->default and not $result->has_value
!ll&&!rl&&r
121131
MC/DC100%2/2
defined $self->default and not $result->has_value
defined $self->default not $result->has_value
Truth table100%3/3
A and not(B)
A= defined $self->defaultB= not $result->has_value
ABresult
0X0
100
111
244 if( defined $self->default && not $result->has_value );
245 135 return $result;
246 }
247  
248 81 ▶sub _result_from_input {
Subroutine _result_from_input: called CC=5 SCAR=16.1
249 81 my ( $self, $result, $input, $exists ) = @_;
250  
251 81 ▶ $input = ref $input eq 'ARRAY' ? $input : [$input]
Branch: 2 branches
BranchTrueFalseTotal
if $self->multiple 26 55 81
ref $input eq 'ARRAY' ? : 11 15 26
252 if $self->multiple;
253 81 $result = $self->next::method( $result, $input, $exists );
254 81 $self->_load_options;
255 81 ▶ $result->_set_value($self->default)
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->default and not $result->has_value 1 80 81
Condition100%3/3
defined $self->default and not $result->has_value
!ll&&!rl&&r
7731
MC/DC100%2/2
defined $self->default and not $result->has_value
defined $self->default not $result->has_value
Truth table100%3/3
A and not(B)
A= defined $self->defaultB= not $result->has_value
ABresult
0X0
100
111
256 if( defined $self->default && not $result->has_value );
257 81 return $result;
258 }
259  
260 236 ▶sub _load_options {
Subroutine _load_options: called CC=13 SCAR=26.0
261 236 my $self = shift;
262  
263 return
264 236 ▶ if ( $self->options_from eq 'build' ||
Branch: 1 branch
BranchTrueFalseTotal
if $self->options_from eq "build" or $self->has_options and $self->do_not_reload 68 168 236
Condition66%4/6
$self->options_from eq "build" or $self->has_options and $self->do_not_reload
l!l&&r!l&&!r
680168
$self->has_options and $self->do_not_reload
!ll&&!rl&&r
92760
MC/DC33%1/3
$self->options_from eq "build" or $self->has_options and $self->do_not_reload
$self->options_from eq "build" $self->has_options $self->do_not_reload
Truth table75%3/4
A or B and C
A= $self->options_from eq "build"B= $self->has_optionsC= $self->do_not_reload
ABCresult
1XX1
0111
00X0
0100
265 ( $self->has_options && $self->do_not_reload ) );
266 168 my @options;
267 168 ▶ if( $self->has_options_method ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->has_options_method) { } 158 10 168
elsif ($self->form) { } 10 0 10
268 158 @options = $self->get_options;
269 158 $self->options_from('method');
270 }
271 elsif ( $self->form ) {
272 10 my $full_accessor;
273 10 ▶ $full_accessor = $self->parent->full_accessor if $self->parent;
Branch: 1 branch
BranchTrueFalseTotal
if $self->parent 10 0 10
274 10 @options = $self->form->lookup_options( $self, $full_accessor );
275 10 ▶ $self->options_from('model') if scalar @options;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @options 0 10 10
276 }
277 168 ▶ return unless @options; # so if there isn't an options method and no options
Branch: 1 branch
BranchTrueFalseTotal
unless @options 10 158 168
278 # from a table, already set options attributes stays put
279  
280 # possibilities:
281 # @options = ( 1 => 'one', 2 => 'two' );
282 # @options = ([ 1 => 'one', 2 => 'tw' ]);
283 # @options = ([ { value => 1, label => 'one'}, { value => 2, label => 'two'}]);
284 # @options = ([[ 'one', 'two' ]]);
285 158 ▶ my $opts = ref $options[0] eq 'ARRAY' ? $options[0] : \@options;
Branch: 1 branch
BranchTrueFalseTotal
ref $options[0] eq 'ARRAY' ? : 49 109 158
286 158 ▶ if ( ref $opts->[0] eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts->[0] eq "HASH") 26 132 158
287 # do the array of hashrefs separately so we can get the defaults
288 26 $self->default_from_options($opts);
289 }
290 158 $opts = $self->options($opts); # coerce will reformat
291 158 ▶ if ($opts) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts) 158 0 158
292 # sort options if sort method exists
293 158 ▶ $opts = $self->sort_options($opts) if $self->has_sort_options_method;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_sort_options_method 48 110 158
294 158 $self->options($opts);
295 }
296 }
297  
298 # This is because setting 'checked => 1' or 'selected => 1' in an options
299 # hashref is the equivalent of setting a default on the field. Originally
300 # that was handled only in rendering, but it moved knowledge about where
301 # the 'fif' value came from into the renderer, which was bad. So instead
302 # we're setting the defaults from the options.
303 # It's probably better to use 'defaults' to start with, but since there are
304 # people using this method, this at least normalizes it.
305 70 ▶sub default_from_options {
Subroutine default_from_options: called CC=4 SCAR=14.2
Pod undocumented
306 70 my ( $self, $options ) = @_;
307  
308 70 ▶ my @defaults = map { $_->{value} } grep { $_->{checked} || $_->{selected} } @$options;
Condition66%2/3
$_->{'checked'} || $_->{'selected'}
l!l&&r!l&&!r
02416
MC/DC50%1/2
$_->{'checked'} || $_->{'selected'}
$_->{'checked'} $_->{'selected'}
Truth table66%2/3
A || B
A= $_->{'checked'}B= $_->{'selected'}
ABresult
1X1
011
000
309 70 ▶ if( scalar @defaults ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @defaults) 2 68 70
310 2 ▶ if( $self->multiple ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->multiple) { } 0 2 2
311 0 $self->default(\@defaults);
312 }
313 else {
314 2 $self->default($defaults[0]);
315 }
316 }
317 }
318  
319 820 ▶before 'value' => sub {
Subroutine __ANON__: called CC=11 SCAR=24.0
320 820 my $self = shift;
321  
322 820 ▶ return undef unless $self->has_result;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_result 1 819 820
323 819 my $value = $self->result->value;
324 819 ▶ if( $self->multiple ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->multiple) 258 561 819
325 258 ▶ if ( !defined $value || $value eq '' || ( ref $value eq 'ARRAY' && scalar @$value == 0 ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $value or $value eq '' or ref $value eq 'ARRAY' and scalar @$value == 0) { } 112 146 258
elsif ($self->has_many and scalar @$value and ref $value->[0] ne 'HASH') { } 4 272 276
Condition88%8/9
not defined $value or $value eq "" or ref $value eq "ARRAY" and scalar @$value == 0
l!l&&r!l&&!r
4666146
not defined $value or $value eq ""
l!l&&r!l&&!r
460212
ref $value eq "ARRAY" and scalar @$value == 0
!ll&&!rl&&r
414266
MC/DC75%3/4
not defined $value or $value eq "" or ref $value eq "ARRAY" and scalar @$value == 0
not defined $value $value eq "" ref $value eq "ARRAY" scalar @$value == 0
Truth table80%4/5
not(A) or B or C and D
A= not defined $valueB= $value eq ""C= ref $value eq "ARRAY"D= scalar @$value == 0
ABCDresult
1XXX1
01XX1
00111
000X0
00100
326 112 $self->_set_value( $self->value_when_empty );
327 }
328 ▶ elsif ( $self->has_many && scalar @$value && ref($value->[0]) ne 'HASH' ) {
Condition100%5/5
$self->has_many and scalar @$value and ref $value->[0] ne "HASH"
!ll&&!rl&&r
130124
$self->has_many and scalar @$value
!ll
13016
MC/DC100%2/2
$self->has_many and scalar @$value and ref $value->[0] ne "HASH"
$self->has_many ref $value->[0] ne "HASH"
Truth table100%3/3
A and B
A= $self->has_manyB= ref $value->[0] ne "HASH"
ABresult
0X0
100
111
329 4 my @new_values;
330 4 foreach my $ele (@$value) {
331 5 push @new_values, { $self->has_many => $ele };
332 }
333 4 $self->_set_value( \@new_values );
334 }
335 }
336 43 };
337  
338 137 ▶sub select_deflate {
Subroutine select_deflate: called CC=6 SCAR=18.2
Pod undocumented
339 137 my ( $self, $value ) = @_;
340  
341 137 ▶ return $value unless ( $self->has_many && $self->multiple );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_many and $self->multiple 132 5 137
Condition66%2/3
$self->has_many and $self->multiple
!ll&&!rl&&r
13205
MC/DC50%1/2
$self->has_many and $self->multiple
$self->has_many $self->multiple
Truth table66%2/3
A and B
A= $self->has_manyB= $self->multiple
ABresult
0X0
100
111
342  
343 # the following is for the edge case of a has_many select
344 5 ▶ return $value unless ref($value) eq 'ARRAY' && scalar @$value && ref($value->[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "ARRAY" and scalar @$value and ref $value->[0] eq "HASH" 2 3 5
Condition60%3/5
ref $value eq "ARRAY" and scalar @$value and ref $value->[0] eq "HASH"
!ll&&!rl&&r
203
ref $value eq "ARRAY" and scalar @$value
!ll
05
MC/DC0%0/2
ref $value eq "ARRAY" and scalar @$value and ref $value->[0] eq "HASH"
ref $value eq "ARRAY" ref $value->[0] eq "HASH"
Truth table33%1/3
A and B
A= ref $value eq "ARRAY"B= ref $value->[0] eq "HASH"
ABresult
0X0
100
111
345 3 return [map { $_->{$self->has_many} } @$value];
346 }
347  
348 43 __PACKAGE__->meta->make_immutable;
349 43 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
350 43 1;
351  
352 __END__
« FormHandler/Widget/Field/CheckboxGroup.pm ↑ Summary FormHandler/Widget/Field/HorizCheckboxGroup.pm »