FormHandler/Widget/Field/CheckboxGroup.pm

filter: Statementstmt 98.6% 73 / 74 Branchbran 75.0% 15 / 20 Conditioncond 58.6% 17 / 29 MC/DCmcdc 18.7% 3 / 16 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 77.1% 115 / 149 CC 24 SCAR 23.8
CC
24
Cov
85%
render_option
16.5
render_element
8.1
render
3.1
CRAP 10.8
« FormHandler/Model/Object.pm ↑ Summary FormHandler/Field/Select.pm »
1 package HTML::FormHandler::Widget::Field::CheckboxGroup;
2 # ABSTRACT: checkbox group field role
3 8 $HTML::FormHandler::Widget::Field::CheckboxGroup::VERSION = '0.410002';
4 8 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use HTML::FormHandler::Render::Util ('process_attrs');
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use HTML::Entities qw( encode_entities );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 11 ▶sub render {
Subroutine render: called CC=3 SCAR=11.2
Pod undocumented
11 11 my ( $self, $result ) = @_;
12 11 ▶ $result ||= $self->result;
Condition66%2/3
$result ||= $self->result
l!l&&r!l&&!r
290
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 11 ▶ die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 11 11
14 11 my $output = $self->render_element( $result );
15 11 return $self->wrap_field( $result, $output );
16 }
17  
18 11 ▶sub render_element {
Subroutine render_element: called CC=8 SCAR=20.9
Pod undocumented
19 11 my ( $self, $result ) = @_;
20 11 ▶ $result ||= $self->result;
Condition33%1/3
$result ||= $self->result
l!l&&r!l&&!r
1100
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 11 my $output = '';
25 11 foreach my $option ( @{ $self->{options} } ) {
26 31 ▶ if ( my $label = $option->{group} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $label = $option->{'group'}) { } 6 25 31
27 6 ▶ $label = $self->_localize( $label ) if $self->localize_labels;
Branch: 1 branch
BranchTrueFalseTotal
if $self->localize_labels 0 6 6
28 6 ▶ my $attr = $option->{attributes} || {};
Condition100%2/2
$option->{'attributes'} || {}
l!l
15
MC/DC100%1/1
$option->{'attributes'} || {}
$option->{'attributes'}
Truth table100%2/2
A
A= $option->{'attributes'}
Aresult
11
00
29 6 my $attr_str = process_attrs($attr);
30 6 ▶ my $lattr = $option->{label_attributes} || {};
Condition100%2/2
$option->{'label_attributes'} || {}
l!l
15
MC/DC100%1/1
$option->{'label_attributes'} || {}
$option->{'label_attributes'}
Truth table100%2/2
A
A= $option->{'label_attributes'}
Aresult
11
00
31 6 my $lattr_str= process_attrs($lattr);
32 6 $output .= qq{\n<div$attr_str><label$lattr_str>} . encode_entities($label, '<>&') . qq{</label>};
33 6 foreach my $group_opt ( @{ $option->{options} } ) {
34 17 $output .= $self->render_option( $group_opt, $result );
35 }
36 6 $output .= qq{\n</div>};
37 }
38 else {
39 25 $output .= $self->render_option( $option, $result );
40 }
41 }
42 11 $self->reset_options_index;
43 11 return $output;
44 }
45  
46 42 ▶sub render_option {
Subroutine render_option: called CC=15 SCAR=28.0
Pod undocumented
47 42 my ( $self, $option, $result ) = @_;
48 42 ▶ $result ||= $self->result;
Condition33%1/3
$result ||= $self->result
l!l&&r!l&&!r
4200
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 42 my $fif = $result->fif;
52 42 my %fif_lookup;
53 42 ▶ @fif_lookup{@$fif} = () if $self->multiple;
Branch: 1 branch
BranchTrueFalseTotal
if $self->multiple 42 0 42
54  
55 # create option label attributes
56 42 ▶ my $lattr = $option->{label_attributes} || {};
Condition50%1/2
$option->{'label_attributes'} || {}
l!l
042
MC/DC0%0/1
$option->{'label_attributes'} || {}
$option->{'label_attributes'}
Truth table50%1/2
A
A= $option->{'label_attributes'}
Aresult
11
00
57 42 push @{ $lattr->{class} }, 'checkbox';
58 42 ▶ if ( $self->get_tag('inline') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_tag("inline")) 9 33 42
59 9 my $class = 'inline';
60 9 ▶ $class = 'checkbox-inline' if $self->has_flag('is_b3');
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_flag("is_b3") 3 6 9
61 9 push @{ $lattr->{class} }, $class;
62 }
63 42 my $lattr_str = process_attrs( $lattr );
64 42 my $id = $self->id . '.' . $self->options_index;
65 42 my $output = qq{\n<label$lattr_str for="$id">};
66 42 my $value = $option->{value};
67 42 $output .= qq{\n<input type="checkbox"};
68 42 $output .= qq{ value="} . $self->html_filter($value) . '"';
69 42 $output .= qq{ name="} . $self->html_name . '"';
70 42 $output .= qq{ id="$id"};
71  
72 # handle option attributes
73 42 ▶ my $attr = $option->{attributes} || {};
Condition50%1/2
$option->{'attributes'} || {}
l!l
042
MC/DC0%0/1
$option->{'attributes'} || {}
$option->{'attributes'}
Truth table50%1/2
A
A= $option->{'attributes'}
Aresult
11
00
74 42 ▶ if( defined $option->{disabled} && $option->{disabled} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $option->{"disabled"} and $option->{"disabled"}) 0 42 42
Condition33%1/3
defined $option->{"disabled"} and $option->{"disabled"}
!ll&&!rl&&r
4200
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
75 0 $attr->{disabled} = 'disabled';
76 }
77 42 ▶ if ( defined $fif &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fif and $self->multiple && exists $fif_lookup{$value} || $fif eq $value) 4 38 42
Condition66%6/9
defined $fif and $self->multiple && exists $fif_lookup{$value} || $fif eq $value
!ll&&!rl&&r
0384
$self->multiple and exists $fif_lookup{$value} or $fif eq $value
l!l&&r!l&&!r
4038
$self->multiple and exists $fif_lookup{$value}
!ll&&!rl&&r
0384
MC/DC25%1/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 table33%2/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
78 ( ( $self->multiple && exists $fif_lookup{$value} ) ||
79 ( $fif eq $value ) ) ) {
80 4 $attr->{checked} = 'checked';
81 }
82 42 $output .= process_attrs($attr);
83 42 $output .= " />\n";
84  
85 # handle label
86 42 my $label = $option->{label};
87 42 ▶ $label = $self->_localize($label) if $self->localize_labels;
Branch: 1 branch
BranchTrueFalseTotal
if $self->localize_labels 0 42 42
88 42 $output .= encode_entities($label, '<>&');
89 42 $output .= "\n</label>";
90 42 $self->inc_options_index;
91  
92 42 ▶ if ($self->get_tag('checkbox_element_wrapper')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_tag("checkbox_element_wrapper")) 3 39 42
93 3 $output = qq{<div class="checkbox">$output</div>};
94 }
95 42 return $output;
96 }
97  
98 8 1;
99  
100 __END__
« FormHandler/Model/Object.pm ↑ Summary FormHandler/Field/Select.pm »