FormHandler/Widget/Wrapper/Base.pm

filter: Statementstmt 61.3% 65 / 106 Branchbran 72.7% 32 / 44 Conditioncond 57.1% 16 / 28 MC/DCmcdc 31.2% 5 / 16 Subroutinesub 52.9% 9 / 17 Podpod 0.0% 0 / 14 totaltotal 56.4% 127 / 225 CC 33 SCAR 17.1
CC
33
Cov
63%
do_render_label
8.1
get_checkbox_label
7.1
wrap_checkbox
6.6
CRAP 5.5
« FormHandler/Render/Util.pm ↑ Summary FormHandler/Widget/Field/RadioGroup.pm »
1 package HTML::FormHandler::Widget::Wrapper::Base;
2 # ABSTRACT: common methods for widget wrappers
3 143 $HTML::FormHandler::Widget::Wrapper::Base::VERSION = '0.410001';
4 143 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 143 ▶use HTML::FormHandler::Render::Util ('process_attrs');
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 sub do_render_label {
9 422 ▶ my ( $self, $result, $label_tag, $class ) = @_;
Subroutine do_render_label: called CC=8 SCAR=20.9
Pod undocumented
10  
11 422 ▶ $label_tag ||= $self->get_tag('label_tag') || 'label';
Condition60%3/5
$label_tag ||= $self->get_tag("label_tag") || "label"
l!l&&r!l&&!r
329930
$self->get_tag('label_tag') || 'label'
l!l
093
MC/DC0%0/2
$label_tag ||= $self->get_tag("label_tag") || "label"
$label_tag $self->get_tag('label_tag')
Truth table33%1/3
A ||= B
A= $label_tagB= $self->get_tag('label_tag')
ABresult
1X1
011
000
12 422 my $attr = $self->label_attributes( $result );
13 422 ▶ push @{ $attr->{class} }, @$class if $class;
Branch: 1 branch
BranchTrueFalseTotal
if $class 58 364 422
14 422 my $attrs = process_attrs($attr);
15 422 my $label;
16 422 ▶ if( $self->does_wrap_label ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->does_wrap_label) { } 1 421 422
17 1 $label = $self->wrap_label( $self->label );
18 }
19 else {
20 421 ▶ $label = $self->get_tag('label_no_filter') ? $self->loc_label : $self->html_filter($self->loc_label);
Branch: 1 branch
BranchTrueFalseTotal
$self->get_tag('label_no_filter') ? : 0 421 421
21 }
22 422 ▶ $label .= $self->get_tag('label_after') if $label_tag ne 'legend';
Branch: 1 branch
BranchTrueFalseTotal
if $label_tag ne "legend" 408 14 422
23 422 my $id = $self->id;
24 422 ▶ my $for = $label_tag eq 'label' ? qq{ for="$id"} : '';
Branch: 1 branch
BranchTrueFalseTotal
$label_tag eq 'label' ? : 398 24 422
25 422 return qq{<$label_tag$attrs$for>$label</$label_tag>};
26 }
27  
28 sub wrap_checkbox {
29 31 ▶ my ( $self, $result, $rendered_widget, $default_wrapper ) = @_;
Subroutine wrap_checkbox: called CC=6 SCAR=18.8
Pod undocumented
30  
31 31 ▶ my $option_wrapper = $self->option_wrapper || $default_wrapper;
Condition66%2/3
$self->option_wrapper || $default_wrapper
l!l&&r!l&&!r
1030
MC/DC50%1/2
$self->option_wrapper || $default_wrapper
$self->option_wrapper $default_wrapper
Truth table66%2/3
A || B
A= $self->option_wrapperB= $default_wrapper
ABresult
1X1
011
000
32 31 ▶ if ( $option_wrapper && $option_wrapper ne 'standard' &&
Branch: 1 branch
BranchTrueFalseTotal
if ($option_wrapper and $option_wrapper ne 'standard' and $option_wrapper ne 'label') { } 1 30 31
Condition66%4/6
$option_wrapper and $option_wrapper ne "standard" and $option_wrapper ne "label"
!ll&&!rl&&r
3001
$option_wrapper and $option_wrapper ne "standard"
!ll&&!rl&&r
3001
MC/DC33%1/3
$option_wrapper and $option_wrapper ne "standard" and $option_wrapper ne "label"
$option_wrapper $option_wrapper ne "standard" $option_wrapper ne "label"
Truth table50%2/4
A and B and C
A= $option_wrapperB= $option_wrapper ne "standard"C= $option_wrapper ne "label"
ABCresult
0XX0
10X0
1100
1111
33 $option_wrapper ne 'label' ) {
34 1 ▶ unless ( $self->can($option_wrapper) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->can($option_wrapper)) 1 0 1
35 1 die "HFH: no option_wrapper method '$option_wrapper'";
36 }
37 0 return $self->$option_wrapper($result, $rendered_widget);
38 }
39 else {
40 30 return $self->standard_wrap_checkbox($result, $rendered_widget);
41 }
42  
43 }
44  
45 sub standard_wrap_checkbox {
46 30 ▶ my ( $self, $result, $rendered_widget ) = @_;
Subroutine standard_wrap_checkbox: called CC=5 SCAR=16.2
Pod undocumented
47  
48 30 ▶ return $rendered_widget
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_tag("no_wrapped_label") 3 27 30
49 if( $self->get_tag('no_wrapped_label' ) );
50  
51 27 my $label = $self->get_checkbox_label;
52 27 my $id = $self->id;
53 27 my $for = qq{ for="$id"};
54  
55 # use "simple" label attributes for inner label
56 27 my @label_class = ('checkbox');
57 27 ▶ push @label_class, 'inline' if $self->get_tag('inline');
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_tag("inline") 0 27 27
58 27 my $lattrs = process_attrs( { class => \@label_class } );
59  
60 # return wrapped checkbox, either on left or right
61 27 my $output = '';
62 27 ▶ if ( $self->get_tag('label_left') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_tag('label_left')) { } 1 26 27
63 1 $output = qq{<label$lattrs$for>\n$label\n$rendered_widget</label>};
64 }
65 else {
66 26 $output = qq{<label$lattrs$for>$rendered_widget\n$label\n</label>};
67 }
68 27 ▶ if ( $self->get_tag('checkbox_element_wrapper') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_tag("checkbox_element_wrapper")) 0 27 27
69 0 $output = qq{<div class="checkbox">$output</div>};
70 }
71 27 return $output;
72 }
73  
74 sub get_checkbox_label {
75 27 ▶ my $self = shift;
Subroutine get_checkbox_label: called CC=7 SCAR=19.5
Pod undocumented
76  
77 27 ▶ my $label = $self->option_label || '';
Condition100%2/2
$self->option_label || ''
l!l
1116
MC/DC100%1/1
$self->option_label || ''
$self->option_label
Truth table100%2/2
A
A= $self->option_label
Aresult
11
00
78 27 ▶ if( $label eq '' && ! $self->do_label ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($label eq '' and not $self->do_label) { } 3 24 27
elsif ($label ne '') { } 11 13 24
Condition100%3/3
$label eq "" and not $self->do_label
!ll&&!rl&&r
11133
MC/DC100%2/2
$label eq "" and not $self->do_label
$label eq "" not $self->do_label
Truth table100%3/3
A and not(B)
A= $label eq ""B= not $self->do_label
ABresult
0X0
100
111
79 3 ▶ $label = $self->get_tag('label_no_filter') ? $self->loc_label : $self->html_filter($self->loc_label);
Branch: 1 branch
BranchTrueFalseTotal
$self->get_tag('label_no_filter') ? : 0 3 3
80 }
81 elsif( $label ne '' ) {
82 11 ▶ $label = $self->get_tag('label_no_filter') ? $self->_localize($label) : $self->html_filter($self->_localize($label));
Branch: 1 branch
BranchTrueFalseTotal
$self->get_tag('label_no_filter') ? : 0 11 11
83 }
84 27 return $label;
85 }
86  
87 sub b3_label_left {
88 0 ▶ my ( $self, $result, $rendered_widget ) = @_;
Subroutine b3_label_left: not called CC=1 SCAR=6.9
Pod undocumented
89  
90 0 my $label = $self->get_checkbox_label;
91 0 my $id = $self->id;
92 0 my $output = qq{<div class="checkbox">};
93 0 $output .= qq{<label for="$id">\n$label\n$rendered_widget</label>};
94 0 $output .= qq{</div>};
95 0 return $output;
96 }
97  
98 sub b3_label_left_inline {
99 0 ▶ my ( $self, $result, $rendered_widget ) = @_;
Subroutine b3_label_left_inline: not called CC=1 SCAR=6.9
Pod undocumented
100  
101 0 my $label = $self->get_checkbox_label;
102 0 my $id = $self->id;
103 0 my $output = qq{<label class="checkbox-inline" for="$id">\n$label\n$rendered_widget</label>};
104 0 return $output;
105 }
106  
107 sub b3_label_right {
108 0 ▶ my ( $self, $result, $rendered_widget ) = @_;
Subroutine b3_label_right: not called CC=1 SCAR=6.9
Pod undocumented
109  
110 0 my $label = $self->get_checkbox_label;
111 0 my $id = $self->id;
112 0 my $output = qq{<div class="checkbox">};
113 0 $output .= qq{<label for="$id">$rendered_widget\n$label\n</label>};
114 0 $output .= qq{</div>};
115 0 return $output;
116 }
117  
118 sub label_left {
119 0 ▶ my ( $self, $result, $rendered_widget ) = @_;
Subroutine label_left: not called CC=1 SCAR=6.9
Pod undocumented
120  
121 0 my $label = $self->get_checkbox_label;
122 0 my $id = $self->id;
123 0 my $output = qq{<label class="checkbox" for="$id">\n$label\n$rendered_widget</label>};
124 0 return $output;
125 }
126  
127 sub label_right {
128 0 ▶ my ( $self, $result, $rendered_widget ) = @_;
Subroutine label_right: not called CC=1 SCAR=6.9
Pod undocumented
129  
130 0 my $label = $self->get_checkbox_label;
131 0 my $id = $self->id;
132 0 my $output = qq{<label class="checkbox" for="$id">$rendered_widget\n$label\n</label>};
133 0 return $output;
134 }
135  
136 sub no_wrapped_label {
137 0 ▶ my ( $self, $result, $rendered_widget ) = @_;
Subroutine no_wrapped_label: not called CC=1 SCAR=6.9
Pod undocumented
138 0 return $rendered_widget;
139 }
140  
141  
142 # for compatibility with older code
143 sub render_label {
144 0 ▶ my $self = shift;
Subroutine render_label: not called CC=2 SCAR=17.9
Pod undocumented
145 0 my $attrs = process_attrs($self->label_attributes);
146 0 my $label = $self->html_filter($self->loc_label);
147 0 ▶ $label .= ": " unless $self->get_tag('label_no_colon');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_tag("label_no_colon") 0 0 0
148 0 return qq{<label$attrs for="} . $self->id . qq{">$label</label>};
149 }
150  
151  
152 # this is not actually used any more, but is left here for compatibility
153 # with user created widgets
154 sub render_class {
155 0 ▶ my ( $self, $result ) = @_;
Subroutine render_class: not called CC=2 SCAR=17.9
Pod undocumented
156 0 ▶ $result ||= $self->result;
Condition0%0/3
$result ||= $self->result
l!l&&r!l&&!r
000
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table0%0/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
157 0 return process_attrs($self->wrapper_attributes($result));
158 }
159  
160 sub render_elementx {
161 6 ▶ my ($self, %args) = @_;
Subroutine render_elementx: called CC=5 SCAR=16.8
Pod undocumented
162 6 ▶ my $result ||= $self->result;
Condition33%1/3
my $result ||= $self->result
l!l&&r!l&&!r
060
MC/DC0%0/2
my $result ||= $self->result
my $result $self->result
Truth table33%1/3
A ||= B
A= my $resultB= $self->result
ABresult
1X1
011
000
163  
164 6 ▶ if ( keys %args > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %args > 0) 6 0 6
165 6 ▶ while ( my ( $key, $value ) = each %args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 6 6 12
166 6 ▶ confess "invalid attribute '$key' passed to render_elementx"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($key) 0 6 6
167 unless $self->can($key);
168 6 $self->$key($value);
169 }
170 }
171 6 $self->render_element($result);
172 }
173  
174 sub renderx {
175 1 ▶ my ($self, %args) = @_;
Subroutine renderx: called CC=5 SCAR=16.8
Pod undocumented
176 1 ▶ my $result ||= $self->result;
Condition33%1/3
my $result ||= $self->result
l!l&&r!l&&!r
010
MC/DC0%0/2
my $result ||= $self->result
my $result $self->result
Truth table33%1/3
A ||= B
A= my $resultB= $self->result
ABresult
1X1
011
000
177  
178 1 ▶ if ( keys %args > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %args > 0) 1 0 1
179 1 ▶ while ( my ( $key, $value ) = each %args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 1 1 2
180 1 ▶ confess "invalid attribute '$key' passed to renderx"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($key) 0 1 1
181 unless $self->can($key);
182 1 $self->$key($value);
183 }
184 }
185 1 $self->render($result);
186 }
187  
188 143 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
189 143 1;
190  
191 __END__
192  
193 =pod
194  
195 =encoding UTF-8
196  
197 =head1 NAME
198  
199 HTML::FormHandler::Widget::Wrapper::Base - common methods for widget wrappers
200  
201 =head1 VERSION
202  
203 version 0.410001
204  
205 =head1 DESCRIPTION
206  
207 Provides several common methods for wrapper widgets, including
208 'do_render_label' and 'wrap_checkbox'.
209  
210 Implements the checkbox 'option_wrapper' rendering:
211  
212 b3_label_left
213 b3_label_right
214 b3_label_left_inline
215 label_left
216 label_right
217 no_wrapped_label
218  
219 =head1 NAME
220  
221 HTML::FormHandler::Widget::Wrapper::Base
222  
223 =head1 AUTHOR
224  
225 FormHandler Contributors - see HTML::FormHandler
226  
227 =head1 COPYRIGHT AND LICENSE
228  
229 This software is copyright (c) 2017 by Gerda Shank.
230  
231 This is free software; you can redistribute it and/or modify it under
232 the same terms as the Perl 5 programming language system itself.
233  
234 =cut
« FormHandler/Render/Util.pm ↑ Summary FormHandler/Widget/Field/RadioGroup.pm »