| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Data::HTML::Element::Option; |
|
2
|
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
210829
|
use strict; |
|
|
11
|
|
|
|
|
25
|
|
|
|
11
|
|
|
|
|
419
|
|
|
4
|
11
|
|
|
11
|
|
53
|
use warnings; |
|
|
11
|
|
|
|
|
23
|
|
|
|
11
|
|
|
|
|
748
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
11
|
|
|
11
|
|
5930
|
use Data::HTML::Element::Utils qw(check_data check_data_type); |
|
|
11
|
|
|
|
|
48
|
|
|
|
11
|
|
|
|
|
386
|
|
|
7
|
11
|
|
|
11
|
|
906
|
use Error::Pure qw(err); |
|
|
11
|
|
|
|
|
21
|
|
|
|
11
|
|
|
|
|
577
|
|
|
8
|
11
|
|
|
11
|
|
62
|
use List::Util 1.33 qw(none); |
|
|
11
|
|
|
|
|
159
|
|
|
|
11
|
|
|
|
|
1008
|
|
|
9
|
11
|
|
|
11
|
|
17049
|
use Mo qw(build is); |
|
|
11
|
|
|
|
|
10351
|
|
|
|
11
|
|
|
|
|
83
|
|
|
10
|
11
|
|
|
11
|
|
20844
|
use Mo::utils 0.26 qw(check_array check_bool check_number); |
|
|
11
|
|
|
|
|
231
|
|
|
|
11
|
|
|
|
|
919
|
|
|
11
|
11
|
|
|
11
|
|
5962
|
use Mo::utils::CSS 0.02 qw(check_css_class); |
|
|
11
|
|
|
|
|
132341
|
|
|
|
11
|
|
|
|
|
324
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.17; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has css_class => ( |
|
16
|
|
|
|
|
|
|
is => 'ro', |
|
17
|
|
|
|
|
|
|
); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has data => ( |
|
20
|
|
|
|
|
|
|
default => [], |
|
21
|
|
|
|
|
|
|
is => 'ro', |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has data_type => ( |
|
25
|
|
|
|
|
|
|
is => 'ro', |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has disabled => ( |
|
29
|
|
|
|
|
|
|
is => 'ro', |
|
30
|
|
|
|
|
|
|
); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has id => ( |
|
33
|
|
|
|
|
|
|
is => 'ro', |
|
34
|
|
|
|
|
|
|
); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has label => ( |
|
37
|
|
|
|
|
|
|
is => 'ro', |
|
38
|
|
|
|
|
|
|
); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has selected => ( |
|
41
|
|
|
|
|
|
|
is => 'ro', |
|
42
|
|
|
|
|
|
|
); |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
has value => ( |
|
45
|
|
|
|
|
|
|
is => 'ro', |
|
46
|
|
|
|
|
|
|
); |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub BUILD { |
|
49
|
29
|
|
|
29
|
0
|
2906084
|
my $self = shift; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Check CSS class. |
|
52
|
29
|
|
|
|
|
142
|
check_css_class($self, 'css_class'); |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Check data type. |
|
55
|
28
|
|
|
|
|
554
|
check_data_type($self); |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Check data based on type. |
|
58
|
27
|
|
|
|
|
120
|
check_data($self); |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Check disabled. |
|
61
|
24
|
100
|
|
|
|
83
|
if (! defined $self->{'disabled'}) { |
|
62
|
20
|
|
|
|
|
48
|
$self->{'disabled'} = 0; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
24
|
|
|
|
|
88
|
check_bool($self, 'disabled'); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Check selected. |
|
67
|
23
|
100
|
|
|
|
504
|
if (! defined $self->{'selected'}) { |
|
68
|
19
|
|
|
|
|
49
|
$self->{'selected'} = 0; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
23
|
|
|
|
|
66
|
check_bool($self, 'selected'); |
|
71
|
|
|
|
|
|
|
|
|
72
|
22
|
|
|
|
|
291
|
return; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__END__ |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=pod |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=encoding utf8 |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 NAME |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Data::HTML::Element::Option - Data object for HTML option element. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
use Data::HTML::Element::Option; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $obj = Data::HTML::Element::Option->new(%params); |
|
92
|
|
|
|
|
|
|
my $css_class = $obj->css_class; |
|
93
|
|
|
|
|
|
|
my $data = $obj->data; |
|
94
|
|
|
|
|
|
|
my $data_type = $obj->data_type; |
|
95
|
|
|
|
|
|
|
my $disabled = $obj->disabled; |
|
96
|
|
|
|
|
|
|
my $id = $obj->id; |
|
97
|
|
|
|
|
|
|
my $label = $obj->label; |
|
98
|
|
|
|
|
|
|
my $selected = $obj->selected; |
|
99
|
|
|
|
|
|
|
my $value = $obj->value; |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 METHODS |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 C<new> |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $obj = Data::HTML::Element::Option->new(%params); |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Constructor. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=over 8 |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item * C<css_class> |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Option CSS class. |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Default value is undef. |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item * C<data> |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Data content. It's reference to array. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Data type of data is described in 'data_type' parameter. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Default value is []. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item * C<data_type> |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Data type for content. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Possible value are: cb plain tags |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
The 'cb' content is code reference. |
|
132
|
|
|
|
|
|
|
The 'plain' content are string(s). |
|
133
|
|
|
|
|
|
|
The 'tags' content is structure described in L<Tags>. |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Default value is 'plain'. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item * C<disabled> |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Disabled flag. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Default value is 0. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item * C<id> |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Option identifier. |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Default value is undef. |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item * C<label> |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Option label. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Default value is undef. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item * C<selected> |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Selected flag. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Default value is 0. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item * C<value> |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Option value. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Default value is undef. |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=back |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Returns instance of object. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 C<css_class> |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
my $css_class = $obj->css_class; |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Get CSS class for option. |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Returns string. |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 C<data> |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
my $data = $obj->data; |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Get data inside option element. |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Returns reference to array. |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 C<data_type> |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
my $data_type = $obj->data_type; |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Get option data type. |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Returns string. |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 C<disabled> |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
my $disabled = $obj->disabled; |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Get option disabled flag. |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Returns bool value (1/0). |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head2 C<id> |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
my $id = $obj->id; |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Get option identifier. |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Returns string. |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head2 C<label> |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
my $label = $obj->label; |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
Get option label. |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Returns string. |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head2 C<selected> |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
my $selected = $obj->selected; |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Get selected flag. |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Returns bool value (1/0). |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head2 C<value> |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
my $value = $obj->value; |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Get option value. |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Returns string. |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head1 ERRORS |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
new(): |
|
238
|
|
|
|
|
|
|
Parameter 'css_class' has bad CSS class name. |
|
239
|
|
|
|
|
|
|
Value: %s |
|
240
|
|
|
|
|
|
|
Parameter 'css_class' has bad CSS class name (number on begin). |
|
241
|
|
|
|
|
|
|
Value: %s |
|
242
|
|
|
|
|
|
|
Parameter 'data' must be a array. |
|
243
|
|
|
|
|
|
|
Value: %s |
|
244
|
|
|
|
|
|
|
Reference: %s |
|
245
|
|
|
|
|
|
|
Parameter 'data' in 'plain' mode must contain reference to array with scalars. |
|
246
|
|
|
|
|
|
|
Parameter 'data' in 'tags' mode must contain reference to array with references to array with Tags structure. |
|
247
|
|
|
|
|
|
|
Parameter 'data_type' has bad value. |
|
248
|
|
|
|
|
|
|
Parameter 'disabled' must be a bool (0/1). |
|
249
|
|
|
|
|
|
|
Value: %s |
|
250
|
|
|
|
|
|
|
Parameter 'selected' must be a bool (0/1). |
|
251
|
|
|
|
|
|
|
Value: %s |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=head1 EXAMPLE |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=for comment filename=option.pl |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
use strict; |
|
258
|
|
|
|
|
|
|
use warnings; |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
use Data::HTML::Element::Option; |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
my $obj = Data::HTML::Element::Option->new( |
|
263
|
|
|
|
|
|
|
'css_class' => 'opt', |
|
264
|
|
|
|
|
|
|
'id' => 7, |
|
265
|
|
|
|
|
|
|
'label' => 'Audi', |
|
266
|
|
|
|
|
|
|
'selected' => 1, |
|
267
|
|
|
|
|
|
|
'value' => 'audi', |
|
268
|
|
|
|
|
|
|
); |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
# Print out. |
|
271
|
|
|
|
|
|
|
print 'Id: '.$obj->id."\n"; |
|
272
|
|
|
|
|
|
|
print 'CSS class: '.$obj->css_class."\n"; |
|
273
|
|
|
|
|
|
|
print 'Label: '.$obj->label."\n"; |
|
274
|
|
|
|
|
|
|
print 'Value: '.$obj->value."\n"; |
|
275
|
|
|
|
|
|
|
print 'Selected: '.$obj->selected."\n"; |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
# Output: |
|
278
|
|
|
|
|
|
|
# Id: 7 |
|
279
|
|
|
|
|
|
|
# CSS class: opt |
|
280
|
|
|
|
|
|
|
# Label: Audi |
|
281
|
|
|
|
|
|
|
# Value: audi |
|
282
|
|
|
|
|
|
|
# Selected: 1 |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
L<Data::HTML::Element::Utils>, |
|
287
|
|
|
|
|
|
|
L<Error::Pure>, |
|
288
|
|
|
|
|
|
|
L<List::Util>, |
|
289
|
|
|
|
|
|
|
L<Mo>, |
|
290
|
|
|
|
|
|
|
L<Mo::utils>, |
|
291
|
|
|
|
|
|
|
L<Mo::utils::CSS>. |
|
292
|
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=head1 REPOSITORY |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Data-HTML-Element> |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=head1 AUTHOR |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
|
300
|
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
L<http://skim.cz> |
|
302
|
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
304
|
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
© 2022-2024 Michal Josef Špaček |
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
BSD 2-Clause License |
|
308
|
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=head1 VERSION |
|
310
|
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
0.17 |
|
312
|
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=cut |