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