line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Widget::Container; |
2
|
|
|
|
|
|
|
|
3
|
88
|
|
|
88
|
|
479
|
use warnings; |
|
88
|
|
|
|
|
208
|
|
|
88
|
|
|
|
|
2667
|
|
4
|
88
|
|
|
88
|
|
436
|
use strict; |
|
88
|
|
|
|
|
158
|
|
|
88
|
|
|
|
|
2644
|
|
5
|
88
|
|
|
88
|
|
433
|
use base 'Class::Accessor::Fast'; |
|
88
|
|
|
|
|
166
|
|
|
88
|
|
|
|
|
11632
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/element label error javascript passive name/); |
8
|
|
|
|
|
|
|
|
9
|
88
|
|
|
88
|
|
189718
|
use overload '""' => sub { return shift->as_xml }, fallback => 1; |
|
88
|
|
|
6
|
|
154739
|
|
|
88
|
|
|
|
|
904
|
|
|
6
|
|
|
|
|
922
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
*js = \&javascript; |
12
|
|
|
|
|
|
|
*js_xml = \&javascript_xml; |
13
|
|
|
|
|
|
|
*field = \&element; |
14
|
|
|
|
|
|
|
*field_xml = \&element_xml; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
HTML::Widget::Container - Container |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $container = $form->element('foo'); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $field = $container->field; |
25
|
|
|
|
|
|
|
my $error = $container->error; |
26
|
|
|
|
|
|
|
my $label = $container->label; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $field_xml = $container->field_xml; |
29
|
|
|
|
|
|
|
my $error_xml = $container->error_xml; |
30
|
|
|
|
|
|
|
my $javascript_xml = $container->javascript_xml; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $xml = $container->as_xml; |
33
|
|
|
|
|
|
|
# $xml eq "$container" |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $javascript = $container->javascript; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Container. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 METHODS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 as_xml |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Return Value: $xml |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub as_xml { |
50
|
8
|
|
|
8
|
1
|
3224
|
my $self = shift; |
51
|
8
|
|
|
|
|
16
|
my $xml = ''; |
52
|
8
|
50
|
|
|
|
28
|
$xml .= $self->element_xml if $self->element; |
53
|
8
|
50
|
|
|
|
3074
|
$xml .= $self->javascript_xml if $self->javascript; |
54
|
8
|
100
|
|
|
|
70
|
$xml .= $self->error_xml if $self->error; |
55
|
8
|
|
|
|
|
774
|
return $xml; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 _build_element |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Arguments: $element |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Return Value: @elements |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Convert $element to L object. Accepts arrayref. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
If you wish to change the rendering behaviour of HTML::Widget; specifically, |
67
|
|
|
|
|
|
|
the handling of elements which are array-refs, you can specify |
68
|
|
|
|
|
|
|
L to a custom class which just |
69
|
|
|
|
|
|
|
overrides this function. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _build_element { |
74
|
258
|
|
|
258
|
|
1586
|
my ( $self, $element ) = @_; |
75
|
|
|
|
|
|
|
|
76
|
258
|
100
|
|
|
|
777
|
return () unless $element; |
77
|
|
|
|
|
|
|
|
78
|
250
|
50
|
|
|
|
667
|
if ( ref $element eq 'ARRAY' ) { |
79
|
0
|
|
|
|
|
0
|
return map { $self->_build_element($_) } @{$element}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
250
|
|
|
|
|
922
|
return $self->build_single_element( $element->clone ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 build_single_element |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Arguments: $element |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Return Value: $element |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Convert $element to L object. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Called by L. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
If you wish to change the rendering behaviour of HTML::Widget; specifically, |
96
|
|
|
|
|
|
|
the handling of an individual element, you can override this function. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub build_single_element { |
101
|
250
|
|
|
250
|
1
|
9409
|
my ( $self, $element ) = @_; |
102
|
|
|
|
|
|
|
|
103
|
250
|
|
50
|
|
|
1274
|
my $class = $element->attr('class') || ''; |
104
|
|
|
|
|
|
|
|
105
|
250
|
|
|
|
|
3266
|
$element = $self->build_element_error($element); |
106
|
|
|
|
|
|
|
|
107
|
250
|
|
|
|
|
671
|
$element = $self->build_element_label( $element, $class ); |
108
|
|
|
|
|
|
|
|
109
|
250
|
|
|
|
|
1467
|
return $element; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 build_element_error |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Arguments: $element |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Return Value: $element |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Called by L. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
If you wish to change how an error is rendered, override this function. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub build_element_error { |
125
|
250
|
|
|
250
|
1
|
546
|
my ( $self, $element ) = @_; |
126
|
|
|
|
|
|
|
|
127
|
250
|
100
|
100
|
|
|
737
|
if ( $self->error && $element->tag eq 'input' ) { |
128
|
21
|
|
|
|
|
653
|
$element = HTML::Element->new( 'span', class => 'fields_with_errors' ) |
129
|
|
|
|
|
|
|
->push_content($element); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
250
|
|
|
|
|
2852
|
return $element; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 build_element_label |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Arguments: $element, $class |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Return Value: $element |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Called by L. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
If you wish to change how an element's label is rendered, override this |
144
|
|
|
|
|
|
|
function. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
The $class argument is the original class of the element, before |
147
|
|
|
|
|
|
|
L was called. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub build_element_label { |
152
|
250
|
|
|
250
|
1
|
410
|
my ( $self, $element, $class ) = @_; |
153
|
|
|
|
|
|
|
|
154
|
250
|
100
|
|
|
|
701
|
return $element unless defined $self->label; |
155
|
|
|
|
|
|
|
|
156
|
54
|
|
|
|
|
419
|
my $l = $self->label->clone; |
157
|
54
|
|
|
|
|
1823
|
my $radiogroup; |
158
|
|
|
|
|
|
|
|
159
|
54
|
100
|
100
|
|
|
310
|
if ( $class eq 'radiogroup_fieldset' ) { |
|
|
100
|
|
|
|
|
|
160
|
2
|
|
|
|
|
10
|
$element->unshift_content($l); |
161
|
2
|
|
|
|
|
36
|
$radiogroup = 1; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
elsif ( $self->error && $element->tag eq 'span' ) { |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# it might still be a radiogroup wrapped in an error span |
166
|
12
|
|
|
|
|
229
|
for my $elem ( $element->content_refs_list ) { |
167
|
12
|
50
|
|
|
|
109
|
next unless ref $$elem; |
168
|
12
|
100
|
|
|
|
48
|
if ( $$elem->attr('class') eq 'radiogroup_fieldset' ) { |
169
|
1
|
|
|
|
|
162
|
$$elem->unshift_content($l); |
170
|
1
|
|
|
|
|
87
|
$radiogroup = 1; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
54
|
100
|
|
|
|
541
|
if ( !$radiogroup ) { |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# Do we prepend or append input to label? |
178
|
51
|
100
|
100
|
|
|
351
|
$element = |
179
|
|
|
|
|
|
|
( $class eq 'checkbox' or $class eq 'radio' ) |
180
|
|
|
|
|
|
|
? $l->unshift_content($element) |
181
|
|
|
|
|
|
|
: $l->push_content($element); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
54
|
|
|
|
|
903
|
return $element; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 as_list |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Return Value: @elements |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Returns a list of L objects. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub as_list { |
196
|
360
|
|
|
360
|
1
|
1521
|
my $self = shift; |
197
|
360
|
|
|
|
|
429
|
my @list; |
198
|
360
|
|
|
|
|
1407
|
push @list, $self->_build_element( $self->element ); |
199
|
360
|
50
|
|
|
|
2397
|
push @list, $self->javascript_element if $self->javascript; |
200
|
360
|
100
|
|
|
|
2814
|
push @list, $self->error if $self->error; |
201
|
360
|
|
|
|
|
3731
|
return @list; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 element |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head2 field |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Arguments: $element |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
L is an alias for L. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head2 element_xml |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head2 field_xml |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Return Value: $xml |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
L is an alias for L. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=cut |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub element_xml { |
223
|
10
|
|
|
10
|
1
|
8992
|
my $self = shift; |
224
|
10
|
|
|
|
|
33
|
my @e = $self->_build_element; |
225
|
|
|
|
|
|
|
return join( '', |
226
|
10
|
|
50
|
|
|
43
|
map( { $_->as_XML } $self->_build_element( $self->element ) ) ) |
227
|
|
|
|
|
|
|
|| ''; |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head2 error |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Arguments: $error |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Return Value: $error |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head2 error_xml |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Return Value: $xml |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=cut |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
sub error_xml { |
243
|
4
|
|
|
4
|
1
|
39
|
my $self = shift; |
244
|
4
|
50
|
|
|
|
65
|
return $self->error ? $self->error->as_XML : ''; |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head2 javascript |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head2 js |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
Arguments: $javascript |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
Return Value: $javascript |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
L is an alias for L. |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head2 javascript_element |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
Return Value: $javascript_element |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
Returns javascript in a script L. |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=cut |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
sub javascript_element { |
266
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
267
|
2
|
|
|
|
|
12
|
my $script = HTML::Element->new( 'script', type => 'text/javascript' ); |
268
|
2
|
|
|
|
|
75
|
my $content = "\n\n"; |
269
|
2
|
|
|
|
|
21
|
my $literal = HTML::Element->new( '~literal', text => $content ); |
270
|
2
|
|
|
|
|
64
|
$script->push_content($literal); |
271
|
2
|
|
|
|
|
51
|
return $script; |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=head2 javascript_xml |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=head2 js_xml |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
Return Value: $javascript_xml |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
Returns javascript in a script block. |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
L is an alias for L. |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=cut |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
sub javascript_xml { |
287
|
2
|
|
|
2
|
1
|
1922
|
my $self = shift; |
288
|
2
|
|
|
|
|
20
|
return $self->javascript_element->as_HTML('<>&'); |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=head1 AUTHOR |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
Sebastian Riedel, C |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head1 LICENSE |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
298
|
|
|
|
|
|
|
the same terms as Perl itself. |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=cut |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
1; |