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