line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormHandler::Widget::Wrapper::Base; |
2
|
|
|
|
|
|
|
# ABSTRACT: common methods for widget wrappers |
3
|
|
|
|
|
|
|
$HTML::FormHandler::Widget::Wrapper::Base::VERSION = '0.40068'; |
4
|
140
|
|
|
140
|
|
93138
|
use Moose::Role; |
|
140
|
|
|
|
|
527
|
|
|
140
|
|
|
|
|
1084
|
|
5
|
140
|
|
|
140
|
|
741958
|
use HTML::FormHandler::Render::Util ('process_attrs'); |
|
140
|
|
|
|
|
423
|
|
|
140
|
|
|
|
|
1254
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub do_render_label { |
9
|
409
|
|
|
409
|
0
|
1260
|
my ( $self, $result, $label_tag, $class ) = @_; |
10
|
|
|
|
|
|
|
|
11
|
409
|
|
50
|
|
|
1547
|
$label_tag ||= $self->get_tag('label_tag') || 'label'; |
|
|
|
66
|
|
|
|
|
12
|
409
|
|
|
|
|
2177
|
my $attr = $self->label_attributes( $result ); |
13
|
409
|
100
|
|
|
|
1303
|
push @{ $attr->{class} }, @$class if $class; |
|
58
|
|
|
|
|
222
|
|
14
|
409
|
|
|
|
|
1445
|
my $attrs = process_attrs($attr); |
15
|
409
|
|
|
|
|
870
|
my $label; |
16
|
409
|
100
|
|
|
|
13834
|
if( $self->does_wrap_label ) { |
17
|
1
|
|
|
|
|
24
|
$label = $self->wrap_label( $self->label ); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
else { |
20
|
408
|
50
|
|
|
|
1480
|
$label = $self->get_tag('label_no_filter') ? $self->loc_label : $self->html_filter($self->loc_label); |
21
|
|
|
|
|
|
|
} |
22
|
409
|
100
|
|
|
|
2409
|
$label .= $self->get_tag('label_after') if $label_tag ne 'legend'; |
23
|
409
|
|
|
|
|
10706
|
my $id = $self->id; |
24
|
409
|
100
|
|
|
|
1807
|
my $for = $label_tag eq 'label' ? qq{ for="$id"} : ''; |
25
|
409
|
|
|
|
|
2595
|
return qq{<$label_tag$attrs$for>$label</$label_tag>}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub wrap_checkbox { |
29
|
31
|
|
|
31
|
0
|
111
|
my ( $self, $result, $rendered_widget, $default_wrapper ) = @_; |
30
|
|
|
|
|
|
|
|
31
|
31
|
|
66
|
|
|
952
|
my $option_wrapper = $self->option_wrapper || $default_wrapper; |
32
|
31
|
100
|
66
|
|
|
167
|
if ( $option_wrapper && $option_wrapper ne 'standard' && |
|
|
|
66
|
|
|
|
|
33
|
|
|
|
|
|
|
$option_wrapper ne 'label' ) { |
34
|
1
|
50
|
|
|
|
9
|
unless ( $self->can($option_wrapper) ) { |
35
|
1
|
|
|
|
|
17
|
die "HFH: no option_wrapper method '$option_wrapper'"; |
36
|
|
|
|
|
|
|
} |
37
|
0
|
|
|
|
|
0
|
return $self->$option_wrapper($result, $rendered_widget); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
30
|
|
|
|
|
132
|
return $self->standard_wrap_checkbox($result, $rendered_widget); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub standard_wrap_checkbox { |
46
|
30
|
|
|
30
|
0
|
92
|
my ( $self, $result, $rendered_widget ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
30
|
100
|
|
|
|
107
|
return $rendered_widget |
49
|
|
|
|
|
|
|
if( $self->get_tag('no_wrapped_label' ) ); |
50
|
|
|
|
|
|
|
|
51
|
27
|
|
|
|
|
107
|
my $label = $self->get_checkbox_label; |
52
|
27
|
|
|
|
|
682
|
my $id = $self->id; |
53
|
27
|
|
|
|
|
88
|
my $for = qq{ for="$id"}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# use "simple" label attributes for inner label |
56
|
27
|
|
|
|
|
83
|
my @label_class = ('checkbox'); |
57
|
27
|
50
|
|
|
|
101
|
push @label_class, 'inline' if $self->get_tag('inline'); |
58
|
27
|
|
|
|
|
149
|
my $lattrs = process_attrs( { class => \@label_class } ); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# return wrapped checkbox, either on left or right |
61
|
27
|
|
|
|
|
81
|
my $output = ''; |
62
|
27
|
100
|
|
|
|
112
|
if ( $self->get_tag('label_left') ) { |
63
|
1
|
|
|
|
|
5
|
$output = qq{<label$lattrs$for>\n$label\n$rendered_widget</label>}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
26
|
|
|
|
|
130
|
$output = qq{<label$lattrs$for>$rendered_widget\n$label\n</label>}; |
67
|
|
|
|
|
|
|
} |
68
|
27
|
50
|
|
|
|
91
|
if ( $self->get_tag('checkbox_element_wrapper') ) { |
69
|
0
|
|
|
|
|
0
|
$output = qq{<div class="checkbox">$output</div>}; |
70
|
|
|
|
|
|
|
} |
71
|
27
|
|
|
|
|
115
|
return $output; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub get_checkbox_label { |
75
|
27
|
|
|
27
|
0
|
59
|
my $self = shift; |
76
|
|
|
|
|
|
|
|
77
|
27
|
|
100
|
|
|
880
|
my $label = $self->option_label || ''; |
78
|
27
|
100
|
100
|
|
|
541
|
if( $label eq '' && ! $self->do_label ) { |
|
|
100
|
|
|
|
|
|
79
|
3
|
50
|
|
|
|
10
|
$label = $self->get_tag('label_no_filter') ? $self->loc_label : $self->html_filter($self->loc_label); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
elsif( $label ne '' ) { |
82
|
11
|
50
|
|
|
|
53
|
$label = $self->get_tag('label_no_filter') ? $self->_localize($label) : $self->html_filter($self->_localize($label)); |
83
|
|
|
|
|
|
|
} |
84
|
27
|
|
|
|
|
84
|
return $label; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub b3_label_left { |
88
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $result, $rendered_widget ) = @_; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
0
|
my $label = $self->get_checkbox_label; |
91
|
0
|
|
|
|
|
0
|
my $id = $self->id; |
92
|
0
|
|
|
|
|
0
|
my $output = qq{<div class="checkbox">}; |
93
|
0
|
|
|
|
|
0
|
$output .= qq{<label for="$id">\n$label\n$rendered_widget</label>}; |
94
|
0
|
|
|
|
|
0
|
$output .= qq{</div>}; |
95
|
0
|
|
|
|
|
0
|
return $output; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub b3_label_left_inline { |
99
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $result, $rendered_widget ) = @_; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
0
|
my $label = $self->get_checkbox_label; |
102
|
0
|
|
|
|
|
0
|
my $id = $self->id; |
103
|
0
|
|
|
|
|
0
|
my $output .= qq{<label class="checkbox-inline" for="$id">\n$label\n$rendered_widget</label>}; |
104
|
0
|
|
|
|
|
0
|
return $output; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub b3_label_right { |
108
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $result, $rendered_widget ) = @_; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
0
|
my $label = $self->get_checkbox_label; |
111
|
0
|
|
|
|
|
0
|
my $id = $self->id; |
112
|
0
|
|
|
|
|
0
|
my $output = qq{<div class="checkbox">}; |
113
|
0
|
|
|
|
|
0
|
$output .= qq{<label for="$id">$rendered_widget\n$label\n</label>}; |
114
|
0
|
|
|
|
|
0
|
$output .= qq{</div>}; |
115
|
0
|
|
|
|
|
0
|
return $output; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub label_left { |
119
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $result, $rendered_widget ) = @_; |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
0
|
my $label = $self->get_checkbox_label; |
122
|
0
|
|
|
|
|
0
|
my $id = $self->id; |
123
|
0
|
|
|
|
|
0
|
my $output .= qq{<label class="checkbox" for="$id">\n$label\n$rendered_widget</label>}; |
124
|
0
|
|
|
|
|
0
|
return $output; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub label_right { |
128
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $result, $rendered_widget ) = @_; |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
0
|
my $label = $self->get_checkbox_label; |
131
|
0
|
|
|
|
|
0
|
my $id = $self->id; |
132
|
0
|
|
|
|
|
0
|
my $output .= qq{<label class="checkbox" for="$id">$rendered_widget\n$label\n</label>}; |
133
|
0
|
|
|
|
|
0
|
return $output; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub no_wrapped_label { |
137
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $result, $rendered_widget ) = @_; |
138
|
0
|
|
|
|
|
0
|
return $rendered_widget; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# for compatibility with older code |
143
|
|
|
|
|
|
|
sub render_label { |
144
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
145
|
0
|
|
|
|
|
0
|
my $attrs = process_attrs($self->label_attributes); |
146
|
0
|
|
|
|
|
0
|
my $label = $self->html_filter($self->loc_label); |
147
|
0
|
0
|
|
|
|
0
|
$label .= ": " unless $self->get_tag('label_no_colon'); |
148
|
0
|
|
|
|
|
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
|
|
|
0
|
0
|
0
|
my ( $self, $result ) = @_; |
156
|
0
|
|
0
|
|
|
0
|
$result ||= $self->result; |
157
|
0
|
|
|
|
|
0
|
return process_attrs($self->wrapper_attributes($result)); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub render_elementx { |
161
|
6
|
|
|
6
|
0
|
27
|
my ($self, %args) = @_; |
162
|
6
|
|
33
|
|
|
222
|
my $result ||= $self->result; |
163
|
|
|
|
|
|
|
|
164
|
6
|
50
|
|
|
|
24
|
if ( keys %args > 0 ) { |
165
|
6
|
|
|
|
|
38
|
while ( my ( $key, $value ) = each %args ) { |
166
|
6
|
50
|
|
|
|
83
|
confess "invalid attribute '$key' passed to render_elementx" |
167
|
|
|
|
|
|
|
unless $self->can($key); |
168
|
6
|
|
|
|
|
169
|
$self->$key($value); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
} |
171
|
6
|
|
|
|
|
36
|
$self->render_element($result); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub renderx { |
175
|
1
|
|
|
1
|
0
|
6
|
my ($self, %args) = @_; |
176
|
1
|
|
33
|
|
|
33
|
my $result ||= $self->result; |
177
|
|
|
|
|
|
|
|
178
|
1
|
50
|
|
|
|
5
|
if ( keys %args > 0 ) { |
179
|
1
|
|
|
|
|
6
|
while ( my ( $key, $value ) = each %args ) { |
180
|
1
|
50
|
|
|
|
6
|
confess "invalid attribute '$key' passed to renderx" |
181
|
|
|
|
|
|
|
unless $self->can($key); |
182
|
1
|
|
|
|
|
29
|
$self->$key($value); |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
} |
185
|
1
|
|
|
|
|
6
|
$self->render($result); |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
140
|
|
|
140
|
|
173334
|
use namespace::autoclean; |
|
140
|
|
|
|
|
440
|
|
|
140
|
|
|
|
|
3531
|
|
189
|
|
|
|
|
|
|
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.40068 |
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 |