line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormHandler::Widget::Block; |
2
|
|
|
|
|
|
|
# ABSTRACT: base block renderer |
3
|
|
|
|
|
|
|
$HTML::FormHandler::Widget::Block::VERSION = '0.40068'; |
4
|
|
|
|
|
|
|
|
5
|
143
|
|
|
143
|
|
1038
|
use Moose; |
|
143
|
|
|
|
|
409
|
|
|
143
|
|
|
|
|
1134
|
|
6
|
|
|
|
|
|
|
with 'HTML::FormHandler::TraitFor::Types'; |
7
|
143
|
|
|
143
|
|
973433
|
use HTML::FormHandler::Render::Util ('process_attrs'); |
|
143
|
|
|
|
|
417
|
|
|
143
|
|
|
|
|
1371
|
|
8
|
143
|
|
|
143
|
|
34234
|
use HTML::FormHandler::Field; |
|
143
|
|
|
|
|
379
|
|
|
143
|
|
|
|
|
118416
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'name' => ( is => 'ro', isa => 'Str', required => 1 ); |
11
|
|
|
|
|
|
|
has 'form' => ( is => 'ro', isa => 'HTML::FormHandler', required => 1, |
12
|
|
|
|
|
|
|
weak_ref => 1, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'class' => ( |
16
|
|
|
|
|
|
|
is => 'rw', |
17
|
|
|
|
|
|
|
isa => 'HFH::ArrayRefStr', |
18
|
|
|
|
|
|
|
traits => ['Array'], |
19
|
|
|
|
|
|
|
builder => 'build_class', |
20
|
|
|
|
|
|
|
handles => { |
21
|
|
|
|
|
|
|
has_class => 'count', |
22
|
|
|
|
|
|
|
add_class => 'push', |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
); |
25
|
18
|
|
|
18
|
0
|
15697
|
sub build_class { [] } |
26
|
|
|
|
|
|
|
has 'attr' => ( |
27
|
|
|
|
|
|
|
is => 'rw', |
28
|
|
|
|
|
|
|
traits => ['Hash'], |
29
|
|
|
|
|
|
|
builder => 'build_attr', |
30
|
|
|
|
|
|
|
handles => { |
31
|
|
|
|
|
|
|
has_attr => 'count', |
32
|
|
|
|
|
|
|
set__attr => 'set', |
33
|
|
|
|
|
|
|
delete__attr => 'delete' |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
); |
36
|
21
|
|
|
21
|
0
|
16871
|
sub build_attr { {} } |
37
|
|
|
|
|
|
|
has 'wrapper' => ( is => 'rw', isa => 'Bool', default => 1 ); |
38
|
|
|
|
|
|
|
has 'tag' => ( is => 'rw', isa => 'Str', default => 'div' ); |
39
|
|
|
|
|
|
|
has 'label' => ( is => 'rw', isa => 'Str', predicate => 'has_label' ); |
40
|
|
|
|
|
|
|
has 'label_tag' => ( is => 'rw', isa => 'Str' ); |
41
|
|
|
|
|
|
|
has 'label_class' => ( |
42
|
|
|
|
|
|
|
is => 'rw', |
43
|
|
|
|
|
|
|
isa => 'HFH::ArrayRefStr', |
44
|
|
|
|
|
|
|
traits => ['Array'], |
45
|
|
|
|
|
|
|
builder => 'build_label_class', |
46
|
|
|
|
|
|
|
handles => { |
47
|
|
|
|
|
|
|
has_label_class => 'count', |
48
|
|
|
|
|
|
|
add_label_class => 'push', |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
); |
51
|
20
|
|
|
20
|
0
|
11994
|
sub build_label_class { [] } |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
has 'render_list' => ( |
54
|
|
|
|
|
|
|
is => 'rw', |
55
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
56
|
|
|
|
|
|
|
lazy => 1, |
57
|
|
|
|
|
|
|
traits => ['Array'], |
58
|
|
|
|
|
|
|
builder => 'build_render_list', |
59
|
|
|
|
|
|
|
handles => { |
60
|
|
|
|
|
|
|
has_render_list => 'count', |
61
|
|
|
|
|
|
|
add_to_render_list => 'push', |
62
|
|
|
|
|
|
|
all_render_list => 'elements', |
63
|
|
|
|
|
|
|
get_render_list => 'get', |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
has 'build_render_list_method' => ( |
68
|
|
|
|
|
|
|
is => 'rw', |
69
|
|
|
|
|
|
|
isa => 'CodeRef', |
70
|
|
|
|
|
|
|
traits => ['Code'], |
71
|
|
|
|
|
|
|
handles => {'build_render_list' => 'execute_method'}, |
72
|
|
|
|
|
|
|
default => sub { \&default_build_render_list }, |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
1
|
0
|
32
|
sub default_build_render_list { [] } |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
has 'content' => ( is => 'rw' ); |
78
|
|
|
|
|
|
|
has 'after_plist' => ( is => 'rw' ); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub render { |
81
|
19
|
|
|
19
|
0
|
54
|
my ( $self, $result ) = @_; |
82
|
19
|
|
66
|
|
|
237
|
$result ||= $self->form->result; |
83
|
|
|
|
|
|
|
|
84
|
19
|
|
|
|
|
44
|
my $start_wrapper = ''; |
85
|
19
|
|
|
|
|
47
|
my $end_wrapper = ''; |
86
|
19
|
100
|
|
|
|
536
|
if( $self->wrapper ) { |
87
|
18
|
|
|
|
|
480
|
my $tag = $self->tag; |
88
|
|
|
|
|
|
|
# create attribute string |
89
|
18
|
|
|
|
|
75
|
my $attr_str = $self->render_attribute_string; |
90
|
18
|
|
|
|
|
63
|
$start_wrapper = qq{<$tag$attr_str>}; |
91
|
18
|
|
|
|
|
56
|
$end_wrapper = qq{</$tag>}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# get rendering of contained fields, if any |
95
|
19
|
|
|
|
|
80
|
my $rendered_fb = $self->render_from_list($result); |
96
|
|
|
|
|
|
|
|
97
|
19
|
|
100
|
|
|
573
|
my $content = $self->content || ''; |
98
|
19
|
|
50
|
|
|
569
|
my $after_plist = $self->after_plist || ''; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# create label |
101
|
19
|
|
|
|
|
83
|
my $label = $self->render_label; |
102
|
19
|
|
|
|
|
148
|
my $block = qq{\n$start_wrapper$label$content$rendered_fb$after_plist$end_wrapper}; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub render_attribute_string { |
107
|
18
|
|
|
18
|
0
|
46
|
my $self = shift; |
108
|
18
|
|
|
|
|
44
|
my $attr = { %{ $self->attr } }; |
|
18
|
|
|
|
|
521
|
|
109
|
18
|
100
|
|
|
|
616
|
$attr->{class} = $self->class if $self->has_class; |
110
|
18
|
|
|
|
|
84
|
my $attr_str = process_attrs($attr); |
111
|
18
|
|
|
|
|
62
|
return $attr_str; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub render_label { |
115
|
19
|
|
|
19
|
0
|
44
|
my $self = shift; |
116
|
19
|
|
|
|
|
39
|
my $label = ''; |
117
|
19
|
100
|
|
|
|
587
|
if ( $self->has_label ) { |
118
|
10
|
|
100
|
|
|
278
|
my $label_tag = $self->label_tag || 'span'; |
119
|
10
|
100
|
|
|
|
271
|
$label_tag = 'legend' if lc $self->tag eq 'fieldset'; |
120
|
10
|
|
|
|
|
327
|
my $label_str = $self->form->_localize( $self->label ); |
121
|
10
|
|
|
|
|
27
|
my $attr_str = ''; |
122
|
10
|
100
|
|
|
|
386
|
$attr_str = process_attrs( { class => $self->label_class } ) if $self->has_label_class; |
123
|
10
|
|
|
|
|
47
|
$label = qq{<$label_tag$attr_str>$label_str</$label_tag>}; |
124
|
|
|
|
|
|
|
} |
125
|
19
|
|
|
|
|
56
|
return $label; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub render_from_list { |
129
|
19
|
|
|
19
|
0
|
84
|
my ( $self, $result ) = @_; |
130
|
|
|
|
|
|
|
|
131
|
19
|
|
|
|
|
42
|
my $output = ''; |
132
|
19
|
100
|
|
|
|
698
|
if ( $self->has_render_list ) { |
133
|
18
|
|
|
|
|
46
|
foreach my $fb ( @{ $self->render_list } ) { |
|
18
|
|
|
|
|
528
|
|
134
|
|
|
|
|
|
|
# it's a Field |
135
|
36
|
100
|
|
|
|
981
|
if ( $self->form->field_in_index($fb) ) { |
136
|
|
|
|
|
|
|
# find field result and use that |
137
|
34
|
|
|
|
|
163
|
my $fld_result = $result->get_result($fb); |
138
|
|
|
|
|
|
|
# if no result, then we shouldn't be rendering this field |
139
|
34
|
50
|
|
|
|
110
|
next unless $fld_result; |
140
|
34
|
|
|
|
|
141
|
$output .= $fld_result->render; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
# it's a Block |
143
|
|
|
|
|
|
|
else { |
144
|
|
|
|
|
|
|
# block can't be called from a field, so this should |
145
|
|
|
|
|
|
|
# always be the for result |
146
|
2
|
|
|
|
|
50
|
my $block = $self->form->block($fb); |
147
|
2
|
50
|
|
|
|
10
|
die "found no form field or block named '$fb'\n" unless $block; |
148
|
2
|
|
|
|
|
11
|
$output .= $block->render($result); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
# else nothing to render from render_list |
153
|
19
|
|
|
|
|
77
|
return $output; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
1; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
__END__ |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=pod |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=encoding UTF-8 |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 NAME |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
HTML::FormHandler::Widget::Block - base block renderer |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 VERSION |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
version 0.40068 |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 SYNOPSIS |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Base block renderer to be used with L<HTML::FormHandler::Blocks>. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
has_block 'my_fieldset' => ( tag => 'fieldset', |
177
|
|
|
|
|
|
|
render_list => ['bar'], label => 'My Special Bar' ); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=over 4 |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item render_list |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
List of names of objects to render (fields and blocks) |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item build_render_list_method |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Coderef for constructing the list of names of objects to render (fields and blocks) |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item tag |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
HTML tag for this block. Default 'div'. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item class |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Arrayref of classes for the HTML element. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item attr |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Other attributes for the HTML element. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item label_tag |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Tag to use for the label. Default: 'span'; default for 'fieldset' is 'legend'. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item label_class |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Classes for the label. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item label |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Label string. Will be localized. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=back |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head1 AUTHOR |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
FormHandler Contributors - see HTML::FormHandler |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Gerda Shank. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
226
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=cut |