line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use base qw(Tags::HTML); |
3
|
10
|
|
|
10
|
|
153581
|
use strict; |
|
10
|
|
|
|
|
46
|
|
|
10
|
|
|
|
|
2834
|
|
4
|
10
|
|
|
10
|
|
98943
|
use warnings; |
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
188
|
|
5
|
10
|
|
|
10
|
|
45
|
|
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
283
|
|
6
|
|
|
|
|
|
|
use Class::Utils qw(set_params split_params); |
7
|
10
|
|
|
10
|
|
49
|
use Error::Pure qw(err); |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
452
|
|
8
|
10
|
|
|
10
|
|
58
|
use Scalar::Util qw(blessed); |
|
10
|
|
|
|
|
29
|
|
|
10
|
|
|
|
|
356
|
|
9
|
10
|
|
|
10
|
|
53
|
|
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
5058
|
|
10
|
|
|
|
|
|
|
our $VERSION = 0.06; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Process 'Tags'. |
13
|
|
|
|
|
|
|
my ($self, $input) = @_; |
14
|
|
|
|
|
|
|
|
15
|
5
|
|
|
5
|
|
6823
|
# Check input. |
16
|
|
|
|
|
|
|
if (! defined $input |
17
|
|
|
|
|
|
|
|| ! blessed($input) |
18
|
5
|
100
|
66
|
|
|
67
|
|| ! $input->isa('Data::HTML::Form::Input')) { |
|
|
|
66
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
err "Input object must be a 'Data::HTML::Form::Input' instance."; |
21
|
|
|
|
|
|
|
} |
22
|
1
|
|
|
|
|
5
|
|
23
|
|
|
|
|
|
|
$self->{'tags'}->put( |
24
|
|
|
|
|
|
|
['b', 'input'], |
25
|
4
|
50
|
|
|
|
31
|
defined $input->css_class ? ( |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
26
|
|
|
|
|
|
|
['a', 'class', $input->css_class], |
27
|
|
|
|
|
|
|
) : (), |
28
|
|
|
|
|
|
|
['a', 'type', $input->type], |
29
|
|
|
|
|
|
|
defined $input->id ? ( |
30
|
|
|
|
|
|
|
['a', 'name', $input->id], |
31
|
|
|
|
|
|
|
['a', 'id', $input->id], |
32
|
|
|
|
|
|
|
) : (), |
33
|
|
|
|
|
|
|
defined $input->value ? ( |
34
|
|
|
|
|
|
|
['a', 'value', $input->value], |
35
|
|
|
|
|
|
|
) : (), |
36
|
|
|
|
|
|
|
$input->checked ? ( |
37
|
|
|
|
|
|
|
['a', 'checked', 'checked'], |
38
|
|
|
|
|
|
|
) : (), |
39
|
|
|
|
|
|
|
defined $input->placeholder ? ( |
40
|
|
|
|
|
|
|
['a', 'placeholder', $input->placeholder], |
41
|
|
|
|
|
|
|
) : (), |
42
|
|
|
|
|
|
|
defined $input->size ? ( |
43
|
|
|
|
|
|
|
['a', 'size', $input->size], |
44
|
|
|
|
|
|
|
) : (), |
45
|
|
|
|
|
|
|
defined $input->readonly ? ( |
46
|
|
|
|
|
|
|
['a', 'readonly', 'readonly'], |
47
|
|
|
|
|
|
|
) : (), |
48
|
|
|
|
|
|
|
defined $input->disabled ? ( |
49
|
|
|
|
|
|
|
['a', 'disabled', 'disabled'], |
50
|
|
|
|
|
|
|
) : (), |
51
|
|
|
|
|
|
|
defined $input->min ? ( |
52
|
|
|
|
|
|
|
['a', 'min', $input->min], |
53
|
|
|
|
|
|
|
) : (), |
54
|
|
|
|
|
|
|
defined $input->max ? ( |
55
|
|
|
|
|
|
|
['a', 'max', $input->max], |
56
|
|
|
|
|
|
|
) : (), |
57
|
|
|
|
|
|
|
['e', 'input'], |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return; |
61
|
|
|
|
|
|
|
} |
62
|
4
|
|
|
|
|
761
|
|
63
|
|
|
|
|
|
|
my ($self, $input) = @_; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Check input. |
66
|
2
|
|
|
2
|
|
6075
|
if (! defined $input |
67
|
|
|
|
|
|
|
|| ! blessed($input) |
68
|
|
|
|
|
|
|
|| ! $input->isa('Data::HTML::Form::Input')) { |
69
|
2
|
50
|
33
|
|
|
31
|
|
|
|
|
33
|
|
|
|
|
70
|
|
|
|
|
|
|
err "Input object must be a 'Data::HTML::Form::Input' instance."; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
0
|
my $css_class = ''; |
74
|
|
|
|
|
|
|
if (defined $input->css_class) { |
75
|
|
|
|
|
|
|
$css_class = '.'.$input->css_class; |
76
|
2
|
|
|
|
|
6
|
} |
77
|
2
|
100
|
|
|
|
8
|
|
78
|
1
|
|
|
|
|
11
|
$self->{'css'}->put( |
79
|
|
|
|
|
|
|
['s', 'input'.$css_class.'[type=submit]:hover'], |
80
|
|
|
|
|
|
|
['d', 'background-color', '#45a049'], |
81
|
2
|
|
|
|
|
62
|
['e'], |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
['s', 'input'.$css_class.'[type=submit]'], |
84
|
|
|
|
|
|
|
['d', 'width', '100%'], |
85
|
|
|
|
|
|
|
['d', 'background-color', '#4CAF50'], |
86
|
|
|
|
|
|
|
['d', 'color', 'white'], |
87
|
|
|
|
|
|
|
['d', 'padding', '14px 20px'], |
88
|
|
|
|
|
|
|
['d', 'margin', '8px 0'], |
89
|
|
|
|
|
|
|
['d', 'border', 'none'], |
90
|
|
|
|
|
|
|
['d', 'border-radius', '4px'], |
91
|
|
|
|
|
|
|
['d', 'cursor', 'pointer'], |
92
|
|
|
|
|
|
|
['e'], |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
['s', 'input'.$css_class.'[type=submit][disabled=disabled]'], |
95
|
|
|
|
|
|
|
['d', 'background-color', '#888888'], |
96
|
|
|
|
|
|
|
['e'], |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
['s', 'input'.$css_class.'[type=text]'], |
99
|
|
|
|
|
|
|
['s', 'input'.$css_class.'[type=date]'], |
100
|
|
|
|
|
|
|
['s', 'input'.$css_class.'[type=number]'], |
101
|
|
|
|
|
|
|
['d', 'width', '100%'], |
102
|
|
|
|
|
|
|
['d', 'padding', '12px 20px'], |
103
|
|
|
|
|
|
|
['d', 'margin', '8px 0'], |
104
|
|
|
|
|
|
|
['d', 'display', 'inline-block'], |
105
|
|
|
|
|
|
|
['d', 'border', '1px solid #ccc'], |
106
|
|
|
|
|
|
|
['d', 'border-radius', '4px'], |
107
|
|
|
|
|
|
|
['d', 'box-sizing', 'border-box'], |
108
|
|
|
|
|
|
|
['e'], |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
return; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
2
|
|
|
|
|
1417
|
1; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=pod |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=encoding utf8 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 NAME |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Tags::HTML::Form::Input - Tags helper for form input element. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SYNOPSIS |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
use Tags::HTML::Form::Input; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my $obj = Tags::HTML::Form::Input->new(%params); |
130
|
|
|
|
|
|
|
$obj->process($input); |
131
|
|
|
|
|
|
|
$obj->process_css($input); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 METHODS |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 C<new> |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
my $obj = Tags::HTML::Form::Input->new(%params); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Constructor. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=over 8 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item * C<css> |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
'CSS::Struct::Output' object for L<process_css> processing. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Default value is undef. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item * C<tags> |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
'Tags::Output' object. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Default value is undef. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=back |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 C<process> |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
$obj->process($input); |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Process Tags structure for fields defined in C<@fields> to output. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Accepted C<$input> is L<Data::HTML::Form::Input>. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Returns undef. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 C<process_css> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
$obj->process_css($input); |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Process CSS::Struct structure for output. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Returns undef. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 ERRORS |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
new(): |
178
|
|
|
|
|
|
|
From Tags::HTML::new(): |
179
|
|
|
|
|
|
|
Parameter 'css' must be a 'CSS::Struct::Output::*' class. |
180
|
|
|
|
|
|
|
Parameter 'tags' must be a 'Tags::Output::*' class. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
process(): |
183
|
|
|
|
|
|
|
From Tags::HTML::process(): |
184
|
|
|
|
|
|
|
Parameter 'tags' isn't defined. |
185
|
|
|
|
|
|
|
Input object must be a 'Data::HTML::Form::Input' instance. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
process_css(): |
188
|
|
|
|
|
|
|
From Tags::HTML::process_css(): |
189
|
|
|
|
|
|
|
Parameter 'css' isn't defined. |
190
|
|
|
|
|
|
|
Input object must be a 'Data::HTML::Form::Input' instance. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 EXAMPLE |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=for comment filename=create_and_print_input.pl |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
use strict; |
197
|
|
|
|
|
|
|
use warnings; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
use CSS::Struct::Output::Indent; |
200
|
|
|
|
|
|
|
use Data::HTML::Form::Input; |
201
|
|
|
|
|
|
|
use Tags::HTML::Form::Input; |
202
|
|
|
|
|
|
|
use Tags::Output::Indent; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# Object. |
205
|
|
|
|
|
|
|
my $css = CSS::Struct::Output::Indent->new; |
206
|
|
|
|
|
|
|
my $tags = Tags::Output::Indent->new( |
207
|
|
|
|
|
|
|
'xml' => 1, |
208
|
|
|
|
|
|
|
); |
209
|
|
|
|
|
|
|
my $obj = Tags::HTML::Form::Input->new( |
210
|
|
|
|
|
|
|
'css' => $css, |
211
|
|
|
|
|
|
|
'tags' => $tags, |
212
|
|
|
|
|
|
|
); |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
# Data object for input. |
215
|
|
|
|
|
|
|
my $input = Data::HTML::Form::Input->new( |
216
|
|
|
|
|
|
|
'css_class' => 'form-input', |
217
|
|
|
|
|
|
|
); |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
# Process input. |
220
|
|
|
|
|
|
|
$obj->process($input); |
221
|
|
|
|
|
|
|
$obj->process_css($input); |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
# Print out. |
224
|
|
|
|
|
|
|
print "HTML:\n"; |
225
|
|
|
|
|
|
|
print $tags->flush; |
226
|
|
|
|
|
|
|
print "\n\n"; |
227
|
|
|
|
|
|
|
print "CSS:\n"; |
228
|
|
|
|
|
|
|
print $css->flush; |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
# Output: |
231
|
|
|
|
|
|
|
# HTML: |
232
|
|
|
|
|
|
|
# <input class="form-input" type="text" /> |
233
|
|
|
|
|
|
|
# |
234
|
|
|
|
|
|
|
# CSS: |
235
|
|
|
|
|
|
|
# input.form-input[type=submit]:hover { |
236
|
|
|
|
|
|
|
# background-color: #45a049; |
237
|
|
|
|
|
|
|
# } |
238
|
|
|
|
|
|
|
# input.form-input[type=submit] { |
239
|
|
|
|
|
|
|
# width: 100%; |
240
|
|
|
|
|
|
|
# background-color: #4CAF50; |
241
|
|
|
|
|
|
|
# color: white; |
242
|
|
|
|
|
|
|
# padding: 14px 20px; |
243
|
|
|
|
|
|
|
# margin: 8px 0; |
244
|
|
|
|
|
|
|
# border: none; |
245
|
|
|
|
|
|
|
# border-radius: 4px; |
246
|
|
|
|
|
|
|
# cursor: pointer; |
247
|
|
|
|
|
|
|
# } |
248
|
|
|
|
|
|
|
# input.form-input { |
249
|
|
|
|
|
|
|
# width: 100%; |
250
|
|
|
|
|
|
|
# padding: 12px 20px; |
251
|
|
|
|
|
|
|
# margin: 8px 0; |
252
|
|
|
|
|
|
|
# display: inline-block; |
253
|
|
|
|
|
|
|
# border: 1px solid #ccc; |
254
|
|
|
|
|
|
|
# border-radius: 4px; |
255
|
|
|
|
|
|
|
# box-sizing: border-box; |
256
|
|
|
|
|
|
|
# } |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
L<Class::Utils>, |
261
|
|
|
|
|
|
|
L<Error::Pure>, |
262
|
|
|
|
|
|
|
L<Scalar::Util>, |
263
|
|
|
|
|
|
|
L<Tags::HTML>. |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head1 REPOSITORY |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Tags-HTML-Form> |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=head1 AUTHOR |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
L<http://skim.cz> |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
© 2022 Michal Josef Špaček |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
BSD 2-Clause License |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=head1 VERSION |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
0.06 |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=cut |