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/Field/Repeatable.pm ↑ Summary FormHandler/Foo.pm »
1 package HTML::FormHandler::Widget::Wrapper::Base;
2 # ABSTRACT: common methods for widget wrappers
3 144 $HTML::FormHandler::Widget::Wrapper::Base::VERSION = '0.410002';
4 144 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 144 ▶use HTML::FormHandler::Render::Util ('process_attrs');
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 426 ▶sub do_render_label {
Subroutine do_render_label: called CC=8 SCAR=20.9
Pod undocumented
9 426 my ( $self, $result, $label_tag, $class ) = @_;
10  
11 426 ▶ $label_tag ||= $self->get_tag('label_tag') || 'label';
Condition60%3/5
$label_tag ||= $self->get_tag("label_tag") || "label"
l!l&&r!l&&!r
333930
$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 426 my $attr = $self->label_attributes( $result );
13 426 ▶ push @{ $attr->{class} }, @$class if $class;
Branch: 1 branch
BranchTrueFalseTotal
if $class 58 368 426
14 426 my $attrs = process_attrs($attr);
15 426 my $label;
16 426 ▶ if( $self->does_wrap_label ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->does_wrap_label) { } 1 425 426
17 1 $label = $self->wrap_label( $self->label );
18 }
19 else {
20 425 ▶ $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 425 425
21 }
22 426 ▶ $label .= $self->get_tag('label_after') if $label_tag ne 'legend';
Branch: 1 branch
BranchTrueFalseTotal
if $label_tag ne "legend" 412 14 426
23 426 my $id = $self->id;
24 426 ▶ my $for = $label_tag eq 'label' ? qq{ for="$id"} : '';
Branch: 1 branch
BranchTrueFalseTotal
$label_tag eq 'label' ? : 402 24 426
25 426 return qq{<$label_tag$attrs$for>$label</$label_tag>};
26 }
27  
28 31 ▶sub wrap_checkbox {
Subroutine wrap_checkbox: called CC=6 SCAR=18.8
Pod undocumented
29 31 my ( $self, $result, $rendered_widget, $default_wrapper ) = @_;
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 30 ▶sub standard_wrap_checkbox {
Subroutine standard_wrap_checkbox: called CC=5 SCAR=16.2
Pod undocumented
46 30 my ( $self, $result, $rendered_widget ) = @_;
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 27 ▶sub get_checkbox_label {
Subroutine get_checkbox_label: called CC=7 SCAR=19.5
Pod undocumented
75 27 my $self = shift;
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 0 ▶sub b3_label_left {
Subroutine b3_label_left: not called CC=1 SCAR=6.9
Pod undocumented
88 0 my ( $self, $result, $rendered_widget ) = @_;
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 0 ▶sub b3_label_left_inline {
Subroutine b3_label_left_inline: not called CC=1 SCAR=6.9
Pod undocumented
99 0 my ( $self, $result, $rendered_widget ) = @_;
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 0 ▶sub b3_label_right {
Subroutine b3_label_right: not called CC=1 SCAR=6.9
Pod undocumented
108 0 my ( $self, $result, $rendered_widget ) = @_;
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 0 ▶sub label_left {
Subroutine label_left: not called CC=1 SCAR=6.9
Pod undocumented
119 0 my ( $self, $result, $rendered_widget ) = @_;
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 0 ▶sub label_right {
Subroutine label_right: not called CC=1 SCAR=6.9
Pod undocumented
128 0 my ( $self, $result, $rendered_widget ) = @_;
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 0 ▶sub no_wrapped_label {
Subroutine no_wrapped_label: not called CC=1 SCAR=6.9
Pod undocumented
137 0 my ( $self, $result, $rendered_widget ) = @_;
138 0 return $rendered_widget;
139 }
140  
141  
142 # for compatibility with older code
143 0 ▶sub render_label {
Subroutine render_label: not called CC=2 SCAR=17.9
Pod undocumented
144 0 my $self = shift;
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 0 ▶sub render_class {
Subroutine render_class: not called CC=2 SCAR=17.9
Pod undocumented
155 0 my ( $self, $result ) = @_;
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 6 ▶sub render_elementx {
Subroutine render_elementx: called CC=5 SCAR=16.8
Pod undocumented
161 6 my ($self, %args) = @_;
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 1 ▶sub renderx {
Subroutine renderx: called CC=5 SCAR=16.8
Pod undocumented
175 1 my ($self, %args) = @_;
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 144 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
189 144 1;
190  
191 __END__
« FormHandler/Field/Repeatable.pm ↑ Summary FormHandler/Foo.pm »