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