lib/HTML/Object/Attribute.pm

filter: Statementstmt 100% 51 / 51 Branchbran 66.6% 4 / 6 Conditioncond 33.3% 9 / 27 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 100% 15 / 15 Podpod 100% 5 / 5 totaltotal 73.6% 84 / 114 CC 13 SCAR 25.2
CC
13
Cov
76%
init
26.5
value
2.0
BEGIN
1.0
CRAP 12.4
« blib/lib/HTML/Object/DOM/Text.pm ↑ Summary lib/HTML/Object/DOM/Declaration.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/Attribute.pm
3 ## Version v0.3.0
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/04/22
7 ## Modified 2025/10/16
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 11 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 11 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 11 ▶ warnings::register_categories( 'HTML::Object' );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 11 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 11 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 11 ▶ use HTML::Object::Literal;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 11 ▶ use HTML::Object::Number;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 11 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 11 our $VERSION = 'v0.3.0';
26 };
27  
28 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 sub init
32 {
33 31 ▶ my $self = shift( @_ );
Subroutine init: called CC=12 SCAR=32.8
Pod documented
34 31 my $name;
35 # HTML::Object::Attribute->new( 'id' );
36 # HTML::Object::Attribute( 'id', value => 'hello', element => $e );
37 # HTML::Object::Attribute( 'id', { value => 'hello', element => $e } );
38 31 ▶ if( ( scalar( @_ ) == 1 && ( !ref( $_[0] ) || overload::Method( $_[0], '""' ) ) ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and !ref($_[0]) || overload::Method($_[0], "\"\"") or @_ % 2 and !ref($_[0]) || overload::Method($_[0], "\"\"") or scalar @_ == 2 and !ref($_[0]) || overload::Method($_[0], "\"\"") and ref $_[1] eq "HASH") 0 30 30
Condition33%9/27
scalar @_ == 1 and !ref($_[0]) || overload::Method($_[0], "\"\"") or @_ % 2 and !ref($_[0]) || overload::Method($_[0], "\"\"") or scalar @_ == 2 and !ref($_[0]) || overload::Method($_[0], "\"\"") and ref $_[1] eq "HASH"
l!l&&r!l&&!r
1030
scalar @_ == 1 and !ref($_[0]) || overload::Method($_[0], "\"\"") or @_ % 2 and !ref($_[0]) || overload::Method($_[0], "\"\"")
l!l&&r!l&&!r
0031
scalar @_ == 1 and !ref($_[0]) || overload::Method($_[0], "\"\"")
!ll&&!rl&&r
3100
not ref $_[0] or overload::Method($_[0], "\"\"")
l!l&&r!l&&!r
000
@_ % 2 and !ref($_[0]) || overload::Method($_[0], "\"\"")
!ll&&!rl&&r
3010
not ref $_[0] or overload::Method($_[0], "\"\"")
l!l&&r!l&&!r
100
scalar @_ == 2 and !ref($_[0]) || overload::Method($_[0], "\"\"") and ref $_[1] eq "HASH"
!ll&&!rl&&r
3000
scalar @_ == 2 and !ref($_[0]) || overload::Method($_[0], "\"\"")
!ll&&!rl&&r
3000
not ref $_[0] or overload::Method($_[0], "\"\"")
l!l&&r!l&&!r
000
MC/DC0%0/10
scalar @_ == 1 and !ref($_[0]) || overload::Method($_[0], "\"\"") or @_ % 2 and !ref($_[0]) || overload::Method($_[0], "\"\"") or scalar @_ == 2 and !ref($_[0]) || overload::Method($_[0], "\"\"") and ref $_[1] eq "HASH"
scalar @_ == 1 not ref $_[0] overload::Method($_[0], "\"\"") @_ % 2 not ref $_[0] overload::Method($_[0], "\"\"") scalar @_ == 2 not ref $_[0] overload::Method($_[0], "\"\"") ref $_[1] eq "HASH"
Truth table3%1/30
A and not(B) or C or D and not(E) or F or G and not(H) or I and J
A= scalar @_ == 1B= not ref $_[0]C= overload::Method($_[0], "\"\"")D= @_ % 2E= not ref $_[0]F= overload::Method($_[0], "\"\"")G= scalar @_ == 2H= not ref $_[0]I= overload::Method($_[0], "\"\"")J= ref $_[1] eq "HASH"
ABCDEFGHIJresult
11XXXXXXXX1
101XXXXXXX1
0XX11XXXXX1
0XX101XXXX1
10011XXXXX1
100101XXXX1
0XX0XX11X11
0XX0XX10111
0XX10011X11
0XX10010111
1000XX11X11
1000XX10111
10010011X11
10010010111
0XX0XX0XXX0
0XX0XX100X0
0XX0XX11X00
0XX0XX10100
0XX1000XXX0
0XX100100X0
0XX10011X00
0XX10010100
1000XX0XXX0
1000XX100X0
1000XX11X00
1000XX10100
1001000XXX0
100100100X0
10010011X00
10010010100
39 ( ( @_ % 2 ) && ( !ref( $_[0] ) || overload::Method( $_[0], '""' ) ) ) ||
40 ( scalar( @_ ) == 2 && ( !ref( $_[0] ) || overload::Method( $_[0], '""' ) ) && ref( $_[1] ) eq 'HASH' ) )
41 {
42 1 $name = shift( @_ );
43 }
44 31 $self->{element} = '';
45 31 $self->{name} = $name;
46 31 $self->{rank} = '';
47 31 $self->{value} = '';
48 31 $self->{_init_strict_use_sub} = 1;
49 31 $self->{_exception_class} = 'HTML::Object::Exception';
50 31 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 31 31
51 31 return( $self );
52 }
53  
54 36 ▶sub element { return( shift->_set_get_object_without_init( 'element', 'HTML::Object::Element', @_ ) ); }
Subroutine element: called CC=1 SCAR=0.0
Pod documented
55  
56 56 ▶sub name { return( shift->_set_get_scalar_as_object( 'name', @_ ) ); }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
57  
58 26 ▶sub rank { return( shift->_set_get_number_as_object( 'rank', @_ ) ); }
Subroutine rank: called CC=1 SCAR=0.0
Pod documented
59  
60 # sub value { return( shift->_set_get_scalar_as_object( 'value', @_ ) ); }
61 sub value
62 {
63 76 ▶ my $self = shift( @_ );
Subroutine value: called CC=2 SCAR=6.9
Pod documented
64 76 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 31 45 76
65 {
66 31 my $v = shift( @_ );
67 31 $v =~ s/^[[:blank:]\h]+|[[:blank:]\h]+$//g;
68 31 return( $self->_set_get_scalar_as_object( 'value', $v ) );
69 }
70 45 return( $self->_set_get_scalar_as_object( 'value' ) );
71 }
72  
73  
74 11 1;
75 # NOTE: POD
76 __END__
77  
78 =encoding utf8
79  
80 =head1 NAME
81  
82 HTML::Object::Attribute - HTML Object Element Attribute Class
83  
84 =head1 SYNOPSIS
85  
86 use HTML::Object::Attribute;
87 my $attr = HTML::Object::Attribute->new( 'id' );
88 $attr->value = "hello";
89  
90 =head1 VERSION
91  
92 v0.3.0
93  
94 =head1 DESCRIPTION
95  
96 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>
97  
98 =head1 CONSTRUCTOR
99  
100 =head2 new
101  
102 Creates a new C<HTML::Object::Attribute> objects.
103  
104 It may also take an hash like arguments, that also are method of the same name.
105  
106 my $attr = HTML::Object::Attribute->new( 'id' );
107 # or
108 my $attr = HTML::Object::Attribute->new( name => 'id' );
109  
110 =head1 PROPERTIES
111  
112 =head2 nodeValue
113  
114 This returns or sets the value of the current node.
115  
116 For document, element or collection, this returns C<undef> and for attribute, text or comment, this returns the objct value.
117  
118 See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeValue>
119  
120 =head1 METHODS
121  
122 =head2 element
123  
124 Returns the L<HTML::Object::Element> object to which this attribute belongs.
125  
126 =head2 getAttributes
127  
128 Returns an L<array object|Module::Generic::Array> of the related element's attributes as L<HTML::Object::Attribute> objects.
129  
130 =head2 getLocalName
131  
132 Returns the attribute name.
133  
134 =head2 getName
135  
136 Returns the attribute name.
137  
138 =head2 getNextSibling
139  
140 Returns the next attribute object, or C<undef>.
141  
142 =head2 getParentNode
143  
144 Returns the parent L<HTML::Object::Element> object.
145  
146 =head2 getPreviousSibling
147  
148 Returns the previous attribute object, or C<undef>.
149  
150 =head2 getValue
151  
152 Returns the attribute value.
153  
154 =head2 isAttributeNode
155  
156 Always returns true.
157  
158 =head2 is_inside
159  
160 Provided with an L<HTML::Object::Element> and this will return true if this attribute is inside it, or false otherwise.
161  
162 =head2 lineage
163  
164 Add the parent element to our lineage. See L<HTML::Object::Element/lineage>
165  
166 =head2 localName
167  
168 Read-only.
169  
170 A string representing the local part of the qualified name of the attribute.
171  
172 This is the same as L</getName>, because this interface does not use xml C<prefix>
173  
174 See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Attr/localName>
175  
176 =head2 name
177  
178 Set or get the attribute name.
179  
180 Normally, under JavaScript, this is read-only, but under perl you can change it. Still be careful.
181  
182 See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Attr/name>
183  
184 =head2 namespaceURI
185  
186 Read-only
187  
188 A string representing the URI of the namespace of the attribute, or C<undef> if there is no namespace.
189  
190 This actually always return C<undef>, because this interface does not use xml C<prefix>
191  
192 See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Attr/namespaceURI>
193  
194 =head2 nodeValue
195  
196 This returns or sets the value of the current element.
197  
198 See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeValue>
199  
200 =head2 ownerElement
201  
202 Returns the L<element object|HTML::Object::Element> to which this attribute object belongs.
203  
204 See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Attr/ownerElement>
205  
206 =head2 prefix
207  
208 Read-only.
209  
210 This always return C<undef>, because this interface does not use xml C<prefix>
211  
212 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.
213  
214 See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Attr/prefix>
215  
216 =head2 rank
217  
218 Set or get the attribute rank. This returns a L<number object|Module::Generic::Number>
219  
220 =head2 string_value
221  
222 This is an alias for L</value>
223  
224 =head2 to_boolean
225  
226 Returns the attribute value as a L<boolean|Module::Generic::Boolean>
227  
228 =head2 to_literal
229  
230 Returns the attribute value as a L<litteral|HTML::Object::Litteral>
231  
232 =head2 to_number
233  
234 Returns the attribute value as a L<number|Module::Generic::Number>
235  
236 =head2 toString
237  
238 Returns a stringification of this attribute such as C<attribute="value">
239  
240 =head2 value
241  
242 Set or get the value of this attribute as a L<scalar object|Module::Generic::Scalar>. For example:
243  
244 $attr->value( "hello" );
245  
246 See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Attr/value>
247  
248 =head1 AUTHOR
249  
250 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
251  
252 =head1 SEE ALSO
253  
254 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>
255  
256 L<https://developer.mozilla.org/en-US/docs/Web/API/Attr>
257  
258 L<Mozilla reference|https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes>
259  
260 L<W3C standard on attributes|https://html.spec.whatwg.org/multipage/syntax.html#attributes-2>
261  
262 =head1 COPYRIGHT & LICENSE
263  
264 Copyright (c) 2021 DEGUEST Pte. Ltd.
265  
266 All rights reserved
267  
268 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
269  
270 =cut
« blib/lib/HTML/Object/DOM/Text.pm ↑ Summary lib/HTML/Object/DOM/Declaration.pm »