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