lib/HTML/FormFu/Element/Select.pm

filter: Statementstmt 100% 54 / 54 Branchbran 100% 18 / 18 Conditioncond 87.5% 21 / 24 MC/DCmcdc 72.7% 8 / 11 Subroutinesub 100% 10 / 10 Podpod n/a totaltotal 94.8% 111 / 117 CC 20 SCAR 22.3
CC
20
Cov
97%
_prepare_attrs
15.1
_string_field
6.0
BEGIN
1.0
CRAP 9.3
« lib/HTML/FormFu/Role/CustomRoles.pm ↑ Summary lib/HTML/FormFu.pm »
1 55 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Element::Select;
4 55 $HTML::FormFu::Element::Select::VERSION = '2.09';
5 # ABSTRACT: Select form field
6  
7 55 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 55 extends 'HTML::FormFu::Element';
9  
10 55 with 'HTML::FormFu::Role::Element::Group';
11  
12 55 ▶use HTML::FormFu::Constants qw( $EMPTY_STR );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 55 ▶use HTML::FormFu::Util qw( append_xml_attribute process_attrs );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 55 ▶use List::Util 1.33 qw( any );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 55 __PACKAGE__->mk_attr_accessors(qw( multiple size ));
17  
18 245 ▶after BUILD => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
19 245 my $self = shift;
20  
21 245 $self->layout_field_filename('field_layout_select_field');
22 245 $self->multi_value(1);
23  
24 245 return;
25 55 };
26  
27 8182 ▶sub _prepare_attrs {
Subroutine _prepare_attrs: called CC=15 SCAR=27.1
28 8182 my ( $self, $submitted, $value, $default, $option ) = @_;
29  
30 8182 ▶ if ( $submitted
Branch: 5 branches
BranchTrueFalseTotal
if ($submitted and defined $value and ref $value eq 'ARRAY' ? &any(sub { $_ eq $option->{'value'}; } , @$value) : $value eq $option->{'value'}) { } 151 8031 8182
elsif ($submitted and $self->retain_default and !defined($value) || $value eq $HTML::FormFu::Element::Select::EMPTY_STR and defined $self->value and $self->value eq $option->{'value'}) { } 4 8027 8031
elsif ($submitted) { } 3548 4479 8027
elsif (defined $default and ref $default eq 'ARRAY' ? &any(sub { $_ eq $option->{'value'}; } , @$default) : $default eq $option->{'value'}) { } 191 5083 5274
ref $value eq 'ARRAY' ? : 3 3050 3053
Condition100%6/6
$submitted and defined $value and ref $value eq "ARRAY" ? &any(sub { $_ eq $option->{"value"}; } , @$value) : $value eq $option->{"value"}
!ll&&!rl&&r
51292902151
$submitted and defined $value
!ll&&!rl&&r
44796503053
MC/DC100%3/3
$submitted and defined $value and ref $value eq "ARRAY" ? &any(sub { $_ eq $option->{"value"}; } , @$value) : $value eq $option->{"value"}
$submitted defined $value ref $value eq "ARRAY" ? &any(sub { $_ eq $option->{"value"}; } , @$value) : $value eq $option->{"value"}
Truth table100%4/4
A and B and C
A= $submittedB= defined $valueC= ref $value eq "ARRAY" ? &any(sub { $_ eq $option->{"value"}; } , @$value) : $value eq $option->{"value"}
ABCresult
0XX0
10X0
1100
1111
31 && defined $value
32 && (ref $value eq 'ARRAY'
33 5 ▶ ? any { $_ eq $option->{value} } @$value
Subroutine __ANON__: called CC=1 SCAR=0.0
34 : $value eq $option->{value} ) )
35 {
36 151 $option->{attributes}{selected} = 'selected';
37 }
38 ▶ elsif ($submitted
Condition80%12/15
$submitted and $self->retain_default and !defined($value) || $value eq $HTML::FormFu::Element::Select::EMPTY_STR and defined $self->value and $self->value eq $option->{"value"}
!ll&&!rl&&r
801984
$submitted and $self->retain_default and !defined($value) || $value eq $HTML::FormFu::Element::Select::EMPTY_STR and defined $self->value
!ll&&!rl&&r
8019012
$submitted and $self->retain_default and !defined($value) || $value eq $HTML::FormFu::Element::Select::EMPTY_STR
!ll&&!rl&&r
8019012
$submitted and $self->retain_default
!ll&&!rl&&r
4479354012
not defined $value or $value eq $HTML::FormFu::Element::Select::EMPTY_STR
l!l&&r!l&&!r
660
MC/DC50%3/6
$submitted and $self->retain_default and !defined($value) || $value eq $HTML::FormFu::Element::Select::EMPTY_STR and defined $self->value and $self->value eq $option->{"value"}
$submitted $self->retain_default not defined $value $value eq $HTML::FormFu::Element::Select::EMPTY_STR defined $self->value $self->value eq $option->{"value"}
Truth table66%6/9
A and B and not(C) or D and E and F
A= $submittedB= $self->retain_defaultC= not defined $valueD= $value eq $HTML::FormFu::Element::Select::EMPTY_STRE= defined $self->valueF= $self->value eq $option->{"value"}
ABCDEFresult
0XXXXX0
10XXXX0
1100XX0
111X0X0
11010X0
111X100
1101100
111X111
1101111
39 && $self->retain_default
40 && ( !defined $value || $value eq $EMPTY_STR )
41 && defined( $self->value )
42 && $self->value eq $option->{value} )
43 {
44 4 $option->{attributes}{selected} = 'selected';
45 }
46 elsif ($submitted) {
47 3548 delete $option->{attributes}{selected};
48 }
49 ▶ elsif (
Branch: 1 branch
BranchTrueFalseTotal
ref $default eq 'ARRAY' ? : 29 3655 3684
Condition100%3/3
defined $default and ref $default eq "ARRAY" ? &any(sub { $_ eq $option->{"value"}; } , @$default) : $default eq $option->{"value"}
!ll&&!rl&&r
7953493191
MC/DC100%2/2
defined $default and ref $default eq "ARRAY" ? &any(sub { $_ eq $option->{"value"}; } , @$default) : $default eq $option->{"value"}
defined $default ref $default eq "ARRAY" ? &any(sub { $_ eq $option->{"value"}; } , @$default) : $default eq $option->{"value"}
Truth table100%3/3
A and B
A= defined $defaultB= ref $default eq "ARRAY" ? &any(sub { $_ eq $option->{"value"}; } , @$default) : $default eq $option->{"value"}
ABresult
0X0
100
111
50 defined $default
51 && (ref $default eq 'ARRAY'
52 46 ▶ ? any { $_ eq $option->{value} } @$default
Subroutine __ANON__: called CC=1 SCAR=0.0
53 : $default eq $option->{value} ) )
54 {
55 191 $option->{attributes}{selected} = 'selected';
56 }
57 8182 return;
58 }
59  
60 239 ▶sub _string_field {
Subroutine _string_field: called CC=6 SCAR=17.9
61 239 my ( $self, $render ) = @_;
62  
63 # select_tag template
64  
65 239 my $html = "<select";
66  
67 239 ▶ if ( defined $render->{nested_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $render->{"nested_name"}) 235 4 239
68 235 $html .= sprintf qq{ name="%s"}, $render->{nested_name};
69 }
70  
71 239 $html .= sprintf "%s>\n", process_attrs( $render->{attributes} );
72  
73 239 for my $option ( @{ $render->{options} } ) {
74 4012 ▶ if ( exists $option->{group} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option->{'group'}) { } 14 3998 4012
75 14 $html .= "<optgroup";
76  
77 14 ▶ if ( defined $option->{label} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $option->{"label"}) 8 6 14
78 8 $html .= sprintf qq{ label="%s"}, $option->{label};
79 }
80  
81 14 $html .= sprintf "%s>\n", process_attrs( $option->{attributes} );
82  
83 14 for my $item ( @{ $option->{group} } ) {
84 $html .= sprintf qq{<option value="%s"%s>%s</option>\n},
85 $item->{value},
86 process_attrs( $item->{attributes} ),
87 $item->{label},
88 28 ;
89 }
90  
91 14 $html .= "</optgroup>\n";
92 }
93 else {
94 $html .= sprintf qq{<option value="%s"%s>%s</option>\n},
95 $option->{value},
96 process_attrs( $option->{attributes} ),
97 $option->{label},
98 3998 ;
99 }
100 }
101  
102 239 $html .= "</select>";
103  
104 239 return $html;
105 }
106  
107 55 __PACKAGE__->meta->make_immutable;
108  
109 55 1;
110  
111 __END__
« lib/HTML/FormFu/Role/CustomRoles.pm ↑ Summary lib/HTML/FormFu.pm »