line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
## HTML Object - ~/lib/HTML/Object/Attribute.pm |
3
|
|
|
|
|
|
|
## Version v0.2.0 |
4
|
|
|
|
|
|
|
## Copyright(c) 2021 DEGUEST Pte. Ltd. |
5
|
|
|
|
|
|
|
## Author: Jacques Deguest <jack@deguest.jp> |
6
|
|
|
|
|
|
|
## Created 2021/04/22 |
7
|
|
|
|
|
|
|
## Modified 2022/09/18 |
8
|
|
|
|
|
|
|
## All rights reserved |
9
|
|
|
|
|
|
|
## |
10
|
|
|
|
|
|
|
## |
11
|
|
|
|
|
|
|
## This program is free software; you can redistribute it and/or modify it |
12
|
|
|
|
|
|
|
## under the same terms as Perl itself. |
13
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
package HTML::Object::Attribute; |
15
|
|
|
|
|
|
|
BEGIN |
16
|
|
|
|
|
|
|
{ |
17
|
7
|
|
|
7
|
|
4701
|
use strict; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
481
|
|
18
|
7
|
|
|
7
|
|
40
|
use warnings; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
230
|
|
19
|
7
|
|
|
7
|
|
45
|
use parent qw( Module::Generic ); |
|
7
|
|
|
|
|
141
|
|
|
7
|
|
|
|
|
55
|
|
20
|
7
|
|
|
7
|
|
558
|
use vars qw( $VERSION ); |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
387
|
|
21
|
7
|
|
|
7
|
|
2765
|
use HTML::Object::Literal; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
225
|
|
22
|
7
|
|
|
7
|
|
2717
|
use HTML::Object::Number; |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
92
|
|
23
|
7
|
|
|
7
|
|
2485
|
use Want; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
435
|
|
24
|
7
|
|
|
7
|
|
124
|
our $VERSION = 'v0.2.0'; |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
|
27
|
7
|
|
|
7
|
|
36
|
use strict; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
150
|
|
28
|
7
|
|
|
7
|
|
31
|
use warnings; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
2542
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub init |
31
|
|
|
|
|
|
|
{ |
32
|
37
|
|
|
37
|
1
|
88
|
my $self = shift( @_ ); |
33
|
37
|
|
|
|
|
67
|
my $name; |
34
|
|
|
|
|
|
|
# HTML::Object::Attribute->new( 'id' ); |
35
|
|
|
|
|
|
|
# HTML::Object::Attribute( 'id', value => 'hello', element => $e ); |
36
|
|
|
|
|
|
|
# HTML::Object::Attribute( 'id', { value => 'hello', element => $e } ); |
37
|
37
|
0
|
33
|
|
|
471
|
if( ( scalar( @_ ) == 1 && ( !ref( $_[0] ) || overload::Method( $_[0], '""' ) ) ) || |
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
66
|
|
|
|
|
38
|
|
|
|
|
|
|
( ( @_ % 2 ) && ( !ref( $_[0] ) || overload::Method( $_[0], '""' ) ) ) || |
39
|
|
|
|
|
|
|
( scalar( @_ ) == 2 && ( !ref( $_[0] ) || overload::Method( $_[0], '""' ) ) && ref( $_[1] ) eq 'HASH' ) ) |
40
|
|
|
|
|
|
|
{ |
41
|
1
|
|
|
|
|
2
|
$name = shift( @_ ); |
42
|
|
|
|
|
|
|
} |
43
|
37
|
|
|
|
|
880
|
$self->{element} = ''; |
44
|
37
|
|
|
|
|
89
|
$self->{name} = $name; |
45
|
37
|
|
|
|
|
92
|
$self->{rank} = ''; |
46
|
37
|
|
|
|
|
84
|
$self->{value} = ''; |
47
|
37
|
|
|
|
|
80
|
$self->{_init_strict_use_sub} = 1; |
48
|
37
|
|
|
|
|
81
|
$self->{_exception_class} = 'HTML::Object::Exception'; |
49
|
37
|
50
|
|
|
|
184
|
$self->SUPER::init( @_ ) || return( $self->pass_error ); |
50
|
37
|
|
|
|
|
111011
|
return( $self ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
42
|
|
|
42
|
1
|
32459
|
sub element { return( shift->_set_get_object_without_init( 'element', 'HTML::Object::Element', @_ ) ); } |
54
|
|
|
|
|
|
|
|
55
|
68
|
|
|
68
|
1
|
170949
|
sub name { return( shift->_set_get_scalar_as_object( 'name', @_ ) ); } |
56
|
|
|
|
|
|
|
|
57
|
32
|
|
|
32
|
1
|
4391
|
sub rank { return( shift->_set_get_number_as_object( 'rank', @_ ) ); } |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# sub value { return( shift->_set_get_scalar_as_object( 'value', @_ ) ); } |
60
|
|
|
|
|
|
|
sub value |
61
|
|
|
|
|
|
|
{ |
62
|
52
|
|
|
52
|
1
|
997455
|
my $self = shift( @_ ); |
63
|
52
|
100
|
|
|
|
164
|
if( @_ ) |
64
|
|
|
|
|
|
|
{ |
65
|
37
|
|
|
|
|
83
|
my $v = shift( @_ ); |
66
|
37
|
|
|
|
|
198
|
$v =~ s/^[[:blank:]\h]+|[[:blank:]\h]+$//g; |
67
|
37
|
|
|
|
|
153
|
return( $self->_set_get_scalar_as_object( 'value', $v ) ); |
68
|
|
|
|
|
|
|
} |
69
|
15
|
|
|
|
|
68
|
return( $self->_set_get_scalar_as_object( 'value' ) ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
# NOTE: POD |
75
|
|
|
|
|
|
|
__END__ |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=encoding utf8 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 NAME |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
HTML::Object::Attribute - HTML Object Element Attribute Class |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 SYNOPSIS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
use HTML::Object::Attribute; |
86
|
|
|
|
|
|
|
my $attr = HTML::Object::Attribute->new( 'id' ); |
87
|
|
|
|
|
|
|
$attr->value = "hello"; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 VERSION |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
v0.2.0 |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 DESCRIPTION |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This class represent an element attribute. it is used as part of L<HTML::Object>, and also contains methods to interface with L<HTML::Object::XPath> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 new |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Creates a new C<HTML::Object::Attribute> objects. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
It may also take an hash like arguments, that also are method of the same name. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $attr = HTML::Object::Attribute->new( 'id' ); |
106
|
|
|
|
|
|
|
# or |
107
|
|
|
|
|
|
|
my $attr = HTML::Object::Attribute->new( name => 'id' ); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 PROPERTIES |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 nodeValue |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This returns or sets the value of the current node. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
For document, element or collection, this returns C<undef> and for attribute, text or comment, this returns the objct value. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeValue> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 METHODS |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 element |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Returns the L<HTML::Object::Element> object to which this attribute belongs. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 getAttributes |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Returns an L<array object|Module::Generic::Array> of the related element's attributes as L<HTML::Object::Attribute> objects. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 getLocalName |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Returns the attribute name. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 getName |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Returns the attribute name. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 getNextSibling |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Returns the next attribute object, or C<undef>. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 getParentNode |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Returns the parent L<HTML::Object::Element> object. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 getPreviousSibling |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Returns the previous attribute object, or C<undef>. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 getValue |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Returns the attribute value. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 isAttributeNode |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Always returns true. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 is_inside |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Provided with an L<HTML::Object::Element> and this will return true if this attribute is inside it, or false otherwise. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 lineage |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Add the parent element to our lineage. See L<HTML::Object::Element/lineage> |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 localName |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Read-only. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
A string representing the local part of the qualified name of the attribute. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This is the same as L</getName>, because this interface does not use xml C<prefix> |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Attr/localName> |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 name |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Set or get the attribute name. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Normally, under JavaScript, this is read-only, but under perl you can change it. Still be careful. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Attr/name> |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head2 namespaceURI |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Read-only |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
A string representing the URI of the namespace of the attribute, or C<undef> if there is no namespace. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
This actually always return C<undef>, because this interface does not use xml C<prefix> |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Attr/namespaceURI> |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 nodeValue |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
This returns or sets the value of the current element. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeValue> |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head2 ownerElement |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Returns the L<element object|HTML::Object::Element> to which this attribute object belongs. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Attr/ownerElement> |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head2 prefix |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Read-only. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
This always return C<undef>, because this interface does not use xml C<prefix> |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Normally, under JavaScript, this would return a string representing the namespace prefix of the attribute, or c<undef> if a namespace without prefix or no namespace are specified. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Attr/prefix> |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head2 rank |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Set or get the attribute rank. This returns a L<number object|Module::Generic::Number> |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head2 string_value |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
This is an alias for L</value> |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head2 to_boolean |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Returns the attribute value as a L<boolean|Module::Generic::Boolean> |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head2 to_literal |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Returns the attribute value as a L<litteral|HTML::Object::Litteral> |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head2 to_number |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Returns the attribute value as a L<number|Module::Generic::Number> |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head2 toString |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Returns a stringification of this attribute such as C<attribute="value"> |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head2 value |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Set or get the value of this attribute as a L<scalar object|Module::Generic::Scalar>. For example: |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
$attr->value( "hello" ); |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Attr/value> |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head1 AUTHOR |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head1 SEE ALSO |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
L<HTML::Object>, L<HTML::Object::Attribute>, L<HTML::Object::Boolean>, L<HTML::Object::Closing>, L<HTML::Object::Collection>, L<HTML::Object::Comment>, L<HTML::Object::Declaration>, L<HTML::Object::Document>, L<HTML::Object::Element>, L<HTML::Object::Exception>, L<HTML::Object::Literal>, L<HTML::Object::Number>, L<HTML::Object::Root>, L<HTML::Object::Space>, L<HTML::Object::Text>, L<HTML::Object::XQuery> |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
L<https://developer.mozilla.org/en-US/docs/Web/API/Attr> |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
L<Mozilla reference|https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes> |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
L<W3C standard on attributes|https://html.spec.whatwg.org/multipage/syntax.html#attributes-2> |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
Copyright (c) 2021 DEGUEST Pte. Ltd. |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
All rights reserved |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=cut |