FormHandler/Widget/Field/HorizCheckboxGroup.pm

filter: Statementstmt 97.0% 65 / 67 Branchbran 57.1% 8 / 14 Conditioncond 37.9% 11 / 29 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 66.9% 91 / 136 CC 21 SCAR 23.4
CC
21
Cov
76%
render_option
16.8
render_element
8.3
render
3.2
CRAP 10.4
« FormHandler/Field/Select.pm ↑ Summary FormHandler/Widget/Form/Simple.pm »
1 package HTML::FormHandler::Widget::Field::HorizCheckboxGroup;
2 # ABSTRACT: checkbox group field role
3 2 $HTML::FormHandler::Widget::Field::HorizCheckboxGroup::VERSION = '0.410002';
4 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use HTML::FormHandler::Render::Util ('process_attrs');
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use HTML::Entities qw( encode_entities );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 2 ▶sub render {
Subroutine render: called CC=3 SCAR=11.8
Pod undocumented
11 2 my ( $self, $result ) = @_;
12 2 ▶ $result ||= $self->result;
Condition33%1/3
$result ||= $self->result
l!l&&r!l&&!r
020
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
13 2 ▶ die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 2 2
14 2 my $output = $self->render_element( $result );
15 2 return $self->wrap_field( $result, $output );
16 }
17  
18 2 ▶sub render_element {
Subroutine render_element: called CC=8 SCAR=21.2
Pod undocumented
19 2 my ( $self, $result ) = @_;
20 2 ▶ $result ||= $self->result;
Condition33%1/3
$result ||= $self->result
l!l&&r!l&&!r
200
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  
23 # loop through options
24 2 my $output = '';
25 2 foreach my $option ( @{ $self->{options} } ) {
26 5 ▶ if ( my $label = $option->{group} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $label = $option->{'group'}) { } 1 4 5
27 1 ▶ $label = $self->_localize( $label ) if $self->localize_labels;
Branch: 1 branch
BranchTrueFalseTotal
if $self->localize_labels 0 1 1
28 1 ▶ my $attr = $option->{attributes} || {};
Condition50%1/2
$option->{'attributes'} || {}
l!l
01
MC/DC0%0/1
$option->{'attributes'} || {}
$option->{'attributes'}
Truth table50%1/2
A
A= $option->{'attributes'}
Aresult
11
00
29 1 my $attr_str = process_attrs($attr);
30 1 ▶ my $lattr = $option->{label_attributes} || {};
Condition50%1/2
$option->{'label_attributes'} || {}
l!l
01
MC/DC0%0/1
$option->{'label_attributes'} || {}
$option->{'label_attributes'}
Truth table50%1/2
A
A= $option->{'label_attributes'}
Aresult
11
00
31 1 my $lattr_str= process_attrs($lattr);
32 1 $output .= qq{\n<div$attr_str><label$lattr_str>} . encode_entities($label, '<>&') . qq{</label>};
33 1 foreach my $group_opt ( @{ $option->{options} } ) {
34 2 $output .= $self->render_option( $group_opt, $result );
35 }
36 1 $output .= qq{\n</div>};
37 }
38 else {
39 4 $output .= $self->render_option( $option, $result );
40 }
41 }
42 2 $self->reset_options_index;
43 2 return $output;
44 }
45  
46 6 ▶sub render_option {
Subroutine render_option: called CC=12 SCAR=28.2
Pod undocumented
47 6 my ( $self, $option, $result ) = @_;
48 6 ▶ $result ||= $self->result;
Condition33%1/3
$result ||= $self->result
l!l&&r!l&&!r
600
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
49  
50 # get existing values
51 6 my $fif = $result->fif;
52 6 my %fif_lookup;
53 6 ▶ @fif_lookup{@$fif} = () if $self->multiple;
Branch: 1 branch
BranchTrueFalseTotal
if $self->multiple 6 0 6
54  
55 # create option label attributes
56 6 ▶ my $lattr = $option->{label_attributes} || {};
Condition50%1/2
$option->{'label_attributes'} || {}
l!l
06
MC/DC0%0/1
$option->{'label_attributes'} || {}
$option->{'label_attributes'}
Truth table50%1/2
A
A= $option->{'label_attributes'}
Aresult
11
00
57 6 my $lattr_str = process_attrs( $lattr );
58  
59 6 my $id = $self->id . '.' . $self->options_index;
60  
61 # start wrapping div
62 6 my $output = qq{<div class="checkbox">};
63  
64 6 $output .= qq{\n<label$lattr_str for="$id">};
65 6 my $value = $option->{value};
66 6 $output .= qq{\n<input type="checkbox"};
67 6 $output .= qq{ value="} . $self->html_filter($value) . '"';
68 6 $output .= qq{ name="} . $self->html_name . '"';
69 6 $output .= qq{ id="$id"};
70  
71 # handle option attributes
72 6 ▶ my $attr = $option->{attributes} || {};
Condition50%1/2
$option->{'attributes'} || {}
l!l
06
MC/DC0%0/1
$option->{'attributes'} || {}
$option->{'attributes'}
Truth table50%1/2
A
A= $option->{'attributes'}
Aresult
11
00
73 6 ▶ if( defined $option->{disabled} && $option->{disabled} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $option->{"disabled"} and $option->{"disabled"}) 0 6 6
Condition33%1/3
defined $option->{"disabled"} and $option->{"disabled"}
!ll&&!rl&&r
600
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
74 0 $attr->{disabled} = 'disabled';
75 }
76 6 ▶ if ( defined $fif &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fif and $self->multiple && exists $fif_lookup{$value} || $fif eq $value) 0 6 6
Condition33%3/9
defined $fif and $self->multiple && exists $fif_lookup{$value} || $fif eq $value
!ll&&!rl&&r
060
$self->multiple and exists $fif_lookup{$value} or $fif eq $value
l!l&&r!l&&!r
006
$self->multiple and exists $fif_lookup{$value}
!ll&&!rl&&r
060
MC/DC0%0/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 table16%1/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
77 ( ( $self->multiple && exists $fif_lookup{$value} ) ||
78 ( $fif eq $value ) ) ) {
79 0 $attr->{checked} = 'checked';
80 }
81 6 $output .= process_attrs($attr);
82 6 $output .= " />\n";
83  
84 # handle label
85 6 my $label = $option->{label};
86 6 ▶ $label = $self->_localize($label) if $self->localize_labels;
Branch: 1 branch
BranchTrueFalseTotal
if $self->localize_labels 0 6 6
87 6 $output .= encode_entities($label, '<>&');
88 6 $output .= "\n</label>";
89  
90 # close wrapping div
91 6 $output .= "\n</div>";
92  
93 6 $self->inc_options_index;
94 6 return $output;
95 }
96  
97 2 1;
98  
99 __END__
« FormHandler/Field/Select.pm ↑ Summary FormHandler/Widget/Form/Simple.pm »