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.40067'; |
4
|
|
|
|
|
|
|
|
5
|
141
|
|
|
141
|
|
603
|
use Moose; |
|
141
|
|
|
|
|
206
|
|
|
141
|
|
|
|
|
849
|
|
6
|
|
|
|
|
|
|
with 'HTML::FormHandler::TraitFor::Types'; |
7
|
141
|
|
|
141
|
|
606854
|
use HTML::FormHandler::Render::Util ('process_attrs'); |
|
141
|
|
|
|
|
217
|
|
|
141
|
|
|
|
|
1103
|
|
8
|
141
|
|
|
141
|
|
21674
|
use HTML::FormHandler::Field; |
|
141
|
|
|
|
|
229
|
|
|
141
|
|
|
|
|
88150
|
|
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
|
16
|
|
|
16
|
0
|
10587
|
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
|
19
|
|
|
19
|
0
|
14482
|
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
|
18
|
|
|
18
|
0
|
8210
|
sub build_label_class { [] } |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
has 'render_list' => ( |
54
|
|
|
|
|
|
|
is => 'rw', |
55
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
56
|
|
|
|
|
|
|
traits => ['Array'], |
57
|
|
|
|
|
|
|
builder => 'build_render_list', |
58
|
|
|
|
|
|
|
handles => { |
59
|
|
|
|
|
|
|
has_render_list => 'count', |
60
|
|
|
|
|
|
|
add_to_render_list => 'push', |
61
|
|
|
|
|
|
|
all_render_list => 'elements', |
62
|
|
|
|
|
|
|
get_render_list => 'get', |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
); |
65
|
2
|
|
|
2
|
0
|
1067
|
sub build_render_list { [] } |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
has 'content' => ( is => 'rw' ); |
68
|
|
|
|
|
|
|
has 'after_plist' => ( is => 'rw' ); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub render { |
71
|
18
|
|
|
18
|
0
|
32
|
my ( $self, $result ) = @_; |
72
|
18
|
|
66
|
|
|
206
|
$result ||= $self->form->result; |
73
|
|
|
|
|
|
|
|
74
|
18
|
|
|
|
|
26
|
my $start_wrapper = ''; |
75
|
18
|
|
|
|
|
23
|
my $end_wrapper = ''; |
76
|
18
|
100
|
|
|
|
500
|
if( $self->wrapper ) { |
77
|
17
|
|
|
|
|
456
|
my $tag = $self->tag; |
78
|
|
|
|
|
|
|
# create attribute string |
79
|
17
|
|
|
|
|
53
|
my $attr_str = $self->render_attribute_string; |
80
|
17
|
|
|
|
|
38
|
$start_wrapper = qq{<$tag$attr_str>}; |
81
|
17
|
|
|
|
|
32
|
$end_wrapper = qq{</$tag>}; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# get rendering of contained fields, if any |
85
|
18
|
|
|
|
|
65
|
my $rendered_fb = $self->render_from_list($result); |
86
|
|
|
|
|
|
|
|
87
|
18
|
|
100
|
|
|
483
|
my $content = $self->content || ''; |
88
|
18
|
|
50
|
|
|
474
|
my $after_plist = $self->after_plist || ''; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# create label |
91
|
18
|
|
|
|
|
56
|
my $label = $self->render_label; |
92
|
18
|
|
|
|
|
126
|
my $block = qq{\n$start_wrapper$label$content$rendered_fb$after_plist$end_wrapper}; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub render_attribute_string { |
97
|
17
|
|
|
17
|
0
|
22
|
my $self = shift; |
98
|
17
|
|
|
|
|
21
|
my $attr = { %{ $self->attr } }; |
|
17
|
|
|
|
|
445
|
|
99
|
17
|
100
|
|
|
|
540
|
$attr->{class} = $self->class if $self->has_class; |
100
|
17
|
|
|
|
|
55
|
my $attr_str = process_attrs($attr); |
101
|
17
|
|
|
|
|
35
|
return $attr_str; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub render_label { |
105
|
18
|
|
|
18
|
0
|
22
|
my $self = shift; |
106
|
18
|
|
|
|
|
20
|
my $label = ''; |
107
|
18
|
100
|
|
|
|
510
|
if ( $self->has_label ) { |
108
|
9
|
|
100
|
|
|
242
|
my $label_tag = $self->label_tag || 'span'; |
109
|
9
|
100
|
|
|
|
219
|
$label_tag = 'legend' if lc $self->tag eq 'fieldset'; |
110
|
9
|
|
|
|
|
219
|
my $label_str = $self->form->_localize( $self->label ); |
111
|
9
|
|
|
|
|
15
|
my $attr_str = ''; |
112
|
9
|
100
|
|
|
|
379
|
$attr_str = process_attrs( { class => $self->label_class } ) if $self->has_label_class; |
113
|
9
|
|
|
|
|
32
|
$label = qq{<$label_tag$attr_str>$label_str</$label_tag>}; |
114
|
|
|
|
|
|
|
} |
115
|
18
|
|
|
|
|
32
|
return $label; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub render_from_list { |
119
|
18
|
|
|
18
|
0
|
61
|
my ( $self, $result ) = @_; |
120
|
|
|
|
|
|
|
|
121
|
18
|
|
|
|
|
29
|
my $output = ''; |
122
|
18
|
100
|
|
|
|
620
|
if ( $self->has_render_list ) { |
123
|
17
|
|
|
|
|
21
|
foreach my $fb ( @{ $self->render_list } ) { |
|
17
|
|
|
|
|
470
|
|
124
|
|
|
|
|
|
|
# it's a Field |
125
|
35
|
100
|
|
|
|
874
|
if ( $self->form->field_in_index($fb) ) { |
126
|
|
|
|
|
|
|
# find field result and use that |
127
|
33
|
|
|
|
|
136
|
my $fld_result = $result->get_result($fb); |
128
|
|
|
|
|
|
|
# if no result, then we shouldn't be rendering this field |
129
|
33
|
50
|
|
|
|
68
|
next unless $fld_result; |
130
|
33
|
|
|
|
|
93
|
$output .= $fld_result->render; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
# it's a Block |
133
|
|
|
|
|
|
|
else { |
134
|
|
|
|
|
|
|
# block can't be called from a field, so this should |
135
|
|
|
|
|
|
|
# always be the for result |
136
|
2
|
|
|
|
|
48
|
my $block = $self->form->block($fb); |
137
|
2
|
50
|
|
|
|
6
|
die "found no form field or block named '$fb'\n" unless $block; |
138
|
2
|
|
|
|
|
10
|
$output .= $block->render($result); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
# else nothing to render from render_list |
143
|
18
|
|
|
|
|
42
|
return $output; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
__END__ |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=pod |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=encoding UTF-8 |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 NAME |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
HTML::FormHandler::Widget::Block - base block renderer |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 VERSION |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
version 0.40067 |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 SYNOPSIS |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Base block renderer to be used with L<HTML::FormHandler::Blocks>. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
has_block 'my_fieldset' => ( tag => 'fieldset', |
167
|
|
|
|
|
|
|
render_list => ['bar'], label => 'My Special Bar' ); |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=over 4 |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item render_list |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
List of names of objects to render (fields and blocks) |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item tag |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
HTML tag for this block. Default 'div'. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=item class |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Arrayref of classes for the HTML element. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item attr |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Other attributes for the HTML element. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item label_tag |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Tag to use for the label. Default: 'span'; default for 'fieldset' is 'legend'. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item label_class |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Classes for the label. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=item label |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Label string. Will be localized. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=back |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 AUTHOR |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
FormHandler Contributors - see HTML::FormHandler |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Gerda Shank. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
212
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=cut |