FormHandler/Widget/Field/Select.pm

filter: Statementstmt 98.6% 71 / 72 Branchbran 77.2% 17 / 22 Conditioncond 57.6% 15 / 26 MC/DCmcdc 20.0% 3 / 15 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 5 totaltotal 77.1% 115 / 149 CC 23 SCAR 20.5
CC
23
Cov
86%
render_option
13.4
render_element
7.1
render_select_start
4.0
CRAP 7.8
« FormHandler/Widget/Theme/BootstrapFormMessages.pm ↑ Summary FormHandler/Field/Date.pm »
1 package HTML::FormHandler::Widget::Field::Select;
2 # ABSTRACT: select field rendering widget
3 33 $HTML::FormHandler::Widget::Field::Select::VERSION = '0.410002';
4  
5 33 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 33 ▶use HTML::Entities qw( encode_entities );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 33 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 33 ▶use HTML::FormHandler::Render::Util ('process_attrs');
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 40 ▶sub render {
Subroutine render: called CC=3 SCAR=11.2
Pod undocumented
11 40 my ( $self, $result ) = @_;
12 40 ▶ $result ||= $self->result;
Condition66%2/3
$result ||= $self->result
l!l&&r!l&&!r
24160
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table66%2/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
13 40 ▶ die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 40 40
14 40 my $output = $self->render_element( $result );
15 40 return $self->wrap_field( $result, $output );
16 }
17  
18 41 ▶sub render_element {
Subroutine render_element: called CC=7 SCAR=19.6
Pod undocumented
19 41 my ( $self, $result ) = @_;
20 41 ▶ $result ||= $self->result;
Condition33%1/3
$result ||= $self->result
l!l&&r!l&&!r
4100
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
21  
22 # create select element
23 41 my $output = $self->render_select_start( $result );
24  
25 # create empty select
26 41 ▶ if( defined $self->empty_select ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->empty_select) 3 38 41
27 3 $output .= $self->render_empty_select;
28 }
29  
30 # loop through options
31 41 foreach my $option ( @{ $self->{options} } ) {
32 133 ▶ if ( my $label = $option->{group} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $label = $option->{'group'}) { } 4 129 133
33 4 ▶ $label = $self->_localize( $label ) if $self->localize_labels;
Branch: 1 branch
BranchTrueFalseTotal
if $self->localize_labels 0 4 4
34 4 $output .= qq{\n<optgroup label="} . encode_entities($label, '"&') . qq{">};
35 4 foreach my $group_opt ( @{ $option->{options} } ) {
36 11 $output .= $self->render_option( $group_opt, $result );
37 }
38 4 $output .= qq{\n</optgroup>};
39 }
40 else {
41 129 $output .= $self->render_option( $option, $result );
42 }
43 }
44 41 $self->reset_options_index;
45  
46 41 $output .= '</select>';
47 41 return $output;
48 }
49  
50 41 ▶sub render_select_start {
Subroutine render_select_start: called CC=4 SCAR=13.9
Pod undocumented
51 41 my ( $self, $result ) = @_;
52 41 ▶ $result ||= $self->result;
Condition33%1/3
$result ||= $self->result
l!l&&r!l&&!r
4100
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
53  
54 41 my $id = $self->id;
55 41 my $output = '<select name="' . $self->html_name . qq{" id="$id"};
56 41 ▶ $output .= ' multiple="multiple"' if $self->multiple;
Branch: 1 branch
BranchTrueFalseTotal
if $self->multiple 17 24 41
57 41 ▶ $output .= ' size="' . $self->size . '"' if defined $self->size;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->size 10 31 41
58 41 $output .= process_attrs($self->element_attributes($result));
59 41 $output .= '>';
60 41 return $output;
61 }
62  
63 3 ▶sub render_empty_select {
Subroutine render_empty_select: called CC=1 SCAR=0.0
Pod undocumented
64 3 my $self = shift;
65  
66 3 my $label = $self->_localize($self->empty_select);
67 3 my $id = $self->id . "." . $self->options_index;
68 3 my $output = qq{\n<option value="" id="$id">$label</option>};
69 3 $self->inc_options_index;
70 3 return $output;
71 }
72  
73 140 ▶sub render_option {
Subroutine render_option: called CC=12 SCAR=25.9
Pod undocumented
74 140 my ( $self, $option, $result ) = @_;
75 140 ▶ $result ||= $self->result;
Condition33%1/3
$result ||= $self->result
l!l&&r!l&&!r
14000
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
76  
77 # current values
78 140 my $fif = $result->fif;
79 140 my %fif_lookup;
80 140 ▶ @fif_lookup{@$fif} = () if $self->multiple;
Branch: 1 branch
BranchTrueFalseTotal
if $self->multiple 65 75 140
81  
82 # not sure why the value of an option would be undef, but just in case,
83 # set to empty string because of 'eq' below
84 140 ▶ my $value = defined $option->{value} ? $option->{value} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $option->{'value'} ? : 140 0 140
85 140 my $id = $self->id . '.' . $self->options_index;
86 140 my $output = qq{\n<option value="} . $self->html_filter($value) . '"';
87 140 $output .= qq{ id="$id"};
88  
89 # handle option attributes
90 140 ▶ my $attrs = $option->{attributes} || {};
Condition50%1/2
$option->{'attributes'} || {}
l!l
0140
MC/DC0%0/1
$option->{'attributes'} || {}
$option->{'attributes'}
Truth table50%1/2
A
A= $option->{'attributes'}
Aresult
11
00
91 140 ▶ if( defined $option->{disabled} && $option->{disabled} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $option->{"disabled"} and $option->{"disabled"}) 0 140 140
Condition33%1/3
defined $option->{"disabled"} and $option->{"disabled"}
!ll&&!rl&&r
14000
MC/DC0%0/2
defined $option->{"disabled"} and $option->{"disabled"}
defined $option->{"disabled"} $option->{"disabled"}
Truth table33%1/3
A and B
A= defined $option->{"disabled"}B= $option->{"disabled"}
ABresult
0X0
100
111
92 0 $attrs->{disabled} = 'disabled';
93 }
94 140 ▶ if ( defined $fif &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fif and $self->multiple && exists $fif_lookup{$value} || $fif eq $value) 31 109 140
Condition88%8/9
defined $fif and $self->multiple && exists $fif_lookup{$value} || $fif eq $value
!ll&&!rl&&r
010931
$self->multiple and exists $fif_lookup{$value} or $fif eq $value
l!l&&r!l&&!r
2110109
$self->multiple and exists $fif_lookup{$value}
!ll&&!rl&&r
754421
MC/DC75%3/4
defined $fif and $self->multiple && exists $fif_lookup{$value} || $fif eq $value
defined $fif $self->multiple exists $fif_lookup{$value} $fif eq $value
Truth table66%4/6
A and B and C or D
A= defined $fifB= $self->multipleC= exists $fif_lookup{$value}D= $fif eq $value
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
95 ( ( $self->multiple && exists $fif_lookup{$value} ) ||
96 ( $fif eq $value ) ) ) {
97 31 $attrs->{selected} = 'selected';
98 }
99 140 $output .= process_attrs($attrs);
100  
101 # handle label
102 140 my $label = $option->{label};
103 140 ▶ $label = $self->_localize($label) if $self->localize_labels;
Branch: 1 branch
BranchTrueFalseTotal
if $self->localize_labels 0 140 140
104 140 $output .= '>' . encode_entities($label, '<>&') . '</option>';
105 140 $self->inc_options_index;
106 140 return $output;
107 }
108  
109 33 1;
110  
111 __END__
« FormHandler/Widget/Theme/BootstrapFormMessages.pm ↑ Summary FormHandler/Field/Date.pm »