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