FormHandler/Widget/Field/HorizCheckboxGroup.pm

filter: Statementstmt 81.2% 52 / 64 Branchbran 42.8% 6 / 14 Conditioncond 31.0% 9 / 29 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 3 totaltotal 55.3% 73 / 132 CC 21 SCAR 27.5
CC
21
Cov
63%
render_element
24.3
render_option
16.8
render
3.2
CRAP 15.7
« FormHandler/Widget/Wrapper/Bootstrap3.pm ↑ Summary FormHandler/Widget/Wrapper/Bootstrap.pm »
1 package HTML::FormHandler::Widget::Field::HorizCheckboxGroup;
2 # ABSTRACT: checkbox group field role
3 1 $HTML::FormHandler::Widget::Field::HorizCheckboxGroup::VERSION = '0.410000';
4 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use HTML::FormHandler::Render::Util ('process_attrs');
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 sub render {
10 1 ▶ my ( $self, $result ) = @_;
Subroutine render: called CC=3 SCAR=11.8
Pod undocumented
11 1 ▶ $result ||= $self->result;
Condition33%1/3
$result ||= $self->result
l!l&&r!l&&!r
010
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
12 1 ▶ die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 1 1
13 1 my $output = $self->render_element( $result );
14 1 return $self->wrap_field( $result, $output );
15 }
16  
17 sub render_element {
18 1 ▶ my ( $self, $result ) = @_;
Subroutine render_element: called CC=8 SCAR=31.9
Pod undocumented
19 1 ▶ $result ||= $self->result;
Condition33%1/3
$result ||= $self->result
l!l&&r!l&&!r
100
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
20  
21  
22 # loop through options
23 1 my $output = '';
24 1 foreach my $option ( @{ $self->{options} } ) {
25 4 ▶ if ( my $label = $option->{group} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $label = $option->{'group'}) { } 0 4 4
26 0 ▶ $label = $self->_localize( $label ) if $self->localize_labels;
Branch: 1 branch
BranchTrueFalseTotal
if $self->localize_labels 0 0 0
27 0 ▶ my $attr = $option->{attributes} || {};
Condition0%0/2
$option->{'attributes'} || {}
l!l
00
MC/DC0%0/1
$option->{'attributes'} || {}
$option->{'attributes'}
Truth table0%0/2
A
A= $option->{'attributes'}
Aresult
11
00
28 0 my $attr_str = process_attrs($attr);
29 0 ▶ my $lattr = $option->{label_attributes} || {};
Condition0%0/2
$option->{'label_attributes'} || {}
l!l
00
MC/DC0%0/1
$option->{'label_attributes'} || {}
$option->{'label_attributes'}
Truth table0%0/2
A
A= $option->{'label_attributes'}
Aresult
11
00
30 0 my $lattr_str= process_attrs($lattr);
31 0 $output .= qq{\n<div$attr_str><label$lattr_str>$label</label>};
32 0 foreach my $group_opt ( @{ $option->{options} } ) {
33 0 $output .= $self->render_option( $group_opt, $result );
34 }
35 0 $output .= qq{\n</div>};
36 }
37 else {
38 4 $output .= $self->render_option( $option, $result );
39 }
40 }
41 1 $self->reset_options_index;
42 1 return $output;
43 }
44  
45 sub render_option {
46 4 ▶ my ( $self, $option, $result ) = @_;
Subroutine render_option: called CC=12 SCAR=28.2
Pod undocumented
47 4 ▶ $result ||= $self->result;
Condition33%1/3
$result ||= $self->result
l!l&&r!l&&!r
400
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
48  
49 # get existing values
50 4 my $fif = $result->fif;
51 4 my %fif_lookup;
52 4 ▶ @fif_lookup{@$fif} = () if $self->multiple;
Branch: 1 branch
BranchTrueFalseTotal
if $self->multiple 4 0 4
53  
54 # create option label attributes
55 4 ▶ my $lattr = $option->{label_attributes} || {};
Condition50%1/2
$option->{'label_attributes'} || {}
l!l
04
MC/DC0%0/1
$option->{'label_attributes'} || {}
$option->{'label_attributes'}
Truth table50%1/2
A
A= $option->{'label_attributes'}
Aresult
11
00
56 4 my $lattr_str = process_attrs( $lattr );
57  
58 4 my $id = $self->id . '.' . $self->options_index;
59  
60 # start wrapping div
61 4 my $output = qq{<div class="checkbox">};
62  
63 4 $output .= qq{\n<label$lattr_str for="$id">};
64 4 my $value = $option->{value};
65 4 $output .= qq{\n<input type="checkbox"};
66 4 $output .= qq{ value="} . $self->html_filter($value) . '"';
67 4 $output .= qq{ name="} . $self->html_name . '"';
68 4 $output .= qq{ id="$id"};
69  
70 # handle option attributes
71 4 ▶ my $attr = $option->{attributes} || {};
Condition50%1/2
$option->{'attributes'} || {}
l!l
04
MC/DC0%0/1
$option->{'attributes'} || {}
$option->{'attributes'}
Truth table50%1/2
A
A= $option->{'attributes'}
Aresult
11
00
72 4 ▶ if( defined $option->{disabled} && $option->{disabled} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $option->{"disabled"} and $option->{"disabled"}) 0 4 4
Condition33%1/3
defined $option->{"disabled"} and $option->{"disabled"}
!ll&&!rl&&r
400
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
73 0 $attr->{disabled} = 'disabled';
74 }
75 4 ▶ if ( defined $fif &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fif and $self->multiple && exists $fif_lookup{$value} || $fif eq $value) 0 4 4
Condition33%3/9
defined $fif and $self->multiple && exists $fif_lookup{$value} || $fif eq $value
!ll&&!rl&&r
040
$self->multiple and exists $fif_lookup{$value} or $fif eq $value
l!l&&r!l&&!r
004
$self->multiple and exists $fif_lookup{$value}
!ll&&!rl&&r
040
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
76 ( ( $self->multiple && exists $fif_lookup{$value} ) ||
77 ( $fif eq $value ) ) ) {
78 0 $attr->{checked} = 'checked';
79 }
80 4 $output .= process_attrs($attr);
81 4 $output .= " />\n";
82  
83 # handle label
84 4 my $label = $option->{label};
85 4 ▶ $label = $self->_localize($label) if $self->localize_labels;
Branch: 1 branch
BranchTrueFalseTotal
if $self->localize_labels 0 4 4
86 4 $output .= $self->html_filter($label);
87 4 $output .= "\n</label>";
88  
89 # close wrapping div
90 4 $output .= "\n</div>";
91  
92 4 $self->inc_options_index;
93 4 return $output;
94 }
95  
96 1 1;
97  
98 __END__
99  
100 =pod
101  
102 =encoding UTF-8
103  
104 =head1 NAME
105  
106 HTML::FormHandler::Widget::Field::HorizCheckboxGroup - checkbox group field role
107  
108 =head1 VERSION
109  
110 version 0.410000
111  
112 =head1 SYNOPSIS
113  
114 Checkbox group widget for rendering multiple selects.
115  
116 Wraps each checkbox in a div.
117  
118 =head1 AUTHOR
119  
120 FormHandler Contributors - see HTML::FormHandler
121  
122 =head1 COPYRIGHT AND LICENSE
123  
124 This software is copyright (c) 2017 by Gerda Shank.
125  
126 This is free software; you can redistribute it and/or modify it under
127 the same terms as the Perl 5 programming language system itself.
128  
129 =cut
« FormHandler/Widget/Wrapper/Bootstrap3.pm ↑ Summary FormHandler/Widget/Wrapper/Bootstrap.pm »