lib/HTML/Object/DOM/Document.pm

filter: Statementstmt 49.1% 233 / 474 Branchbran 26.5% 44 / 166 Conditioncond 33.0% 41 / 124 MC/DCmcdc 10.1% 7 / 69 Subroutinesub 48.9% 72 / 147 Podpod 100% 121 / 121 totaltotal 47.0% 518 / 1101 CC 145 SCAR 30.8
CC
145
Cov
42%
_set_get_on_signal
210.0
replaceChildren
90.0
__ANON__
42.0
CRAP 21.8
« lib/HTML/Object/DOM/Implementation.pm ↑ Summary lib/HTML/Object/DOM/NodeIteratorShared.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Document.pm
3 ## Version v0.3.0
4 ## Copyright(c) 2024 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/13
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::DOM::Document;
15 BEGIN
16 {
17 32 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 32 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 32 ▶ warnings::register_categories( 'HTML::Object' );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 32 ▶ use parent qw( HTML::Object::Document HTML::Object::DOM::Element );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 32 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 32 ▶ use HTML::Object::ErrorEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 32 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 32 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 32 our $VERSION = 'v0.3.0';
26 };
27  
28 32 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 32 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 sub init
32 {
33 74 ▶ my $self = shift( @_ );
Subroutine init: called CC=2 SCAR=6.9
Pod documented
34 74 $self->{_init_strict_use_sub} = 1;
35 74 ▶ $self->HTML::Object::Document::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->HTML::Object::Document::init(@_) or return $self->pass_error 0 74 74
36 74 $self->{onload} = undef;
37 74 $self->{onreadystatechange} = undef;
38 74 $self->{visibilitystate} = 'visible';
39 74 $self->{_xpath_eval} = undef;
40 # Nodes are special in the document. In other elements, nodes are the same as children
41 # But here no. There can be only 1 element: html, but one can add a doctype or comments
42 # comments added will be part of the children, but not the doctype. So
43 # $doc->children is always equal to 1, but
44 # $doc->childNodes->length would be equal to 2 (including the doctype)
45 # So our real array is nodes, i.e. what would otherwise be children for other elements
46 # $self->{nodes} is automatically created by the read-only method 'nodes'
47 # State of the document for document->open(), document->close()
48 74 $self->{_closed} = 1;
49 74 return( $self );
50 }
51  
52 1 ▶sub activeElement : lvalue { return( shift->_set_get_object_lvalue( 'activeelement', 'HTML::Object::DOM::Element', @_ ) ); }
Subroutine activeElement: called CC=1 SCAR=0.0
Pod documented
53  
54 sub adoptNode
55 {
56 0 ▶ my $self = shift( @_ );
Subroutine adoptNode: not called CC=5 SCAR=34.0
Pod documented
57 0 ▶ my $elem = shift( @_ ) || return( $self->error( "No element object was provided to adopt into our document." ) );
Condition0%0/2
shift @_ || (return $self->error('No element object was provided to adopt into our document.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No element object was provided to adopt into our document.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
58 0 ▶ return( $self->error( "Element provided ($elem) is not a HTML::Object::Element object." ) ) if( !$self->_is_a( $elem, 'HTML::Object::Element' ) || $self->_is_a( $elem, 'HTML::Object::Collection' ) );
Branch: 1 branch
BranchTrueFalseTotal
if not $self->_is_a($elem, "HTML::Object::Element") or $self->_is_a($elem, "HTML::Object::Collection") 0 0 0
Condition0%0/3
not $self->_is_a($elem, "HTML::Object::Element") or $self->_is_a($elem, "HTML::Object::Collection")
l!l&&r!l&&!r
000
MC/DC0%0/2
not $self->_is_a($elem, "HTML::Object::Element") or $self->_is_a($elem, "HTML::Object::Collection")
not $self->_is_a($elem, "HTML::Object::Element") $self->_is_a($elem, "HTML::Object::Collection")
Truth table0%0/3
not(A) or B
A= not $self->_is_a($elem, "HTML::Object::Element")B= $self->_is_a($elem, "HTML::Object::Collection")
ABresult
1X1
011
000
59 0 ▶ if( $elem->parent )
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->parent) 0 0 0
60 {
61 0 $elem->detach;
62 }
63 0 return( $elem );
64 }
65  
66 # Note: method append is different from HTML::Object::DOM::Element because we need to check what goes in
67 sub append
68 {
69 0 ▶ my $self = shift( @_ );
Subroutine append: not called CC=4 SCAR=30.0
Pod documented
70 0 ▶ return( $self ) if( !scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 0 0 0
71 # If a HTML::Object::DOM::DocumentFragment object is provided, its children are
72 # copied to the list and its own children array is emptied.
73 0 ▶ my $list = $self->_check_list_of_nodes_or_text( @_ ) || return( $self->pass_error );
Condition0%0/2
$self->_check_list_of_nodes_or_text(@_) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_check_list_of_nodes_or_text(@_) || (return $self->pass_error)
$self->_check_list_of_nodes_or_text(@_)
Truth table0%0/2
A
A= $self->_check_list_of_nodes_or_text(@_)
Aresult
11
00
74 0 my $nodes = $self->nodes;
75 0 ▶ $self->reset(1) if( !$list->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
unless $list->is_empty 0 0 0
76 $list->foreach(sub
77 {
78 0 ▶ $_->parent( $self );
Subroutine __ANON__: not called CC=1 SCAR=6.9
79 0 });
80 0 $nodes->push( $list->list );
81 0 return( $self );
82 }
83  
84 # Node: method appendChild is inherited
85  
86 sub as_string
87 {
88 7 ▶ my $self = shift( @_ );
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
89 7 my $a = $self->new_array;
90 $self->nodes->foreach(sub
91 {
92 35 ▶ my $e = shift( @_ );
Subroutine __ANON__: called CC=2 SCAR=7.1
93 35 my $v = $e->as_string;
94 35 ▶ $a->push( defined( $v ) ? $v->scalar : $v );
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 35 0 35
95 7 });
96 7 return( $a->join( '' ) );
97 }
98  
99 sub body : lvalue { return( shift->_set_get_callback({
100 get => sub
101 {
102 18 ▶ my $self = shift( @_ );
Subroutine __ANON__: called CC=4 SCAR=13.9
103 18 ▶ my $html = $self->documentElement ||
Condition50%1/2
$self->documentElement || die('Unable to find a top HTML tag')
l!l
180
MC/DC0%0/1
$self->documentElement || die('Unable to find a top HTML tag')
$self->documentElement
Truth table50%1/2
A
A= $self->documentElement
Aresult
11
00
104 die( "Unable to find a top HTML tag" );
105 18 my $children = $html->children;
106 18 my $body;
107 18 foreach( @$children )
108 {
109 72 ▶ if( $_->tag eq 'body' )
Branch: 1 branch
BranchTrueFalseTotal
if ($_->tag eq "body") 18 54 72
110 {
111 18 $body = $_;
112 # End loop
113 18 last;
114 }
115 }
116 # $body may be undef, and that's ok. A Module::Generic::Null object will be returned instead
117 18 return( $body );
118 },
119 set => sub
120 {
121 0 ▶ my $self = shift( @_ );
Subroutine __ANON__: not called CC=6 SCAR=37.4
122 0 my $e = shift( @_ );
123 0 ▶ my $html = $self->documentElement ||
Condition0%0/2
$self->documentElement || die('Unable to find a top HTML tag')
l!l
00
MC/DC0%0/1
$self->documentElement || die('Unable to find a top HTML tag')
$self->documentElement
Truth table0%0/2
A
A= $self->documentElement
Aresult
11
00
124 die( "Unable to find a top HTML tag" );
125 0 my $children = $html->children;
126 0 ▶ if( !$self->_is_a( $e, 'HTML::Object::Element' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($e, "HTML::Object::Element")) 0 0 0
127 {
128 0 die( "Element provided to set as new body element is not a HTML::Object::Element object." );
129 }
130
131 0 my $body;
132 0 ▶ for( my $pos = 0; $pos < scalar( @$children ); $pos++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < scalar @$children) 0 0 0
133 {
134 0 my $child = $children->[$pos];
135 0 ▶ if( $child->tag eq 'body' )
Branch: 1 branch
BranchTrueFalseTotal
if ($child->tag eq "body") 0 0 0
136 {
137 0 $body = $child;
138 0 $children->offset( $pos, 1, $e );
139 # End loop
140 0 last;
141 }
142 }
143
144 # No body was found, amazingly enough; add it now
145 0 ▶ if( !defined( $body ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $body) 0 0 0
146 {
147 0 $children->push( $e );
148 }
149 0 return( $e );
150 }
151 18 ▶}, @_ ) ); }
Subroutine body: called CC=1 SCAR=0.0
Pod documented
152  
153 0 ▶sub captureEvents { return( shift->defaultView->captureEvents( @_ ) ); }
Subroutine captureEvents: not called CC=1 SCAR=6.9
Pod documented
154  
155 1 ▶sub caretPositionFromPoint { return; }
Subroutine caretPositionFromPoint: called CC=1 SCAR=0.0
Pod documented
156  
157 0 ▶sub caretRangeFromPoint { return; }
Subroutine caretRangeFromPoint: not called CC=1 SCAR=6.9
Pod documented
158  
159 # read-only
160 # e.g.:
161 # <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
162 # <meta charset="utf-8" />
163 sub characterSet : lvalue
164 {
165 2 ▶ my $self = shift( @_ );
Subroutine characterSet: called CC=11 SCAR=26.6
Pod documented
166 # Get an Module::Generic::Array object
167 2 ▶ my $results = $self->findNode( 'meta' ) || return( $self->pass_error );
Condition50%1/2
$self->findNode('meta') || (return $self->pass_error)
l!l
20
MC/DC0%0/1
$self->findNode('meta') || (return $self->pass_error)
$self->findNode('meta')
Truth table50%1/2
A
A= $self->findNode('meta')
Aresult
11
00
168 2 require Module::Generic::HeaderValue;
169 2 foreach my $e ( $results->list )
170 {
171 2 ▶ if( $e->attributes->has( 'http-equiv' ) &&
Branch: 2 branches
BranchTrueFalseTotal
if ($e->attributes->has('http-equiv') and $e->attributes->get('http-equiv') eq 'Content-Type' and $e->attributes->has('content')) { } 1 1 2
elsif ($e->attributes->has('charset')) { } 1 0 1
Condition66%4/6
$e->attributes->has("http-equiv") and $e->attributes->get("http-equiv") eq "Content-Type" and $e->attributes->has("content")
!ll&&!rl&&r
101
$e->attributes->has("http-equiv") and $e->attributes->get("http-equiv") eq "Content-Type"
!ll&&!rl&&r
101
MC/DC33%1/3
$e->attributes->has("http-equiv") and $e->attributes->get("http-equiv") eq "Content-Type" and $e->attributes->has("content")
$e->attributes->has("http-equiv") $e->attributes->get("http-equiv") eq "Content-Type" $e->attributes->has("content")
Truth table50%2/4
A and B and C
A= $e->attributes->has("http-equiv")B= $e->attributes->get("http-equiv") eq "Content-Type"C= $e->attributes->has("content")
ABCresult
0XX0
10X0
1100
1111
172 $e->attributes->get( 'http-equiv' ) eq 'Content-Type' &&
173 $e->attributes->has( 'content' ) )
174 {
175 1 my $type = $e->attributes->get( 'content' );
176 1 ▶ next if( !defined( $type ) || !CORE::length( $type ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and length $type 0 1 1
Condition33%1/3
defined $type and length $type
!ll&&!rl&&r
001
MC/DC0%0/2
defined $type and length $type
defined $type length $type
Truth table33%1/3
A and B
A= defined $typeB= length $type
ABresult
0X0
100
111
177 1 my $hv = Module::Generic::HeaderValue->new_from_header( $type );
178 1 my $charset = $hv->param( 'charset' );
179 1 ▶ return( $charset // '' );
Condition50%1/2
$charset // ""
l!l
10
MC/DC0%0/1
$charset // ""
$charset
Truth table50%1/2
A
A= $charset
Aresult
11
00
180 }
181 elsif( $e->attributes->has( 'charset' ) )
182 {
183 1 ▶ return( $e->attributes->get( 'charset' ) // '' );
Condition50%1/2
$e->attributes->get("charset") // ""
l!l
10
MC/DC0%0/1
$e->attributes->get("charset") // ""
$e->attributes->get("charset")
Truth table50%1/2
A
A= $e->attributes->get("charset")
Aresult
11
00
184 }
185 }
186 0 return( '' );
187 }
188  
189 # Note: property childElementCount read-only inherited from HTML::Object::DOM::Element
190  
191 # Note: property children read-only
192 sub children
193 {
194 423 ▶ my $self = shift( @_ );
Subroutine children: called CC=2 SCAR=6.9
Pod documented
195 423 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 5 418 423
196 {
197 5 return( $self->_set_get_object_array_object( 'children', 'HTML::Object::Element', @_ ) );
198 }
199 418 $self->_init_nodes;
200 418 return( $self->_set_get_object_array_object( 'children', 'HTML::Object::Element' ) );
201 }
202  
203 0 ▶sub childNodes : lvalue { return( shift->_set_get_array_as_object( 'nodes', @_ ) ); }
Subroutine childNodes: not called CC=1 SCAR=6.9
Pod documented
204  
205 # Note: property children read-only inherited
206  
207 # method cloneNode is inherited from HTML::Object::DOM::Node
208  
209 0 ▶sub close { return( shift->{_closed} = 1 ); }
Subroutine close: not called CC=1 SCAR=6.9
Pod documented
210  
211 1 ▶sub compatMode : lvalue { return; }
Subroutine compatMode: called CC=1 SCAR=0.0
Pod documented
212  
213 # read-only
214 # e.g.:
215 # <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
216 sub contentType
217 {
218 2 ▶ my $self = shift( @_ );
Subroutine contentType: called CC=9 SCAR=23.7
Pod documented
219 2 ▶ my $results = $self->findNode( 'meta' ) || return( $self->pass_error );
Condition50%1/2
$self->findNode('meta') || (return $self->pass_error)
l!l
20
MC/DC0%0/1
$self->findNode('meta') || (return $self->pass_error)
$self->findNode('meta')
Truth table50%1/2
A
A= $self->findNode('meta')
Aresult
11
00
220 2 require Module::Generic::HeaderValue;
221 2 my $default = 'text/html';
222 2 foreach my $e ( $results->list )
223 {
224 2 ▶ if( $e->attributes->has( 'http-equiv' ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($e->attributes->has("http-equiv") and $e->attributes->get("http-equiv") eq "Content-Type" and $e->attributes->has("content")) 1 1 2
Condition66%4/6
$e->attributes->has("http-equiv") and $e->attributes->get("http-equiv") eq "Content-Type" and $e->attributes->has("content")
!ll&&!rl&&r
101
$e->attributes->has("http-equiv") and $e->attributes->get("http-equiv") eq "Content-Type"
!ll&&!rl&&r
101
MC/DC33%1/3
$e->attributes->has("http-equiv") and $e->attributes->get("http-equiv") eq "Content-Type" and $e->attributes->has("content")
$e->attributes->has("http-equiv") $e->attributes->get("http-equiv") eq "Content-Type" $e->attributes->has("content")
Truth table50%2/4
A and B and C
A= $e->attributes->has("http-equiv")B= $e->attributes->get("http-equiv") eq "Content-Type"C= $e->attributes->has("content")
ABCresult
0XX0
10X0
1100
1111
225 $e->attributes->get( 'http-equiv' ) eq 'Content-Type' &&
226 $e->attributes->has( 'content' ) )
227 {
228 1 my $type = $e->attributes->get( 'content' );
229 1 ▶ next if( !defined( $type ) || !CORE::length( $type ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and length $type 0 1 1
Condition33%1/3
defined $type and length $type
!ll&&!rl&&r
001
MC/DC0%0/2
defined $type and length $type
defined $type length $type
Truth table33%1/3
A and B
A= defined $typeB= length $type
ABresult
0X0
100
111
230 1 my $hv = Module::Generic::HeaderValue->new_from_header( $type );
231 1 ▶ return( $hv->value->first // $default );
Condition33%1/3
$hv->value->first // $default
l!l&&r!l&&!r
100
MC/DC0%0/2
$hv->value->first // $default
$hv->value->first $default
Truth table33%1/3
A // B
A= $hv->value->firstB= $default
ABresult
1X1
011
000
232 }
233 }
234 1 return( $default );
235 }
236  
237 2 ▶sub cookie : lvalue { return( shift->_set_get_lvalue( '_cookie', @_ ) ); }
Subroutine cookie: called CC=1 SCAR=0.0
Pod documented
238  
239 sub createAttribute
240 {
241 1 ▶ my $self = shift( @_ );
Subroutine createAttribute: called CC=4 SCAR=14.3
Pod documented
242 1 my $name = shift( @_ );
243 1 ▶ $name = lc( $name ) if( defined( $name ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 1 0 1
244 1 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_valid_attribute($name) 0 1 1
245 message => "The attribute provided \"$name\" contains illegal characters.",
246 class => 'HTML::Object::SyntaxError',
247 }) ) if( !$self->is_valid_attribute( $name ) );
248 1 require HTML::Object::DOM::Attribute;
249 1 ▶ my $att = HTML::Object::DOM::Attribute->new( $name, @_ ) ||
Condition50%1/2
'HTML::Object::DOM::Attribute'->new($name, @_) || (return $self->pass_error('HTML::Object::DOM::Attribute'->error))
l!l
10
MC/DC0%0/1
'HTML::Object::DOM::Attribute'->new($name, @_) || (return $self->pass_error('HTML::Object::DOM::Attribute'->error))
'HTML::Object::DOM::Attribute'->new($name, @_)
Truth table50%1/2
A
A= 'HTML::Object::DOM::Attribute'->new($name, @_)
Aresult
11
00
250 return( $self->pass_error( HTML::Object::DOM::Attribute->error ) );
251 1 return( $att );
252 }
253  
254 0 ▶sub createAttributeNS { return; }
Subroutine createAttributeNS: not called CC=1 SCAR=6.9
Pod documented
255  
256 0 ▶sub createCDATASection { return; }
Subroutine createCDATASection: not called CC=1 SCAR=6.9
Pod documented
257  
258 # TODO Create pod: https://developer.mozilla.org/en-US/docs/Web/API/Document/createComment
259 sub createComment
260 {
261 0 ▶ my $self = shift( @_ );
Subroutine createComment: not called CC=2 SCAR=17.9
Pod documented
262 0 my $data;
263 0 ▶ $data = join( '', @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
264 0 return( $self->new_comment( value => $data ) );
265 }
266  
267 sub createDocumentFragment
268 {
269 1 ▶ my $self = shift( @_ );
Subroutine createDocumentFragment: called CC=2 SCAR=7.0
Pod documented
270 1 require HTML::Object::DOM::DocumentFragment;
271 1 ▶ my $frag = HTML::Object::DOM::DocumentFragment->new( @_ ) ||
Condition50%1/2
'HTML::Object::DOM::DocumentFragment'->new(@_) || (return $self->pass_error('HTML::Object::DOM::DocumentFragment'->error))
l!l
10
MC/DC0%0/1
'HTML::Object::DOM::DocumentFragment'->new(@_) || (return $self->pass_error('HTML::Object::DOM::DocumentFragment'->error))
'HTML::Object::DOM::DocumentFragment'->new(@_)
Truth table50%1/2
A
A= 'HTML::Object::DOM::DocumentFragment'->new(@_)
Aresult
11
00
272 return( $self->pass_error( HTML::Object::DOM::DocumentFragment->error ) );
273 1 return( $frag );
274 }
275  
276 sub createElement
277 {
278 15 ▶ my $self = shift( @_ );
Subroutine createElement: called CC=5 SCAR=16.2
Pod documented
279 15 ▶ my $tag = shift( @_ ) || return( $self->error( "No tag was provided to create an element." ) );
Condition50%1/2
shift @_ || (return $self->error('No tag was provided to create an element.'))
l!l
150
MC/DC0%0/1
shift @_ || (return $self->error('No tag was provided to create an element.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
280 15 my $opts = $self->_get_args_as_hash( @_ );
281 15 my $p = HTML::Object::DOM->new;
282 15 my $def = $p->get_definition( $tag );
283 # Even if the tag does not exist, the default behaviour is to accept whatever was
284 # provided and assume it is a non-empty tag
285 15 ▶ if( !defined( $def ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $def) 0 15 15
286 {
287 0 $def =
288 {
289 is_empty => 0,
290 is_inline => 0,
291 };
292 }
293
294 15 $opts->{debug} = $self->debug;
295 15 @$opts{qw( is_empty is_inline )} = @$def{qw( is_empty is_inline )};
296 15 $opts->{tag} = $tag;
297
298 15 my $e;
299 15 ▶ $def->{class} //= '';
Condition100%2/2
$def->{"class"} //= ""
l!l
141
MC/DC100%1/1
$def->{"class"} //= ""
$def->{"class"}
Truth table100%2/2
A
A= $def->{"class"}
Aresult
11
00
300 15 ▶ if( $def->{class} )
Branch: 1 branch
BranchTrueFalseTotal
if ($def->{'class'}) { } 14 1 15
301 {
302 14 $e = $p->new_special( $def->{class} => $opts );
303 }
304 else
305 {
306 1 $e = $p->new_element( $opts );
307 }
308 15 $e->close;
309 15 return( $e );
310 }
311  
312 0 ▶sub createElementNS { return; }
Subroutine createElementNS: not called CC=1 SCAR=6.9
Pod documented
313  
314 # TODO: createEntityReference
315 0 ▶sub createEntityReference { return; }
Subroutine createEntityReference: not called CC=1 SCAR=6.9
Pod documented
316  
317 # TODO createEvent https://developer.mozilla.org/en-US/docs/Web/API/Document/createEvent
318 sub createEvent
319 {
320 0 ▶ my $self = shift( @_ );
Subroutine createEvent: not called CC=4 SCAR=30.0
Pod documented
321 0 ▶ my $type = shift( @_ ) || return( $self->error({
Condition0%0/2
shift @_ || (return $self->error({'message', 'No event type was provided', 'class', 'HTML::Objct::SyntaxError'}))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error({'message', 'No event type was provided', 'class', 'HTML::Objct::SyntaxError'}))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
322 message => 'No event type was provided',
323 class => 'HTML::Objct::SyntaxError',
324 }) );
325 0 ▶ $self->_load_class( 'HTML::Object::Event' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::Event") or return $self->pass_error 0 0 0
326 0 ▶ my $evt = HTML::Object::Event->new( $type, @_ ) ||
Condition0%0/2
'HTML::Object::Event'->new($type, @_) || (return $self->pass_error('HTML::Object::Event'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::Event'->new($type, @_) || (return $self->pass_error('HTML::Object::Event'->error))
'HTML::Object::Event'->new($type, @_)
Truth table0%0/2
A
A= 'HTML::Object::Event'->new($type, @_)
Aresult
11
00
327 return( $self->pass_error( HTML::Object::Event->error ) );
328 0 return( $evt );
329 }
330  
331 # TODO: createExpression
332 sub createExpression
333 {
334 0 ▶ my $self = shift( @_ );
Subroutine createExpression: not called CC=5 SCAR=34.0
Pod documented
335 0 my $eval;
336 0 ▶ unless( $eval = $self->{_xpath_eval} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($eval = $self->{"_xpath_eval"}) 0 0 0
337 {
338 0 ▶ $self->_load_class( 'HTML::Object::DOM::XPathEvaluator' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::XPathEvaluator") or return $self->pass_error 0 0 0
339 0 ▶ $self->{_xpath_eval} = $eval = HTML::Object::DOM::XPathEvaluator->new ||
Condition0%0/2
'HTML::Object::DOM::XPathEvaluator'->new || (return $self->pass_error('HTML::Object::DOM::XPathEvaluator'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::DOM::XPathEvaluator'->new || (return $self->pass_error('HTML::Object::DOM::XPathEvaluator'->error))
'HTML::Object::DOM::XPathEvaluator'->new
Truth table0%0/2
A
A= 'HTML::Object::DOM::XPathEvaluator'->new
Aresult
11
00
340 return( $self->pass_error( HTML::Object::DOM::XPathEvaluator->error ) );
341 }
342 0 my $expr = $eval->createExpression( @_ );
343 0 ▶ return( $self->pass_error( $eval->error ) ) if( !defined( $expr ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 0 0 0
344 0 return( $expr );
345 }
346  
347 # TODO: createNSResolver
348 0 ▶sub createNSResolver { return; }
Subroutine createNSResolver: not called CC=1 SCAR=6.9
Pod documented
349  
350 # TODO: createNodeIterator
351 sub createNodeIterator
352 {
353 2 ▶ my $self = shift( @_ );
Subroutine createNodeIterator: called CC=3 SCAR=11.3
Pod documented
354 2 ▶ $self->_load_class( 'HTML::Object::DOM::NodeIterator' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::NodeIterator") or return $self->pass_error 0 2 2
355 2 my $iterator = HTML::Object::DOM::NodeIterator->new( @_ );
356 2 ▶ return( $self->pass_error( HTML::Object::DOM::NodeIterator->error ) ) if( !defined( $iterator ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $iterator 0 2 2
357 2 return( $iterator );
358 }
359  
360 0 ▶sub createProcessingInstruction { return; }
Subroutine createProcessingInstruction: not called CC=1 SCAR=6.9
Pod documented
361  
362 # TODO: createRange
363 0 ▶sub createRange { return; }
Subroutine createRange: not called CC=1 SCAR=6.9
Pod documented
364  
365 sub createTextNode
366 {
367 1 ▶ my $self = shift( @_ );
Subroutine createTextNode: called CC=4 SCAR=14.6
Pod documented
368 1 ▶ my $txt = @_ == 1 ? shift( @_ ) : join( '', @_ );
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 1 0 1
369 1 ▶ $self->_load_class( 'HTML::Object::DOM::Text' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::Text") or return $self->pass_error 0 1 1
370 1 ▶ my $node = HTML::Object::DOM::Text->new( value => $txt ) ||
Condition50%1/2
'HTML::Object::DOM::Text'->new('value', $txt) || (return $self->pass_error('HTML::Object::DOM::Text'->error))
l!l
10
MC/DC0%0/1
'HTML::Object::DOM::Text'->new('value', $txt) || (return $self->pass_error('HTML::Object::DOM::Text'->error))
'HTML::Object::DOM::Text'->new('value', $txt)
Truth table50%1/2
A
A= 'HTML::Object::DOM::Text'->new('value', $txt)
Aresult
11
00
371 return( $self->pass_error( HTML::Object::DOM::Text->error ) );
372 1 return( $node );
373 }
374  
375 0 ▶sub createTouch { return; }
Subroutine createTouch: not called CC=1 SCAR=6.9
Pod documented
376  
377 0 ▶sub createTouchList { return; }
Subroutine createTouchList: not called CC=1 SCAR=6.9
Pod documented
378  
379 sub createTreeWalker
380 {
381 8 ▶ my $self = shift( @_ );
Subroutine createTreeWalker: called CC=3 SCAR=11.3
Pod documented
382 8 ▶ $self->_load_class( 'HTML::Object::DOM::TreeWalker' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::TreeWalker") or return $self->pass_error 0 8 8
383 8 my $crawler = HTML::Object::DOM::TreeWalker->new( @_ );
384 8 ▶ return( $self->pass_error( HTML::Object::DOM::TreeWalker->error ) ) if( !defined( $crawler ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $crawler 0 8 8
385 8 return( $crawler );
386 }
387  
388 0 ▶sub currentScript { return( shift->_set_get_object_lvalue( 'currentscript', 'HTML::Object::DOM::Element', @_ ) ); }
Subroutine currentScript: not called CC=1 SCAR=6.9
Pod documented
389  
390 70 ▶sub defaultView : lvalue { return( shift->_set_get_object_lvalue( 'defaultview', 'HTML::Object::DOM::Window', @_ ) ); }
Subroutine defaultView: called CC=1 SCAR=0.0
Pod documented
391  
392 1 ▶sub designMode : lvalue { return; }
Subroutine designMode: called CC=1 SCAR=0.0
Pod documented
393  
394 2 ▶sub dir : lvalue { return( shift->_set_get_lvalue( '_dir' ) ); }
Subroutine dir: called CC=1 SCAR=0.0
Pod documented
395  
396 # Note: property doctype read-only
397 sub doctype : lvalue
398 {
399 3 ▶ my $self = shift( @_ );
Subroutine doctype: called CC=1 SCAR=0.0
Pod documented
400 3 return( $self->declaration );
401 }
402  
403 # Note: property documentElement read-only
404 sub documentElement : lvalue
405 {
406 22 ▶ my $self = shift( @_ );
Subroutine documentElement: called CC=7 SCAR=22.6
Pod documented
407 22 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 22 22
408 {
409 0 ▶ warn( "This property \"documentElement\" is read-only.\n" ) if( $self->_is_warnings_enabled( 'HTML::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTML::Object") 0 0 0
410 }
411 22 my $html;
412 # It should be the first one, but let's not assume anything
413 22 my $children = $self->children;
414 22 foreach( @$children )
415 {
416 66 ▶ if( $_->tag eq 'html' )
Branch: 1 branch
BranchTrueFalseTotal
if ($_->tag eq "html") 22 44 66
417 {
418 22 $html = $_;
419 22 last;
420 }
421 }
422 22 ▶ if( !$html && want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $html and want("OBJECT")) 0 22 22
Condition33%1/3
not $html and want("OBJECT")
!ll&&!rl&&r
2200
MC/DC0%0/2
not $html and want("OBJECT")
not $html want("OBJECT")
Truth table33%1/3
not(A) and B
A= not $htmlB= want("OBJECT")
ABresult
0X0
100
111
423 {
424 0 require Module::Generic::Null;
425 0 return( Module::Generic::Null->new( wants => 'OBJECT' ) );
426 }
427 22 return( $html );
428 }
429  
430 # Note: property documentURI read-only
431 1 ▶sub documentURI : lvalue { return( shift->_set_get_uri( 'uri', @_ ) ); }
Subroutine documentURI: called CC=1 SCAR=0.0
Pod documented
432  
433 0 ▶sub elementFromPoint { return; }
Subroutine elementFromPoint: not called CC=1 SCAR=6.9
Pod documented
434  
435 0 ▶sub elementsFromPoint { return; }
Subroutine elementsFromPoint: not called CC=1 SCAR=6.9
Pod documented
436  
437 # Note: property read-only embeds
438 sub embeds
439 {
440 1 ▶ my $self = shift( @_ );
Subroutine embeds: called CC=2 SCAR=7.1
Pod documented
441 1 ▶ my $results = $self->findNode( 'embed' ) || return( $self->pass_error );
Condition50%1/2
$self->findNode('embed') || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$self->findNode('embed') || (return $self->pass_error)
$self->findNode('embed')
Truth table50%1/2
A
A= $self->findNode('embed')
Aresult
11
00
442 1 return( $self->new_collection_elements( $results ) );
443 }
444  
445 0 ▶sub enableStyleSheetsForSet { return; }
Subroutine enableStyleSheetsForSet: not called CC=1 SCAR=6.9
Pod documented
446  
447 sub evaluate
448 {
449 0 ▶ my $self = shift( @_ );
Subroutine evaluate: not called CC=4 SCAR=30.0
Pod documented
450 0 my $eval;
451 0 ▶ unless( $eval = $self->{_xpath_eval} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($eval = $self->{"_xpath_eval"}) 0 0 0
452 {
453 0 ▶ $self->_load_class( 'HTML::Object::DOM::XPathEvaluator' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::XPathEvaluator") or return $self->pass_error 0 0 0
454 0 ▶ $self->{_xpath_eval} = $eval = HTML::Object::DOM::XPathEvaluator->new ||
Condition0%0/2
'HTML::Object::DOM::XPathEvaluator'->new || (return $self->pass_error('HTML::Object::DOM::XPathEvaluator'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::DOM::XPathEvaluator'->new || (return $self->pass_error('HTML::Object::DOM::XPathEvaluator'->error))
'HTML::Object::DOM::XPathEvaluator'->new
Truth table0%0/2
A
A= 'HTML::Object::DOM::XPathEvaluator'->new
Aresult
11
00
455 return( $self->pass_error( HTML::Object::DOM::XPathEvaluator->error ) );
456 }
457 0 return( $eval->evaluate( @_ ) );
458 }
459  
460 0 ▶sub execCommand { return; }
Subroutine execCommand: not called CC=1 SCAR=6.9
Pod documented
461  
462 0 ▶sub exitPictureInPicture { return; }
Subroutine exitPictureInPicture: not called CC=1 SCAR=6.9
Pod documented
463  
464 0 ▶sub exitPointerLock { return; }
Subroutine exitPointerLock: not called CC=1 SCAR=6.9
Pod documented
465  
466 1 ▶sub featurePolicy : lvalue { return; }
Subroutine featurePolicy: called CC=1 SCAR=0.0
Pod documented
467  
468 # Note: firstChild returns its values from the nodes array, not the children one; is inherited
469  
470 # Note: method firstElementChild is inherited from HTML::Object::DOM::Element
471  
472 # Note: property read-only fonts
473 1 ▶sub fonts { return; }
Subroutine fonts: called CC=1 SCAR=0.0
Pod documented
474  
475 # Note: property read-only forms
476 sub forms
477 {
478 1 ▶ my $self = shift( @_ );
Subroutine forms: called CC=2 SCAR=7.1
Pod documented
479 1 ▶ my $results = $self->findNode( 'form' ) || return( $self->pass_error );
Condition50%1/2
$self->findNode('form') || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$self->findNode('form') || (return $self->pass_error)
$self->findNode('form')
Truth table50%1/2
A
A= $self->findNode('form')
Aresult
11
00
480 1 return( $self->new_collection_elements( $results ) );
481 }
482  
483 1 ▶sub fullscreenElement : lvalue { return; }
Subroutine fullscreenElement: called CC=1 SCAR=0.0
Pod documented
484  
485 0 ▶sub getAnimations { return; }
Subroutine getAnimations: not called CC=1 SCAR=6.9
Pod documented
486  
487 0 ▶sub getBoxQuads { return; }
Subroutine getBoxQuads: not called CC=1 SCAR=6.9
Pod documented
488  
489 sub getElementById
490 {
491 19 ▶ my $self = shift( @_ );
Subroutine getElementById: called CC=3 SCAR=11.0
Pod documented
492 19 my $id = shift( @_ );
493 19 ▶ return if( !defined( $id ) || !CORE::length( $id ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and length $id 0 19 19
Condition33%1/3
defined $id and length $id
!ll&&!rl&&r
0019
MC/DC0%0/2
defined $id and length $id
defined $id length $id
Truth table33%1/3
A and B
A= defined $idB= length $id
ABresult
0X0
100
111
494 19 my $seen = {};
495 19 my $crawl;
496 $crawl = sub
497 {
498 354 ▶ my $elem = shift( @_ );
Subroutine __ANON__: called CC=6 SCAR=17.9
499 354 my $addr = Scalar::Util::refaddr( $elem );
500 354 ▶ return if( CORE::exists( $seen->{ $addr } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $seen->{$addr} 0 354 354
501 # Not a true element, such as text, comment
502 354 ▶ return if( $elem->tag->substr( 0, 1 ) eq '_' && !$self->_is_a( $elem => 'HTML::Object::Document' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $elem->tag->substr(0, 1) eq "_" and not $self->_is_a($elem, "HTML::Object::Document") 189 165 354
Condition100%3/3
$elem->tag->substr(0, 1) eq "_" and not $self->_is_a($elem, "HTML::Object::Document")
!ll&&!rl&&r
14619189
MC/DC100%2/2
$elem->tag->substr(0, 1) eq "_" and not $self->_is_a($elem, "HTML::Object::Document")
$elem->tag->substr(0, 1) eq "_" not $self->_is_a($elem, "HTML::Object::Document")
Truth table100%3/3
A and not(B)
A= $elem->tag->substr(0, 1) eq "_"B= not $self->_is_a($elem, "HTML::Object::Document")
ABresult
0X0
100
111
503 165 $seen->{ $addr }++;
504 165 ▶ if( $elem->attributes->has( 'id' ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->attributes->has("id") and $elem->attributes->get("id") eq $id) 19 146 165
Condition100%3/3
$elem->attributes->has("id") and $elem->attributes->get("id") eq $id
!ll&&!rl&&r
1361019
MC/DC100%2/2
$elem->attributes->has("id") and $elem->attributes->get("id") eq $id
$elem->attributes->has("id") $elem->attributes->get("id") eq $id
Truth table100%3/3
A and B
A= $elem->attributes->has("id")B= $elem->attributes->get("id") eq $id
ABresult
0X0
100
111
505 $elem->attributes->get( 'id' ) eq $id )
506 {
507 19 return( $elem );
508 }
509 146 my $e;
510 $elem->children->foreach(sub
511 {
512 335 ▶ my $this = shift( @_ );
Subroutine __ANON__: called CC=2 SCAR=6.9
513 335 ▶ if( my $found = $crawl->( $this ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $found = &$crawl($this)) 57 278 335
514 {
515 57 $e = $found;
516 # last
517 57 return(0);
518 }
519 278 return(1);
520 146 });
521 146 return( $e );
522 19 };
523 19 return( $crawl->( $self ) );
524 }
525  
526 # Note: method getElementsByClassName is inherited from HTML::Object::DOM::Element
527  
528 sub getElementsByName
529 {
530 0 ▶ my $self = shift( @_ );
Subroutine getElementsByName: not called CC=5 SCAR=34.0
Pod documented
531 0 my $name = shift( @_ );
532 0 ▶ return( $self->error( "No value was provided for getElementsByName()" ) ) if( !defined( $name ) || !CORE::length( "$name" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length "$name" 0 0 0
Condition0%0/3
defined $name and length "$name"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and length "$name"
defined $name length "$name"
Truth table0%0/3
A and B
A= defined $nameB= length "$name"
ABresult
0X0
100
111
533 0 ▶ my $results = $self->look_down( name => $name ) || return( $self->pass_error );
Condition0%0/2
$self->look_down('name', $name) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->look_down('name', $name) || (return $self->pass_error)
$self->look_down('name', $name)
Truth table0%0/2
A
A= $self->look_down('name', $name)
Aresult
11
00
534 0 ▶ my $list = $self->new_nodelist( $results ) || return( $self->pass_error );
Condition0%0/2
$self->new_nodelist($results) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_nodelist($results) || (return $self->pass_error)
$self->new_nodelist($results)
Truth table0%0/2
A
A= $self->new_nodelist($results)
Aresult
11
00
535 0 return( $list );
536 }
537  
538 # Note: method getElementsByTagName is inherited from HTML::Object::DOM::Element
539  
540 0 ▶sub getElementsByTagNameNS { return; }
Subroutine getElementsByTagNameNS: not called CC=1 SCAR=6.9
Pod documented
541  
542 19 ▶sub getRootNode { return( shift->root ); }
Subroutine getRootNode: called CC=1 SCAR=0.0
Pod documented
543  
544 0 ▶sub getSelection { return; }
Subroutine getSelection: not called CC=1 SCAR=6.9
Pod documented
545  
546 # Note: method hasChildNodes is inherited
547  
548 0 ▶sub hasFocus { return(1); }
Subroutine hasFocus: not called CC=1 SCAR=6.9
Pod documented
549  
550 0 ▶sub hasStorageAccess { return; }
Subroutine hasStorageAccess: not called CC=1 SCAR=6.9
Pod documented
551  
552 # Note: property head read-only
553 sub head : lvalue
554 {
555 2 ▶ my $self = shift( @_ );
Subroutine head: called CC=4 SCAR=16.6
Pod documented
556 2 ▶ my $results = $self->findNode( 'head' ) || return( $self->pass_error );
Condition50%1/2
$self->findNode('head') || (return $self->pass_error)
l!l
20
MC/DC0%0/1
$self->findNode('head') || (return $self->pass_error)
$self->findNode('head')
Truth table50%1/2
A
A= $self->findNode('head')
Aresult
11
00
557 2 my $head = $results->first;
558 2 ▶ if( !$head && want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $head and want("OBJECT")) 0 2 2
Condition33%1/3
not $head and want("OBJECT")
!ll&&!rl&&r
200
MC/DC0%0/2
not $head and want("OBJECT")
not $head want("OBJECT")
Truth table33%1/3
not(A) and B
A= not $headB= want("OBJECT")
ABresult
0X0
100
111
559 {
560 0 require Module::Generic::Null;
561 0 rreturn( Module::Generic::Null->new( wants => 'OBJECT' ) );
562 }
563 2 return( $head );
564 }
565  
566 # Note: property hidden read-only
567 1 ▶sub hidden : lvalue { return; }
Subroutine hidden: called CC=1 SCAR=0.0
Pod documented
568  
569 # Note: property images read-only
570 sub images : lvalue
571 {
572 1 ▶ my $self = shift( @_ );
Subroutine images: called CC=2 SCAR=7.1
Pod documented
573 1 ▶ my $results = $self->findNode( 'img' ) || return( $self->pass_error );
Condition50%1/2
$self->findNode('img') || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$self->findNode('img') || (return $self->pass_error)
$self->findNode('img')
Truth table50%1/2
A
A= $self->findNode('img')
Aresult
11
00
574 1 return( $self->new_collection_elements( $results ) );
575 }
576  
577 # Note: property implementation read-only
578 sub implementation
579 {
580 1 ▶ my $self = shift( @_ );
Subroutine implementation: called CC=4 SCAR=14.6
Pod documented
581 1 ▶ unless( $self->{_implementation} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_implementation"}) 1 0 1
582 {
583 1 ▶ $self->_load_class( 'HTML::Object::DOM::Implementation' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::Implementation") or return $self->pass_error 0 1 1
584 1 ▶ $self->{_implementation} = HTML::Object::DOM::Implementation->new( debug => $self->debug ) ||
Condition50%1/2
'HTML::Object::DOM::Implementation'->new('debug', $self->debug) || (return $self->pass_error('HTML::Object::DOM::Implementation'->error))
l!l
10
MC/DC0%0/1
'HTML::Object::DOM::Implementation'->new('debug', $self->debug) || (return $self->pass_error('HTML::Object::DOM::Implementation'->error))
'HTML::Object::DOM::Implementation'->new('debug', $self->debug)
Truth table50%1/2
A
A= 'HTML::Object::DOM::Implementation'->new('debug', $self->debug)
Aresult
11
00
585 return( $self->pass_error( HTML::Object::DOM::Implementation->error ) );
586 }
587 1 return( $self->{_implementation} );
588 }
589  
590 0 ▶sub importNode { return( shift->adoptNode( @_ ) ); }
Subroutine importNode: not called CC=1 SCAR=6.9
Pod documented
591  
592 # Note: method insertAfter is inherited
593  
594 # Note: method insertBefore is inherited
595  
596 # Note: property lastChild is inherited
597  
598 # Note: method lastElementChild is inherited from HTML::Object::DOM::Element
599  
600 1 ▶sub lastModified : lvalue { return( shift->_set_get_datetime( '_last_modified' ) ); }
Subroutine lastModified: called CC=1 SCAR=0.0
Pod documented
601  
602 # Note: property links read-only
603 sub links : lvalue
604 {
605 1 ▶ my $self = shift( @_ );
Subroutine links: called CC=2 SCAR=7.1
Pod documented
606 1 ▶ my $results = $self->findNode( 'a' ) || return( $self->pass_error );
Condition50%1/2
$self->findNode('a') || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$self->findNode('a') || (return $self->pass_error)
$self->findNode('a')
Truth table50%1/2
A
A= $self->findNode('a')
Aresult
11
00
607 1 return( $results );
608 }
609  
610 1 ▶sub location : lvalue { return( shift->_set_get_uri( 'uri', @_ ) ); }
Subroutine location: called CC=1 SCAR=0.0
Pod documented
611  
612 0 ▶sub mozSetImageElement { return; }
Subroutine mozSetImageElement: not called CC=1 SCAR=6.9
Pod documented
613  
614 # Note: property mozSyntheticDocument
615 0 ▶sub mozSyntheticDocument : lvalue { return( shift->_set_get_boolean( 'mozsyntheticdocument', @_ ) ); }
Subroutine mozSyntheticDocument: not called CC=1 SCAR=6.9
Pod documented
616  
617 0 ▶sub nextSibling { return( shift->new_null ); }
Subroutine nextSibling: not called CC=1 SCAR=6.9
Pod documented
618  
619 # See also children for its alter ego
620 41 ▶sub nodes { return( shift->_init_nodes ); }
Subroutine nodes: called CC=1 SCAR=0.0
Pod documented
621  
622 # Note: Property
623 # Should be undef for document
624 # <https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeValue>
625 2 ▶sub nodeValue { return; }
Subroutine nodeValue: called CC=1 SCAR=0.0
Pod documented
626  
627 # Note: this is merely an alias to HTML::Object::DOM::Node->normalize
628 0 ▶sub normalizeDocument { return( shift->normalize( @_ ) ); }
Subroutine normalizeDocument: not called CC=1 SCAR=6.9
Pod documented
629  
630 # Note: Property
631 0 ▶sub onabort : lvalue { return( shift->_set_get_on_signal( [qw( ABRT TERM INT )], @_ ) ); }
Subroutine onabort: not called CC=1 SCAR=6.9
Pod documented
632  
633 0 ▶sub onafterscriptexecute : lvalue { return( shift->on( 'afterscriptexecute', @_ ) ); }
Subroutine onafterscriptexecute: not called CC=1 SCAR=6.9
Pod documented
634  
635 0 ▶sub onbeforescriptexecute : lvalue { return( shift->on( 'beforescriptexecute', @_ ) ); }
Subroutine onbeforescriptexecute: not called CC=1 SCAR=6.9
Pod documented
636  
637 0 ▶sub oncopy : lvalue { return( shift->on( 'copy', @_ ) ); }
Subroutine oncopy: not called CC=1 SCAR=6.9
Pod documented
638  
639 0 ▶sub oncut : lvalue { return( shift->on( 'cut', @_ ) ); }
Subroutine oncut: not called CC=1 SCAR=6.9
Pod documented
640  
641 0 ▶sub onerror : lvalue { return( shift->_set_get_on_signal( [qw( __WARN__ )], @_ ) ); }
Subroutine onerror: not called CC=1 SCAR=6.9
Pod documented
642  
643 0 ▶sub onfullscreenchange : lvalue { return( shift->on( 'fullscreenchange', @_ ) ); }
Subroutine onfullscreenchange: not called CC=1 SCAR=6.9
Pod documented
644  
645 0 ▶sub onfullscreenerror : lvalue { return( shift->on( 'fullscreenerror', @_ ) ); }
Subroutine onfullscreenerror: not called CC=1 SCAR=6.9
Pod documented
646  
647 66 ▶sub onload : lvalue { return( shift->_set_get_code( 'onload', @_ ) ); }
Subroutine onload: called CC=1 SCAR=0.0
Pod documented
648  
649 0 ▶sub onpaste : lvalue { return( shift->on( 'paste', @_ ) ); }
Subroutine onpaste: not called CC=1 SCAR=6.9
Pod documented
650  
651 # sub onreadystatechange : lvalue { return( shift->_set_get_code( 'onreadystatechange', @_ ) ); }
652 193 ▶sub onreadystatechange : lvalue { return( shift->on( 'readystatechange', @_ ) ); }
Subroutine onreadystatechange: called CC=1 SCAR=0.0
Pod documented
653  
654 0 ▶sub onscroll : lvalue { return( shift->on( 'scroll', @_ ) ); }
Subroutine onscroll: not called CC=1 SCAR=6.9
Pod documented
655  
656 0 ▶sub onselectionchange : lvalue { return( shift->on( 'selectionchange', @_ ) ); }
Subroutine onselectionchange: not called CC=1 SCAR=6.9
Pod documented
657  
658 0 ▶sub onvisibilitychange : lvalue { return( shift->on( 'visibilitychange', @_ ) ); }
Subroutine onvisibilitychange: not called CC=1 SCAR=6.9
Pod documented
659  
660 0 ▶sub onwheel : lvalue { return( shift->on( 'wheel', @_ ) ); }
Subroutine onwheel: not called CC=1 SCAR=6.9
Pod documented
661  
662 sub open
663 {
664 0 ▶ my $self = shift( @_ );
Subroutine open: not called CC=5 SCAR=34.0
Pod documented
665 # Already opened
666 0 ▶ return( $self ) if( !$self->{_closed} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_closed"} 0 0 0
667 0 ▶ my $doc = $self->_list_to_nodes( q{<html><head><title></title></head><body></body></html>} ) ||
Condition0%0/2
$self->_list_to_nodes('<html><head><title></title></head><body></body></html>') || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_list_to_nodes('<html><head><title></title></head><body></body></html>') || (return $self->pass_error)
$self->_list_to_nodes('<html><head><title></title></head><body></body></html>')
Truth table0%0/2
A
A= $self->_list_to_nodes('<html><head><title></title></head><body></body></html>')
Aresult
11
00
668 return( $self->pass_error );
669 # Remove the DTD
670 0 $self->declaration( undef );
671 0 my $html = $doc->children->first;
672 0 ▶ return( $self->error( "Cannot find the top <html> element in our own standard document for document->open!" ) ) if( !$html );
Branch: 1 branch
BranchTrueFalseTotal
unless $html 0 0 0
673 0 ▶ return( $self->error( "HTML top element found is not a <html> element" ) ) if( $html->tag ne 'html' );
Branch: 1 branch
BranchTrueFalseTotal
if $html->tag ne "html" 0 0 0
674 0 $html->parent( $self );
675 0 $self->children->reset;
676 0 $self->children->push( $html );
677 0 $self->reset(1);
678 0 return( $self );
679 }
680  
681 # Note: property ownerDocument inherited from HTML::Object::DOM::Node
682  
683 0 ▶sub parentElement { return( shift->new_null ); }
Subroutine parentElement: not called CC=1 SCAR=6.9
Pod documented
684  
685 2 ▶sub parentNode { return( shift->new_null ); }
Subroutine parentNode: called CC=1 SCAR=0.0
Pod documented
686  
687 1 ▶sub pictureInPictureElement : lvalue { return( shift->_set_get_object_lvalue( 'pictureinpictureelement', 'HTML::Object::DOM::Element', @_ ) ); }
Subroutine pictureInPictureElement: called CC=1 SCAR=0.0
Pod documented
688  
689 1 ▶sub pictureInPictureEnabled : lvalue { return( shift->_set_get_boolean( 'pictureinpictureenabled', @_ ) ); }
Subroutine pictureInPictureEnabled: called CC=1 SCAR=0.0
Pod documented
690  
691 # Note: property read-only plugins
692 1 ▶sub plugins { return( shift->new_collection_elements ); }
Subroutine plugins: called CC=1 SCAR=0.0
Pod documented
693  
694 1 ▶sub pointerLockElement : lvalue { return( shift->_set_get_object_lvalue( 'pointerlockelement', 'HTML::Object::DOM::Element', @_ ) ); }
Subroutine pointerLockElement: called CC=1 SCAR=0.0
Pod documented
695  
696 sub prepend
697 {
698 0 ▶ my $self = shift( @_ );
Subroutine prepend: not called CC=4 SCAR=30.0
Pod documented
699 0 ▶ return( $self ) if( !scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 0 0 0
700 # If a HTML::Object::DOM::DocumentFragment object is provided, its children are
701 # copied to the list and its own children array is emptied.
702 0 ▶ my $list = $self->_check_list_of_nodes_or_text( @_ ) || return( $self->pass_error );
Condition0%0/2
$self->_check_list_of_nodes_or_text(@_) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_check_list_of_nodes_or_text(@_) || (return $self->pass_error)
$self->_check_list_of_nodes_or_text(@_)
Truth table0%0/2
A
A= $self->_check_list_of_nodes_or_text(@_)
Aresult
11
00
703 0 my $nodes = $self->nodes;
704 0 ▶ $self->reset(1) if( !$list->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
unless $list->is_empty 0 0 0
705 $list->foreach(sub
706 {
707 0 ▶ $_->parent( $self );
Subroutine __ANON__: not called CC=1 SCAR=6.9
708 0 });
709 0 $nodes->unshift( $list->list );
710 0 return( $self );
711 }
712  
713 0 ▶sub previousSibling { return( shift->new_null ); }
Subroutine previousSibling: not called CC=1 SCAR=6.9
Pod documented
714  
715 0 ▶sub queryCommandEnabled { return(0); }
Subroutine queryCommandEnabled: not called CC=1 SCAR=6.9
Pod documented
716  
717 0 ▶sub queryCommandIndeterm { return(1); }
Subroutine queryCommandIndeterm: not called CC=1 SCAR=6.9
Pod documented
718  
719 0 ▶sub queryCommandState { return(0); }
Subroutine queryCommandState: not called CC=1 SCAR=6.9
Pod documented
720  
721 0 ▶sub queryCommandSupported { return(0); }
Subroutine queryCommandSupported: not called CC=1 SCAR=6.9
Pod documented
722  
723 0 ▶sub queryCommandValue { return; }
Subroutine queryCommandValue: not called CC=1 SCAR=6.9
Pod documented
724  
725 # Note: method querySelector is inherited from HTML::Object::DOM::Element
726  
727 # Note: method querySelectorAll is inherited from HTML::Object::DOM::Element
728  
729 196 ▶sub readyState : lvalue { return( shift->_set_get_lvalue( 'readyState', @_ ) ); }
Subroutine readyState: called CC=1 SCAR=0.0
Pod documented
730  
731 1 ▶sub referrer : lvalue { return( shift->_set_get_uri( 'referrer', @_ ) ); }
Subroutine referrer: called CC=1 SCAR=0.0
Pod documented
732  
733 0 ▶sub releaseCapture { return( shift->defaultView->releaseCapture( @_ ) ); }
Subroutine releaseCapture: not called CC=1 SCAR=6.9
Pod documented
734  
735 0 ▶sub releaseEvents { return( shift->defaultView->releaseEvents( @_ ) ); }
Subroutine releaseEvents: not called CC=1 SCAR=6.9
Pod documented
736  
737 # Note: method removeChild is inherited
738  
739 # Note: replaceChild is inherited
740  
741 # Note: the Document replaceChildren() method is different from the HTML::Object::DOM::Element replaceChildren()
742 sub replaceChildren
743 {
744 0 ▶ my $self = shift( @_ );
Subroutine replaceChildren: not called CC=9 SCAR=45.0
Pod documented
745 0 ▶ if( !scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @_) 0 0 0
746 {
747 0 $self->nodes->reset;
748 0 return( $self );
749 }
750 0 my $list = $self->_get_from_list_of_elements_or_html( @_ );
751 0 ▶ return( $list ) if( $list->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $list->is_empty 0 0 0
752 0 my $html;
753 0 foreach my $e ( @$list )
754 {
755 0 ▶ if( $self->_is_a( $e => 'HTML::Object::DOM::Element' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($e, "HTML::Object::DOM::Element")) 0 0 0
756 {
757 0 ▶ if( $e->tag eq 'html' )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->tag eq 'html') { } 0 0 0
758 {
759 0 ▶ if( defined( $html ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $html) { } 0 0 0
760 {
761 0 return( $self->error({
762 message => "You have already provided an <html> element. You can only provide one.",
763 class => 'HTML::Object::HierarchyRequestError',
764 }) );
765 }
766 else
767 {
768 0 $html = $e;
769 }
770 }
771 else
772 {
773 0 return( $self->error({
774 message => "Only the <html> element is allowed inside the Document.",
775 class => 'HTML::Object::HierarchyRequestError',
776 }) );
777 }
778 }
779 }
780 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $html 0 0 0
781 message => "You have not provided any <html> element. A document must have at least one <html> element.",
782 class => 'HTML::Object::HierarchyRequestError',
783 }) ) if( !defined( $html ) );
784 0 ▶ return( $self ) if( $list->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $list->is_empty 0 0 0
785 0 my $nodes = $self->nodes;
786 0 $nodes->reset;
787 $list->foreach(sub
788 {
789 0 ▶ $_->detach;
Subroutine __ANON__: not called CC=1 SCAR=6.9
790 0 $_->parent( $self );
791 0 });
792 0 $nodes->push( $list->list );
793 0 $self->children->reset;
794 0 $self->children->push( $html );
795 0 return( $self );
796 }
797  
798 0 ▶sub requestStorageAccess { return; }
Subroutine requestStorageAccess: not called CC=1 SCAR=6.9
Pod documented
799  
800 # Note: property scripts read-only
801 sub scripts : lvalue
802 {
803 1 ▶ my $self = shift( @_ );
Subroutine scripts: called CC=2 SCAR=7.1
Pod documented
804 1 ▶ my $results = $self->findNode( 'script' ) || return( $self->pass_error );
Condition50%1/2
$self->findNode('script') || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$self->findNode('script') || (return $self->pass_error)
$self->findNode('script')
Truth table50%1/2
A
A= $self->findNode('script')
Aresult
11
00
805 1 return( $results );
806 }
807  
808 # Note: property scrollingElement read-only
809 1 ▶sub scrollingElement : lvalue { return( shift->_set_get_object_lvalue( 'scrollingelement', 'HTML::Object::DOM::Element', @_ ) ); }
Subroutine scrollingElement: called CC=1 SCAR=0.0
Pod documented
810  
811 107 ▶sub string_value { return; }
Subroutine string_value: called CC=1 SCAR=0.0
Pod documented
812  
813 # Note: property styleSheets read-only
814 sub styleSheets : lvalue
815 {
816 1 ▶ my $self = shift( @_ );
Subroutine styleSheets: called CC=3 SCAR=11.3
Pod documented
817 1 ▶ my $list = $self->findNode( 'link[rel="stylesheet"]' ) || return( $self->pass_error );
Condition50%1/2
$self->findNode('link[rel="stylesheet"]') || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$self->findNode('link[rel="stylesheet"]') || (return $self->pass_error)
$self->findNode('link[rel="stylesheet"]')
Truth table50%1/2
A
A= $self->findNode('link[rel="stylesheet"]')
Aresult
11
00
818 1 ▶ my $results2 = $self->findNode( 'stylesheet' ) || return( $self->pass_error );
Condition50%1/2
$self->findNode('stylesheet') || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$self->findNode('stylesheet') || (return $self->pass_error)
$self->findNode('stylesheet')
Truth table50%1/2
A
A= $self->findNode('stylesheet')
Aresult
11
00
819 1 $list->merge( $results2 );
820 1 return( $list );
821 }
822  
823 # Note: property timeline read-only
824 1 ▶sub timeline : lvalue { return; }
Subroutine timeline: called CC=1 SCAR=0.0
Pod documented
825  
826 sub title : lvalue { return( shift->_set_get_callback({
827 get => sub
828 {
829 2 ▶ my $self = shift( @_ );
Subroutine __ANON__: called CC=3 SCAR=11.4
830 2 ▶ my $results = $self->findNode( 'title' ) || die( $self->error );
Condition50%1/2
$self->findNode('title') || die($self->error)
l!l
20
MC/DC0%0/1
$self->findNode('title') || die($self->error)
$self->findNode('title')
Truth table50%1/2
A
A= $self->findNode('title')
Aresult
11
00
831 2 ▶ return if( $results->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $results->is_empty 0 2 2
832 2 return( $results->first->text );
833 },
834 set => sub
835 {
836 0 ▶ my $self = shift( @_ );
Subroutine __ANON__: not called CC=5 SCAR=34.0
837 0 my $arg = shift( @_ );
838 0 ▶ my $results = $self->findNode( 'title' ) || die( $self->error );
Condition0%0/2
$self->findNode('title') || die($self->error)
l!l
00
MC/DC0%0/1
$self->findNode('title') || die($self->error)
$self->findNode('title')
Truth table0%0/2
A
A= $self->findNode('title')
Aresult
11
00
839 0 my $e;
840 0 ▶ if( $results->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
if ($results->is_empty) { } 0 0 0
841 {
842 0 ▶ my $head_results = $self->findNode( 'head' ) || die( $self->error );
Condition0%0/2
$self->findNode('head') || die($self->error)
l!l
00
MC/DC0%0/1
$self->findNode('head') || die($self->error)
$self->findNode('head')
Truth table0%0/2
A
A= $self->findNode('head')
Aresult
11
00
843 0 ▶ if( $head_results->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
if ($head_results->is_empty) 0 0 0
844 {
845 0 die( "Could not find the <head> tag to set as parent of the missing <title>. Something is seriously wrong." );
846 }
847 0 my $head = $head_results->first;
848 0 $e = $self->createElement( 'title' );
849 0 $e->close;
850 0 $head->push( $e );
851 0 $e->parent( $head );
852 }
853 else
854 {
855 0 $e = $results->first;
856 }
857
858 0 return( $e->text( $arg ) );
859 },
860 2 ▶}, @_ ) ); }
Subroutine title: called CC=1 SCAR=0.0
Pod documented
861  
862 1 ▶sub URL : lvalue { return( shift->_set_get_uri( 'uri', @_ ) ); }
Subroutine URL: called CC=1 SCAR=0.0
Pod documented
863  
864 # Note: property visibilityState read-only
865 1 ▶sub visibilityState : lvalue { return( shift->_set_get_scalar_as_object( 'visibilitystate', @_ ) ); }
Subroutine visibilityState: called CC=1 SCAR=0.0
Pod documented
866  
867 sub write
868 {
869 0 ▶ my $self = shift( @_ );
Subroutine write: not called CC=4 SCAR=30.0
Pod documented
870 0 ▶ if( $self->{_closed} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_closed"}) 0 0 0
871 {
872 0 ▶ $self->open() || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->open or return $self->pass_error 0 0 0
873 }
874 0 ▶ my $body = $self->body || return( $self->pass_error );
Condition0%0/2
$self->body || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->body || (return $self->pass_error)
$self->body
Truth table0%0/2
A
A= $self->body
Aresult
11
00
875 # Using _list_to_nodes from HTML::Object::DOM::Node
876 0 my $list = $self->_list_to_nodes( @_ );
877 $list->foreach(sub
878 {
879 0 ▶ $_->parent( $body );
Subroutine __ANON__: not called CC=1 SCAR=6.9
880 0 });
881 0 $body->children->push( $list->list );
882 0 return( $list );
883 }
884  
885 sub writeln
886 {
887 0 ▶ my $self = shift( @_ );
Subroutine writeln: not called CC=5 SCAR=34.0
Pod documented
888 0 my @args = @_;
889 0 for( @args )
890 {
891 0 ▶ next if( ref( $_ ) && !overload::Method( $_, '""' ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ and not overload::Method($_, "\"\"") 0 0 0
Condition0%0/3
ref $_ and not overload::Method($_, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ and not overload::Method($_, "\"\"")
ref $_ not overload::Method($_, "\"\"")
Truth table0%0/3
A and not(B)
A= ref $_B= not overload::Method($_, "\"\"")
ABresult
0X0
100
111
892 0 ▶ $_ .= "\n" unless( /\n$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless /\n$/ 0 0 0
893 }
894 0 return( $self->write( @args ) );
895 }
896  
897 sub _check_list_of_nodes_or_text
898 {
899 0 ▶ my $self = shift( @_ );
Subroutine _check_list_of_nodes_or_text: not called CC=6 SCAR=37.4
900 # If a HTML::Object::DOM::DocumentFragment object is provided, its children are
901 # copied to the list and its own children array is emptied.
902 0 my $list = $self->_get_from_list_of_elements_or_html( @_ );
903 0 ▶ return( $list ) if( $list->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $list->is_empty 0 0 0
904 0 my $html = $self->documentElement;
905 0 foreach my $e ( @$list )
906 {
907 0 ▶ if( $self->_is_a( $e => 'HTML::Object::DOM::Element' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($e, "HTML::Object::DOM::Element")) 0 0 0
908 {
909 # There can be only one element in the document: the <html> element.
910 0 ▶ if( ref( $html ) )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $html) { } 0 0 0
elsif ($e->tag ne 'html') { } 0 0 0
911 {
912 0 return( $self->error({
913 message => "Cannot have more than one Element child of a Document and it must be an <html> element.",
914 class => 'HTML::Object::HierarchyRequestError',
915 }) );
916 }
917 elsif( $e->tag ne 'html' )
918 {
919 0 return( $self->error({
920 message => "Only the <html> element is allowed inside the Document.",
921 class => 'HTML::Object::HierarchyRequestError',
922 }) );
923 }
924 }
925 }
926 0 return( $list );
927 }
928  
929 sub _init_nodes
930 {
931 459 ▶ my $self = shift( @_ );
Subroutine _init_nodes: called CC=3 SCAR=11.4
932 459 ▶ unless( CORE::exists( $self->{nodes} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"nodes"}) 71 388 459
933 {
934 71 my $children = $self->_set_get_object_array_object( 'children', 'HTML::Object::Element' );
935 71 $self->{nodes} = $children;
936 71 ▶ my $html = $children->grep(sub{ $self->_is_a( $_ => 'HTML::Object::DOM::Node' ) && $_->tag eq 'html' })->first;
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_a($_, "HTML::Object::DOM::Node") and $_->tag eq "html" 33 0 33
937 # We have a document with an <html> tag, we change the children to be an array with just the <html> element
938 # and we set nodes to be the array containing all top nodes.
939 # Maybe, we should change that structural design in the future to make it better
940 71 ▶ if( $html )
Branch: 1 branch
BranchTrueFalseTotal
if ($html) 0 71 71
941 {
942 0 my $new_children = $self->new_array( $html );
943 0 $self->_set_get_object_array_object( 'children', 'HTML::Object::Element', $new_children );
944 }
945 }
946 459 return( $self->{nodes} );
947 }
948  
949 sub _set_get_on_signal : lvalue
950 {
951 0 ▶ my $self = shift( @_ );
Subroutine _set_get_on_signal: not called CC=14 SCAR=53.5
952 0 ▶ my $sigs = shift( @_ ) || return;
Condition0%0/2
shift @_ || (return)
l!l
00
MC/DC0%0/1
shift @_ || (return)
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
953 0 ▶ return if( ref( $sigs ) ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $sigs ne "ARRAY" 0 0 0
954 0 my $has_arg = 0;
955 0 my $arg;
956 0 ▶ if( want( qw( LVALUE ASSIGN ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want(('LVALUE', 'ASSIGN'))) { } 0 0 0
957 {
958 0 ( $arg ) = want( 'ASSIGN' );
959 0 $has_arg = 'assign';
960 }
961 else
962 {
963 0 ▶ @_ = () if( scalar( @_ ) == 1 && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and not defined $_[0] 0 0 0
Condition0%0/3
scalar @_ == 1 and not defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and not defined $_[0]
scalar @_ == 1 not defined $_[0]
Truth table0%0/3
A and not(B)
A= scalar @_ == 1B= not defined $_[0]
ABresult
0X0
100
111
964 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
965 {
966 0 $arg = shift( @_ );
967 0 $has_arg++;
968 }
969 }
970 # To empty it, it must be set to an empty string
971 0 ▶ if( $has_arg && defined( $arg ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_arg and defined $arg) 0 0 0
Condition0%0/3
$has_arg and defined $arg
!ll&&!rl&&r
000
MC/DC0%0/2
$has_arg and defined $arg
$has_arg defined $arg
Truth table0%0/3
A and B
A= $has_argB= defined $arg
ABresult
0X0
100
111
972 {
973 0 my $code = $arg;
974 0 ▶ if( ref( $code ) ne 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $code ne "CODE") 0 0 0
975 {
976 0 my $error = "Value provided is not a code reference (reference to a subroutine or anonymous subroutine).";
977 0 ▶ if( $has_arg eq 'assign' )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_arg eq "assign") 0 0 0
978 {
979 0 $self->error({ message => $error, class => 'HTML::Object::TypeError' });
980 0 return( $self->{__lvalue_error} = undef );
981 }
982 0 ▶ return( $self->error({ message => $error, class => 'HTML::Object::TypeError' }) ) if( want( 'LVALUE' ) );
Branch: 1 branch
BranchTrueFalseTotal
if want("LVALUE") 0 0 0
983 0 Wanted::rreturn( $self->error({ message => $error, class => 'HTML::Object::TypeError' }) );
984 }
985 0 foreach my $sig ( @$sigs )
986 {
987 $SIG{ $sig } = sub
988 {
989 0 ▶ my $type;
Subroutine __ANON__: not called CC=3 SCAR=24.8
990 0 ▶ if( $sig eq '__WARN__' || $sig eq '__DIE__' )
Branch: 1 branch
BranchTrueFalseTotal
if ($sig eq '__WARN__' or $sig eq '__DIE__') { } 0 0 0
Condition0%0/3
$sig eq "__WARN__" or $sig eq "__DIE__"
l!l&&r!l&&!r
000
MC/DC0%0/2
$sig eq "__WARN__" or $sig eq "__DIE__"
$sig eq "__WARN__" $sig eq "__DIE__"
Truth table0%0/3
A or B
A= $sig eq "__WARN__"B= $sig eq "__DIE__"
ABresult
1X1
011
000
991 {
992 0 ( $type = $sig ) =~ s/^__([A-Z]+)__$/$1/;
993 }
994 else
995 {
996 0 $type = shift( @_ );
997 }
998 0 my $event = HTML::Object::ErrorEvent->new( $type, @_ );
999 0 $code->( $event );
1000 0 };
1001 }
1002 }
1003 0 my $dummy = 1;
1004 0 ▶ return( $dummy ) if( want( 'LVALUE' ) );
Branch: 1 branch
BranchTrueFalseTotal
if want("LVALUE") 0 0 0
1005 0 Wanted::rreturn( $dummy );
1006 }
1007  
1008 32 1;
1009 # NOTE: POD
1010 __END__
1011  
1012 =encoding utf-8
1013  
1014 =head1 NAME
1015  
1016 HTML::Object::DOM::Document - HTML Object DOM Document Class
1017  
1018 =head1 SYNOPSIS
1019  
1020 use HTML::Object::DOM::Document;
1021 my $doc = HTML::Object::DOM::Document->new ||
1022 die( HTML::Object::DOM::Document->error, "\n" );
1023  
1024 =head1 VERSION
1025  
1026 v0.3.0
1027  
1028 =head1 DESCRIPTION
1029  
1030 This module represents an HTML document. It inherits from L<HTML::Object::Document> and L<HTML::Object::DOM::Element>
1031  
1032 It is the top object in the hierarchy and thus has no parent. It should contain only one child, the C<html> element, and has one associated L<element|HTML::Object::DOM::Element>, the L<doctype|/doctype>, which can also be accessed with L</declaration>
1033  
1034 =head1 INHERITANCE
1035  
1036 +------------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------+
1037 | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Document |
1038 +------------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------+
1039 | ^
1040 | |
1041 v |
1042 +------------------------+ |
1043 | HTML::Object::Document | -----------------------------------------------------------------------------------------------------------+
1044 +------------------------+
1045  
1046 =head1 PROPERTIES
1047  
1048 =head2 activeElement
1049  
1050 Normally this returns C<undef> under perl, but you can set it to whatever L<element object|HTML::Object::DOM::Element> you want.
1051  
1052 Under JavaScript, this returns the L<element|HTML::Object::DOM::Element> that currently has focus.
1053  
1054 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement>
1055  
1056 =head2 body
1057  
1058 Returns the C<body> L<node object|HTML::Object::Element> of the current document.
1059  
1060 Example:
1061  
1062 # Given this HTML: <body id="oldBodyElement"></body>
1063 say($doc->body->id); # "oldBodyElement"
1064  
1065 my $aNewBodyElement = $doc->createElement("body");
1066  
1067 $aNewBodyElement->id = "newBodyElement";
1068 $doc->body = $aNewBodyElement;
1069 say($doc->body->id); # "newBodyElement"
1070  
1071 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/body>
1072  
1073 =head2 characterSet
1074  
1075 This is read-only.
1076  
1077 Returns the character set being used by the document. This is always C<utf-8>
1078  
1079 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/characterSet>
1080  
1081 =head2 childElementCount
1082  
1083 This is read-only.
1084  
1085 Returns the number of child elements of the current document. This being the top document, it typically contains only 1 element, the C<<html>> tag.
1086  
1087 The total number of children is not the same as the number of child nodes.
1088  
1089 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/childElementCount>
1090  
1091 =head2 children
1092  
1093 This is read-only.
1094  
1095 Returns the child elements of the current document, as an L<array object|Module::Generic::Array>.
1096  
1097 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/children>
1098  
1099 =head2 compatMode
1100  
1101 Returns C<undef> since this is not relevant under perl.
1102  
1103 Normally, it would indicate whether the document is rendered in quirks or strict mode.
1104  
1105 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/compatMode>
1106  
1107 =head2 contentType
1108  
1109 This is read-only.
1110  
1111 Returns the Content-Type from the MIME Header of the current document.
1112  
1113 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/contentType>
1114  
1115 =head2 cookie
1116  
1117 Set or get a semicolon-separated list of the cookies for that document or sets a single cookie.
1118  
1119 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie>
1120  
1121 =head2 currentScript
1122  
1123 Under perl, this does not nor return do anything special, but you can set yourself an L<HTML::Object::DOM::Element>.
1124  
1125 Normally, under JavaScript, this returns the C<currentScript> property returns the <script> element whose script is currently being processed and is not a JavaScript module.
1126  
1127 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript>
1128  
1129 =head2 defaultView
1130  
1131 This returns a reference to the L<window object|HTML::Object::DOM::Window>.
1132  
1133 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/defaultView>
1134  
1135 =head2 designMode
1136  
1137 This always returns true under perl.
1138  
1139 Under the web, with JavaScript, this would get/set the ability to edit the whole document.
1140  
1141 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/designMode>
1142  
1143 =head2 dir
1144  
1145 Get or set directionality (rtl/ltr) of the document.
1146  
1147 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/dir>
1148  
1149 =head2 doctype
1150  
1151 This is read-only.
1152  
1153 Returns the Document Type Definition (DTD) L<object|HTML::Object::Element> of the current document.
1154  
1155 Example:
1156  
1157 my $doctypeObj = $doc->doctype;
1158  
1159 say(
1160 "doctype->name: " . $doctypeObj->name . "\n" +
1161 "doctype->internalSubset: " . $doctypeObj->internalSubset . "\n" +
1162 "doctype->publicId: " . $doctypeObj->publicId . "\n" +
1163 "doctype->systemId: " . $doctypeObj->systemId
1164 );
1165  
1166 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/doctype>
1167  
1168 =head2 documentElement
1169  
1170 This is read-only.
1171  
1172 Returns the L<element|HTML::Object::DOM::Element> that is a direct child of the document. For HTML documents, this is normally the L<HTML Element|HTML::Object::Element> object representing the document's C<<html>> element.
1173  
1174 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/documentElement>
1175  
1176 =head2 documentURI
1177  
1178 Set or get the document location as a string, if any.
1179  
1180 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/documentURI>
1181  
1182 =head2 embeds
1183  
1184 This is read-only.
1185  
1186 Returns a list, as an L<html collection object|HTML::Object::DOM::Collection>, of the embedded <embed> elements within the current document.
1187  
1188 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/embeds>
1189  
1190 =head2 featurePolicy
1191  
1192 Returns C<undef> since this is not relevant under perl.
1193  
1194 Normally, under JavaScript, this would return the FeaturePolicy interface which provides a simple API for introspecting the feature policies applied to a specific document.
1195  
1196 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/featurePolicy>
1197  
1198 =head2 firstElementChild
1199  
1200 This is read-only.
1201  
1202 Returns the first child L<element|HTML::Object::DOM::Element> of the current document.
1203  
1204 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/firstElementChild>
1205  
1206 =head2 fonts
1207  
1208 Returns C<undef> since this is not relevant under perl.
1209  
1210 Normally, it would return the C<FontFaceSet> interface of the current document.
1211  
1212 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/fonts>
1213  
1214 =head2 forms
1215  
1216 This is read-only.
1217  
1218 Returns a list, as an L<html collection object|HTML::Object::DOM::Collection>, of the <form> elements within the current document.
1219  
1220 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/forms>
1221  
1222 =head2 fullscreenElement
1223  
1224 Returns C<undef> since this is not relevant under perl.
1225  
1226 Normally, it would return the element that is currently in full screen mode for this document.
1227  
1228 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/fullscreenElement>
1229  
1230 =head2 head
1231  
1232 This is read-only.
1233  
1234 Returns the L<<head> element|HTML::Object::DOM::Head> of the current document, or C<undef> if there is none.
1235  
1236 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/head>
1237  
1238 =head2 hidden
1239  
1240 Returns C<undef> since this is not relevant under perl.
1241  
1242 Normally, it would return a boolean value indicating if the page is considered hidden or not.
1243  
1244 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/hidden>
1245  
1246 =head2 images
1247  
1248 This is read-only.
1249  
1250 Returns a list, as an L<html collection object|HTML::Object::DOM::Collection>, of the images in the current document.
1251  
1252 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/images>
1253  
1254 =head2 implementation
1255  
1256 This returns the L<DOM implementation object|HTML::Object::DOM::Implementation> associated with the current document.
1257  
1258 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/implementation>
1259  
1260 =head2 lastElementChild
1261  
1262 This is read-only.
1263  
1264 Returns the last child L<element|HTML::Object::DOM::Element> of the current document, which is the root <html> element, the only child of the document.
1265  
1266 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/lastElementChild>
1267  
1268 =head2 lastModified
1269  
1270 This is read-only.
1271  
1272 Returns the date on which the document was last modified, if any, as a L<DateTime> object.
1273  
1274 This value exists if the document was read from a file, and it would contain the file last modification time.
1275  
1276 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/lastModified>
1277  
1278 =head2 links
1279  
1280 This is read-only.
1281  
1282 Returns a list, as an L<html collection object|HTML::Object::DOM::Collection>, of all the hyperlinks in the document.
1283  
1284 Example:
1285  
1286 my $links = $doc->$links;
1287 for( my $i = 0; $i < $links->length; $i++ )
1288 {
1289 my $linkHref = $doc->createTextNode( $links->[$i]->href );
1290 my $lineBreak = $doc->createElement("br");
1291 $doc->body->appendChild( $linkHref );
1292 $doc->body->appendChild( $lineBreak );
1293 }
1294  
1295 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/links>
1296  
1297 =head2 location
1298  
1299 Set or get the URI of the current document. This is the same as L</documentURI>
1300  
1301 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/location>
1302  
1303 =head2 mozSyntheticDocument
1304  
1305 Normally this is returns C<undef> under perl, byt you can set whatever boolean value you want.
1306  
1307 Under JavaScript, this returns a boolean that is true only if this document is synthetic, such as a standalone image, video, audio file, or the like.
1308  
1309 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/mozSyntheticDocument>
1310  
1311 =head2 nodeValue
1312  
1313 This returns or sets the value of the current node.
1314  
1315 For document, element or collection, this returns C<undef> and for attribute, text or comment, this returns the objct value.
1316  
1317 See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeValue>
1318  
1319 =head2 ownerDocument
1320  
1321 Read-only. This always returns C<undef> since this is the top element. This is inherited from L<HTML::Object::DOM::Node>
1322  
1323 =head2 pictureInPictureElement
1324  
1325 Normally this returns C<undef> under perl, but you can set whatever L<element|HTML::Object::DOM::Element> object you want.
1326  
1327 Under JavaScript, this returns C<undef> since this is not relevant under perl.
1328  
1329 Normally, under JavaScript, this would return the Element currently being presented in picture-in-picture mode in this document.
1330  
1331 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/pictureInPictureElement>
1332  
1333 =head2 pictureInPictureEnabled
1334  
1335 Normally this returns C<undef> under perl, but you can set whatever boolean value you want.
1336  
1337 Under JavaScript, this would return true if the picture-in-picture feature is enabled, and false otherwise.
1338  
1339 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/pictureInPictureEnabled>
1340  
1341 =head2 plugins
1342  
1343 Returns always an empty L<collection object|HTML::Object::DOM::Collection> since this is not relevant under perl.
1344  
1345 Normally, under JavaScript, this would return a list, as a collection, of the available plugins.
1346  
1347 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/plugins>
1348  
1349 =head2 pointerLockElement
1350  
1351 Normally this returns C<undef> under perl, but you can set whatever L<element|HTML::Object::DOM::Element> object you want.
1352  
1353 Under JavaScript, this would return the element set as the target for mouse events while the pointer is locked. null if lock is pending, pointer is unlocked, or if the target is in another document.
1354  
1355 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/pointerLockElement>
1356  
1357 =head2 readyState
1358  
1359 This is read-only.
1360  
1361 Returns loading status of the document. This always returns a true value.
1362  
1363 The readyState of a document can be one of following:
1364  
1365 =over 4
1366  
1367 =item B<loading>
1368  
1369 The document is still loading.
1370  
1371 =item B<interactive>
1372  
1373 The document has finished loading and the document has been parsed.
1374  
1375 There is actually no distinction with the following C<complete> state.
1376  
1377 =item B<complete>
1378  
1379 The document and all its resources have finished loading. The state indicates that the load event is about to fire.
1380  
1381 This is actually the same state as C<interactive>
1382  
1383 =back
1384  
1385 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState>
1386  
1387 =head2 referrer
1388  
1389 Set or get the URI of the page that linked to this page.
1390  
1391 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer>
1392  
1393 =head2 scripts
1394  
1395 This is read-only.
1396  
1397 Returns all the L<<script> elements|HTML::Object::DOM::Element::Script> on the document, as a L<collection object|HTML::Object::DOM::Collection>.
1398  
1399 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/scripts>
1400  
1401 =head2 scrollingElement
1402  
1403 Although this is meaningless under perl, you can set or get an L<element object|HTML::Object::DOM::Element> that scrolls the document.
1404  
1405 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/scrollingElement>
1406  
1407 =head2 styleSheets
1408  
1409 This is read-only.
1410  
1411 Returns a list, as an L<array object|Module::Generic::Array>, of L<CSS StyleSheet element objects|HTML::Object::Element> for stylesheets explicitly linked into, or embedded in a document.
1412  
1413 Contrary to the original JavaScript equivalent, this does not return C<CSSStyleSheet> objects, because it would be potentially heavy to parse each css in C<link> and C<style> tags. You could do this yourself by using L<CSS::Object> and looping through each L<element object|HTML::Object::Element> returned. For example:
1414  
1415 $doc->styleSheets->foreach(sub
1416 {
1417 my $e = shift( @_ );
1418 if( $e->tag eq 'link' )
1419 {
1420 my $resp = $ua->get( $e->attr( 'href' ) );
1421 die( $resp->message ) if( $resp->is_error );
1422 my $style = $resp->decoded_content;
1423 my $css = CSS::Object->new;
1424 $css->read_string( $style );
1425 $css->rules->foreach(sub
1426 {
1427 my $rule = shift( @_ );
1428 # more processing
1429 });
1430 }
1431 elsif( $e->tag eq 'style' )
1432 {
1433 my $css = CSS::Object->new;
1434 $css->read_string( $e->text );
1435 $css->rules->foreach(sub
1436 {
1437 my $rule = shift( @_ );
1438 # more processing
1439 });
1440 }
1441 });
1442  
1443 or you can use L<HTML::Object::XQuery/find> with a xpath selector, such as:
1444  
1445 use HTML::Object::XQuery; # Load jQuery style query functions
1446 # $doc is the HTML::Object::Document returned by HTML::Object->parse
1447 my $collection = $doc->findNode( 'link[rel="https://example.org/css/main.css"]' ) ||
1448 die( $doc->error );
1449 $collection->children->foreach(sub
1450 {
1451 # more processing
1452 });
1453  
1454 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/styleSheets>
1455  
1456 =head2 timeline
1457  
1458 Returns C<undef> since this is not relevant under perl.
1459  
1460 Normally, under JavaScript, this would return timeline as a special instance of DocumentTimeline that is automatically created on page load.
1461  
1462 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/timeline>
1463  
1464 =head2 title
1465  
1466 Set or get the title of the current document.
1467  
1468 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/title>
1469  
1470 =head2 URL
1471  
1472 Set or get the document location as a string.
1473  
1474 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/URL>
1475  
1476 =head2 visibilityState
1477  
1478 Normally this returns C<undef> under perl, but you can set whatever string value you want. This returns a L<scalar object|Module::Generic::Scalar>
1479  
1480 Under JavaScript, this would return a string denoting the visibility state of the document. Possible values are visible, hidden, prerender, and unloaded.
1481  
1482 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilityState>
1483  
1484 =head1 METHODS
1485  
1486 =head2 adoptNode
1487  
1488 L</adoptNode> transfers a L<node|HTML::Object::Element> from another document into the method's L<document|HTML::Object::Document>. The adopted L<node|HTML::Object::Element> and its subtree is removed from its original document (if any), and its ownerDocument is changed to the current document. The L<node|HTML::Object::Element> can then be inserted into the current L<document|HTML::Object::Document>.
1489  
1490 Before they can be inserted into the current document, nodes from external documents should either be:
1491  
1492 =over 4
1493  
1494 =item * cloned using L</importNode>; or
1495  
1496 =item * adopted using L</adoptNode>.
1497  
1498 =back
1499  
1500 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/adoptNode>
1501  
1502 =head2 append
1503  
1504 Inserts a set of Node objects or string objects after the last child of the document.
1505  
1506 This is inherited from L<HTML::Object::DOM::Element>
1507  
1508 Example:
1509  
1510 my $html = $doc->createElement( 'html' );
1511 $doc->append( $html );
1512 # HierarchyRequestError: The operation would yield an incorrect node tree.
1513  
1514 # Also
1515  
1516 my $doc = HTML::Object::DOM::Document->new;
1517 my $html = $doc->createElement( 'html');
1518 $doc->append( $html );
1519  
1520 $doc->children; # HTMLCollection [<html>]
1521  
1522 =head2 appendChild
1523  
1524 Provided with one or more nodes and this will add them to the list of this document's children.
1525  
1526 =head2 as_string
1527  
1528 Returns a string representation of this document and all its hierarchy.
1529  
1530 =head2 captureEvents
1531  
1532 See L<HTML::Object::DOM::Window/captureEvents>.
1533  
1534 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/captureEvents>
1535  
1536 =head2 caretRangeFromPoint
1537  
1538 Always returns C<undef> under perl.
1539  
1540 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint>
1541  
1542 =head2 caretPositionFromPoint
1543  
1544 Returns C<undef> since this is not relevant under perl.
1545  
1546 Normally, under JavaScript, this would return a CaretPosition object containing the DOM node containing the caret, and caret's character offset within that node.
1547  
1548 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/caretPositionFromPoint>
1549  
1550 =head2 childNodes
1551  
1552 Returns an L<array object|Module::Generic::Array> of the document child nodes.
1553  
1554 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Node/childNodes>
1555  
1556 =head2 close
1557  
1558 The C<close()> method finishes writing to a document, opened with L</open>.
1559  
1560 Example:
1561  
1562 # Open a document to write to it
1563 $doc->open();
1564  
1565 # Write the content of the document
1566 $doc->write("<p>The one and only content.</p>");
1567  
1568 # Close the document
1569 $doc->close();
1570  
1571 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/close>
1572  
1573 =head2 contentType
1574  
1575 =head2 createAttribute
1576  
1577 Provided with an argument and this creates a new L<attribute object|HTML::Object::Attribute> and returns it.
1578  
1579 The attribute name is converted to lowercase.
1580  
1581 Example:
1582  
1583 my $node = $doc->getElementById( 'div1' );
1584 my $a = $doc->createAttribute( 'my_attrib' );
1585 $a->value = 'newVal';
1586 $node->setAttributeNode( $a );
1587 say( $node->getAttribute( 'my_attrib' ) ); # "newVal"
1588  
1589 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createAttribute>
1590  
1591 =head2 createAttributeNS
1592  
1593 Returns C<undef> since this is not relevant under perl.
1594  
1595 Normally, under JavaScript, this would create a new attribute node in a given namespace and returns it.
1596  
1597 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createAttributeNS>
1598  
1599 =head2 createCDATASection
1600  
1601 Returns C<undef> since this is not relevant under perl.
1602  
1603 Normally, under JavaScript, this would create a new CDATA node and returns it.
1604  
1605 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createCDATASection>
1606  
1607 =head2 createComment
1608  
1609 Creates a new comment node and returns it.
1610  
1611 Example:
1612  
1613 my $comment = $doc->createComment( 'This is a not-so-secret comment in your document' );
1614 $doc->getElementsByTagName( 'div' )->[0]->appendChild( $comment );
1615 say( $doc->as_string );
1616 # <div><!--This is a not-so-secret $comment in your document--></div>
1617  
1618 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createComment>
1619  
1620 =head2 createDocumentFragment
1621  
1622 This create a new L<HTML::Object::DOM::DocumentFragment> object, passing its C<new()> constructor whatever argument was provided.
1623  
1624 It returns the newly instantiated object.
1625  
1626 L<Document fragments|HTML::Object::DOM::DocumentFragment> are L<DOM Node|HTML::Object::DOM::Node> objects which are never part of the main L<DOM tree|HTML::Object::DOM::Document>. The usual use case is to create the document fragment, append elements to the document fragment and then append the document fragment to the L<DOM tree|HTML::Object::DOM::Document>. In the L<DOM tree|HTML::Object::DOM::Document>, the document fragment is replaced by all its children.
1627  
1628 Since the L<document fragment|HTML::Object::DOM::DocumentFragment> is not part of the main L<DOM tree|HTML::Object::DOM::Document>, appending children to it does not affect the main tree.
1629  
1630 Example:
1631  
1632 <ul id="ul"></ul>
1633  
1634 use Module::Generic::Array;
1635 my $element = $doc->getElementById('ul'); # assuming ul exists
1636 my $fragment = $doc->createDocumentFragment();
1637 my $browsers = Module::Generic::Array->new( ['Firefox', 'Chrome', 'Opera',
1638 'Safari', 'Internet Explorer'] );
1639  
1640 $browsers->foreach(sub
1641 {
1642 my $browser = shift( @_ );
1643 my $li = $doc->createElement('li');
1644 $li->textContent = $browser;
1645 $fragment->appendChild( $li );
1646 });
1647  
1648 $element->appendChild( $fragment );
1649  
1650 would yield:
1651  
1652 =over 4
1653  
1654 =item * Firefox
1655  
1656 =item * Chrome
1657  
1658 =item * Opera
1659  
1660 =item * Safari
1661  
1662 =item * Internet Explorer
1663  
1664 =back
1665  
1666 See L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createDocumentFragment>
1667  
1668 =head2 createElement
1669  
1670 Provided with a tag name and this creates a new L<HTML::Object::Element> object that is returned.
1671  
1672 This methods sets an L<error|Module::Generic/error> and returns C<undef> upon error.
1673  
1674 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement>
1675  
1676 =head2 createElementNS
1677  
1678 Returns C<undef> since this is not relevant under perl.
1679  
1680 Normally, under JavaScript, this would create a new element with the given tag name and namespace URI.
1681  
1682 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createElementNS>
1683  
1684 =head2 createEntityReference
1685  
1686 Returns C<undef> since this is not relevant for HTML document. This is used for XML.
1687  
1688 This was used to create a new entity reference object and returns it.
1689  
1690 Example:
1691  
1692 $doc->createEntityReference( '&amp' ); # &
1693  
1694 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createEntityReference>
1695  
1696 =head2 createEvent
1697  
1698 Creates an event object, passing it whatever arguments were provided, and returns it.
1699  
1700 Example:
1701  
1702 my $event = $doc->createEvent( $type );
1703  
1704 # Create the $event.
1705 my $event = $doc->createEvent( 'click' );
1706  
1707 # Define that the event name is 'build'.
1708 $event->initEvent( build => { bubbles => 1 });
1709  
1710 # Listen for the $event.
1711 $elem->addEventListener( build => sub
1712 {
1713 # e->target matches elem
1714 }, { capture => 0 });
1715  
1716 # Target can be any Element or other EventTarget.
1717 $elem->dispatchEvent( $event );
1718  
1719 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createEvent>
1720  
1721 =head2 createExpression
1722  
1723 Compiles an L<HTML::Object::XPath::Expr> which can then be used for (repeated) evaluations. It returns a L<HTML::Object::DOM::XPathResult> object.
1724  
1725 Example:
1726  
1727 my $xpathExpr = $doc->createExpression( $xpathText );
1728 my $result = $xpathExpr->evaluate( $contextNode );
1729  
1730 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createExpression>
1731  
1732 =head2 createNSResolver
1733  
1734 This always returns C<undef> as XML is not used in L<HTML::Object>
1735  
1736 Normally, under JavaScript, this creates an C<XPathNSResolver> object.
1737  
1738 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createNSResolver>
1739  
1740 =head2 createNodeIterator
1741  
1742 Creates a L<HTML::Object::DOM::NodeIterator> object.
1743  
1744 Example:
1745  
1746 use Module::Generic::Array;
1747 my $nodeIterator = $doc->createNodeIterator(
1748 $doc->body,
1749 NodeFilter->SHOW_ELEMENT,
1750 {
1751 sub acceptNode
1752 {
1753 my $node = shift( @_ );
1754 return( $node->nodeName->toLowerCase() == 'p' ? NodeFilter->FILTER_ACCEPT : NodeFilter->FILTER_REJECT;
1755 }
1756 }
1757 );
1758 my $pars = Module::Generic::Array->new;
1759 my $currentNode;
1760  
1761 while( $currentNode = $nodeIterator->nextNode() )
1762 {
1763 $pars->push( $currentNode );
1764 }
1765  
1766 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createNodeIterator>
1767  
1768 =head2 createProcessingInstruction
1769  
1770 Creates a new C<ProcessingInstruction> object.
1771  
1772 Example:
1773  
1774 my $doc = HTML::Object::DOM->new->parseFromString('<foo />', 'application/xml');
1775 my $pi = $doc->createProcessingInstruction('xml-stylesheet', 'href="mycss->css" type="text/css"');
1776  
1777 $doc->insertBefore($pi, $doc->firstChild);
1778  
1779 say( $doc->as_string );
1780 # Displays: <?xml-stylesheet href="mycss->css" type="text/css"?><foo/>
1781  
1782 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createProcessingInstruction>
1783  
1784 =head2 createRange
1785  
1786 This always returns C<undef> under perl.
1787  
1788 Normally, under JavaScript, this creates a C<Range> object.
1789  
1790 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createRange>
1791  
1792 =head2 createTextNode
1793  
1794 Provided with a text, either as a string, or as a list of strings, and this creates a text node.
1795  
1796 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createTextNode>
1797  
1798 =head2 createTouch
1799  
1800 This always returns C<undef> under perl.
1801  
1802 Normally, under JavaScript, this creates a Touch object.
1803  
1804 Also, this feature is deprecated.
1805  
1806 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createTouch>
1807  
1808 =head2 createTouchList
1809  
1810 This always returns C<undef> under perl.
1811  
1812 Normally, under JavaScript, this creates a C<TouchList> object.
1813  
1814 Also, this feature is deprecated.
1815  
1816 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createTouchList>
1817  
1818 =head2 createTreeWalker
1819  
1820 Creates a C<TreeWalker> object.
1821  
1822 Example:
1823  
1824 use HTML::Object::DOM::NodeFilter qw( :all );
1825 my $treeWalker = $doc->createTreeWalker(
1826 $doc->body,
1827 SHOW_ELEMENT,
1828 sub{ return( FILTER_ACCEPT ); },
1829 );
1830  
1831 my $nodeList = Module::Generic::Array->new;
1832 my $currentNode = $treeWalker->currentNode;
1833  
1834 while( $currentNode )
1835 {
1836 $nodeList->push( $currentNode );
1837 $currentNode = $treeWalker->nextNode();
1838 }
1839  
1840 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/createTreeWalker>
1841  
1842 =head2 elementFromPoint
1843  
1844 This always returns C<undef> under perl.
1845  
1846 Normally, under JavaScript, this returns the topmost element at the specified coordinates.
1847  
1848 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint>
1849  
1850 =head2 elementsFromPoint
1851  
1852 This always returns C<undef> under perl.
1853  
1854 Normally, under JavaScript, this returns an array of all elements at the specified coordinates.
1855  
1856 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/elementsFromPoint>
1857  
1858 =head2 enableStyleSheetsForSet
1859  
1860 This always returns C<undef> under perl.
1861  
1862 Normally, under JavaScript, this enables the style sheets for the specified style sheet set.
1863  
1864 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/enableStyleSheetsForSet>
1865  
1866 =head2 evaluate
1867  
1868 Evaluates an L<XPath|HTML::Object::XPath> expression.
1869  
1870 Example:
1871  
1872 my $xpathResult = $doc->evaluate(
1873 $xpathExpression,
1874 $contextNode
1875 );
1876  
1877 my $headings = $doc->evaluate( "/html/body//h2", $document );
1878 # Search the document for all h2 elements.
1879 # The result will likely be an unordered node iterator.
1880 my $thisHeading = $headings->iterateNext();
1881 my $alertText = "Level 2 $headings in this document are:\n";
1882 while( $thisHeading )
1883 {
1884 $alertText .= $thisHeading->textContent . "\n";
1885 $thisHeading = $headings->iterateNext();
1886 }
1887 say( $alertText ); # print the text of all h2 elements
1888  
1889 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/evaluate>
1890  
1891 =head2 execCommand
1892  
1893 This does absolutely nothing and always returns C<undef>.
1894  
1895 This is actually a deprecated feature of the web API.
1896  
1897 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand>
1898  
1899 =head2 exitPictureInPicture
1900  
1901 This always returns C<undef> under perl.
1902  
1903 Normally, under JavaScript, this removes the video from the floating picture-in-picture window back to its original container.
1904  
1905 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/exitPictureInPicture>
1906  
1907 =head2 exitPointerLock
1908  
1909 This always returns C<undef> under perl.
1910  
1911 Normally, under JavaScript, this releases the pointer lock.
1912  
1913 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/exitPointerLock>
1914  
1915 =head2 firstChild
1916  
1917 Returns the first child from the document list of nodes.
1918  
1919 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Node/firstChild>
1920  
1921 =head2 firstElementChild
1922  
1923 =head2 getElementById
1924  
1925 Provided with an element C<id>, and this method returns the corresponding L<element object|HTML::Object::Element>.
1926  
1927 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById>
1928  
1929 =head2 getAnimations
1930  
1931 This always returns C<undef> under perl.
1932  
1933 Normally, under JavaScript, this returns an array of all Animation objects currently in effect, whose target elements are descendants of the document.
1934  
1935 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/getAnimations>
1936  
1937 =head2 getBoxQuads
1938  
1939 This always returns C<undef> under perl.
1940  
1941 Normally, under JavaScript, this returns a list of C<DOMQuad> objects representing the CSS fragments of the node.
1942  
1943 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/getBoxQuads>
1944  
1945 =head2 getElementById
1946  
1947 Provided with a string and this returns an element object whose C<id> attribute matches the string specified.
1948  
1949 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById>
1950  
1951 =head2 getElementsByClassName
1952  
1953 Returns a list of elements with the given class name.
1954  
1955 Example:
1956  
1957 <span class="orange fruit">Orange Fruit</span>
1958 <span class="orange juice">Orange Juice</span>
1959 <span class="apple juice">Apple Juice</span>
1960 <span class="foo bar">Something Random</span>
1961 <textarea id="resultArea" style="width:98%;height:7em"></textarea>
1962  
1963 Another example:
1964  
1965 # getElementsByClassName only selects elements that have both given classes
1966 my $allOrangeJuiceByClass = $doc->getElementsByClassName('orange juice');
1967 my $result = "$doc->getElementsByClassName('orange juice')";
1968 for( my $i=0; $i < $allOrangeJuiceByClass->length; $i++ )
1969 {
1970 $result .= "\n " . $allOrangeJuiceByClass->[$i]->textContent;
1971 }
1972  
1973 # querySelector only selects full complete matches
1974 my $allOrangeJuiceQuery = $doc->querySelectorAll('.orange->juice');
1975 $result += "\n\ndocument->querySelectorAll('.orange->juice')";
1976 for( my $i=0; $i < $allOrangeJuiceQuery->length; $i++ )
1977 {
1978 $result .= "\n " . $allOrangeJuiceQuery->[$i]->textContent;
1979 }
1980  
1981 $doc->getElementById( 'resultArea' )->value = $result;
1982  
1983 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName>
1984  
1985 =head2 getElementsByName
1986  
1987 Returns a L<NodeList|HTML::Object::DOM::NodeList> Collection of elements with a given name attribute in the L<document|HTML::Object::DOM::Element>.
1988  
1989 Example:
1990  
1991 <!DOCTYPE html>
1992 <html lang="en">
1993 <head>
1994 <title>Example: using getElementsByName</title>
1995 </head>
1996 <body>
1997 <input type="hidden" name="up" />
1998 <input type="hidden" name="down" />
1999 </body>
2000 </html>
2001  
2002 my $up_names = $doc->getElementsByName( 'up' );
2003 say( $up_names->[0]->tagName ); # displays "input"
2004  
2005 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByName>
2006  
2007 =head2 getElementsByTagName
2008  
2009 Returns a L<list|HTML::Object::DOM::Collection> of elements with the given tag name.
2010  
2011 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByTagName>
2012  
2013 =head2 getElementsByTagNameNS
2014  
2015 This is merely an alias to L</getElementsByTagName> since there is no support for namespace.
2016  
2017 Normally, under JavaScript, this returns a list of elements with the given tag name and namespace.
2018  
2019 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByTagNameNS>
2020  
2021 =head2 getRootNode
2022  
2023 Returns the current object.
2024  
2025 =head2 getSelection
2026  
2027 This always returns C<undef> under perl.
2028  
2029 Normally, under JavaScript, this returns a C<Selection> object representing the range of text selected by the user, or the current position of the caret.
2030  
2031 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/getSelection>
2032  
2033 =head2 hasChildNodes
2034  
2035 Returns true if the document list of nodes is not empty, false otherwise.
2036  
2037 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Node/hasChildNodes>
2038  
2039 =head2 hasFocus
2040  
2041 Under perl, this always returns true.
2042  
2043 Normally, under JavaScript, this returns a boolean value indicating whether the document or any element inside the document has focus. This method can be used to determine whether the active element in a document has focus.
2044  
2045 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus>
2046  
2047 =head2 hasStorageAccess
2048  
2049 This always returns C<undef> under perl.
2050  
2051 Normally, under JavaScript, this returns a C<Promise> that resolves with a boolean value indicating whether the document has access to its first-party storage.
2052  
2053 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/hasStorageAccess>
2054  
2055 =head2 importNode
2056  
2057 Returns a clone of a node from an external document.
2058  
2059 Example:
2060  
2061 my $iframe = $doc->querySelector( 'iframe' );
2062 my $oldNode = $iframe->contentWindow->document->getElementById( 'myNode' );
2063 my $newNode = $doc->importNode( $oldNode, $true );
2064 $doc->getElementById( 'container' )->appendChild( $newNode );
2065  
2066 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/importNode>
2067  
2068 =head2 insertAfter
2069  
2070 Provided with a node and a reference node and this will insert the node after the reference node.
2071  
2072 It returns the current object upon success, or C<undef> upon L<error|Module::Generic/error>
2073  
2074 Surprisingly enough there is no C<insertAfter> method in the web API, only L</insertBefore>
2075  
2076 =head2 insertBefore
2077  
2078 Provided with a node and a reference node and this will insert the node before the reference node.
2079  
2080 It returns the current object upon success, or C<undef> upon L<error|Module::Generic/error>
2081  
2082 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore>
2083  
2084 =head2 lastChild
2085  
2086 Returns the last child node from the document list of nodes.
2087  
2088 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Node/lastChild>
2089  
2090 =head2 mozSetImageElement
2091  
2092 This always returns C<undef> under perl.
2093  
2094 Normally, under JavaScript, this allows you to change the element being used as the background image for a specified element ID.
2095  
2096 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/mozSetImageElement>
2097  
2098 =head2 nextSibling
2099  
2100 Returns a L<smart undef|Module::Generic/new_null>. This means the return value will depend on what the caller expects. In scalar context it will return C<undef> and an empty list in list context, but if this method is chained, it will return a dummy object to avoid the perl error "method called on an undefined value"
2101  
2102 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Node/nextSibling>
2103  
2104 =head2 normalizeDocument
2105  
2106 Replaces entities, normalizes text nodes, etc.
2107  
2108 This is actually an alias to L<HTML::Object::DOM::Node/normalize>
2109  
2110 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/normalizeDocument>
2111  
2112 =head2 open
2113  
2114 The C<open()> method opens a document for writing and returns the current L<document|HTML::Object::DOM::Document> object.
2115  
2116 This does come with some side effects. For example:
2117  
2118 =over 4
2119  
2120 =item * All event listeners currently registered on the L<document|HTML::Object::DOM::Document>, L<nodes|HTML::Object::DOM::Node> inside the L<document|HTML::Object::DOM::Document>, or the document's L<window|HTML::Object::DOM::Window> are removed.
2121  
2122 =item * All existing L<nodes|HTML::Object::DOM::Node> are removed from the L<document|HTML::Object::DOM::Document>.
2123  
2124 =back
2125  
2126 Example:
2127  
2128 The following simple code opens the document and replaces its content with a number of different HTML fragments, before closing it again.
2129  
2130 my $doc = $parser->parse_data( $html );
2131 $doc->open();
2132 $doc->write("<p>Hello world!</p>");
2133 $doc->write("<p>I am a fish</p>");
2134 $doc->write("<p>The number is 42</p>");
2135 $doc->close();
2136  
2137 An automatic L</open> call happens when L</write> is called after the document has loaded.
2138  
2139 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/open>
2140  
2141 =head2 parentElement
2142  
2143 This interface returns the DOM node's parent Element, or C<undef> if the node either has no parent, or its parent isn't a DOM Element.
2144  
2145 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Node/parentElement>
2146  
2147 =head2 parentNode
2148  
2149 This returns the parent of the specified node in the DOM tree.
2150  
2151 Document and L<DocumentFragment|HTML::Object::DOM::DocumentFragment> nodes can never have a parent, so C<parentNode> will always return C<undef>.
2152  
2153 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Node/parentNode>
2154  
2155 =head2 prepend
2156  
2157 Inserts a set of L<Node|HTML::Object::DOM::Node> objects or string objects before the first child of the document.
2158  
2159 Example:
2160  
2161 my $html = $doc->createElement( 'html' );
2162 $doc->prepend( $html );
2163 # HierarchyRequestError: The operation would yield an incorrect node tree.
2164  
2165 Another example:
2166  
2167 my $doc = HTML::Object::DOM::Document->new;
2168 my $html = $doc->createElement( 'html' );
2169 $doc->prepend( $html );
2170  
2171 $doc->children; # HTMLCollection [<$html>]
2172  
2173 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/prepend>
2174  
2175 =head2 previousSibling
2176  
2177 This returns the node immediately preceding the specified one in its parent's childNodes list, or C<undef> if the specified node is the first in that list.
2178  
2179 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Node/previousSibling>
2180  
2181 =head2 queryCommandEnabled
2182  
2183 This always returns false under perl.
2184  
2185 Normally, under JavaScript, this reports whether or not the specified editor command is enabled by the browser.
2186  
2187 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/queryCommandEnabled>
2188  
2189 =head2 queryCommandIndeterm
2190  
2191 This always returns true under perl.
2192  
2193 Normally, under JavaScript, this returns true if the formatting command is in an indeterminate state on the current range.
2194  
2195 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/queryCommandIndeterm>
2196  
2197 =head2 queryCommandState
2198  
2199 This always returns false under perl.
2200  
2201 Normally, under JavaScript, this returns true if the formatting command has been executed on the current range.
2202  
2203 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/queryCommandState>
2204  
2205 =head2 queryCommandSupported
2206  
2207 This always returns false under perl.
2208  
2209 Normally, under JavaScript, this returns true if the formatting command is supported on the current range.
2210  
2211 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/queryCommandSupported>
2212  
2213 =head2 queryCommandValue
2214  
2215 This always returns C<undef> under perl.
2216  
2217 Normally, under JavaScript, this returns the current value of the current range for a formatting command.
2218  
2219 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/queryCommandValue>
2220  
2221 =head2 querySelector
2222  
2223 Returns the first Element node within the document, in document order, that matches the specified selectors.
2224  
2225 Example:
2226  
2227 <div id="foo\bar"></div>
2228 <div id="foo:bar"></div>
2229  
2230 $doc->querySelector( '#foo\\bar' ); # Match the first div
2231 $doc->querySelector( '#foo\:bar' ); # Match the second div
2232  
2233 my $el = $doc->querySelector(".myclass");
2234  
2235 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector>
2236  
2237 =head2 querySelectorAll
2238  
2239 Returns a list of all the Element nodes within the document that match the specified selectors.
2240  
2241 Example:
2242  
2243 <div class="outer">
2244 <div class="select">
2245 <div class="inner">
2246 </div>
2247 </div>
2248 </div>
2249  
2250 my $inner = $select->querySelectorAll( '.outer .inner' );
2251 $inner->length; # 1, not 0
2252  
2253 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll>
2254  
2255 =head2 releaseCapture
2256  
2257 Releases the current mouse capture if it's on an element in this document.
2258  
2259 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/releaseCapture>
2260  
2261 =head2 releaseEvents
2262  
2263 See L<HTML::Object::DOM::Window/releaseEvents>.
2264  
2265 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/releaseEvents>
2266  
2267 =head2 removeChild
2268  
2269 Provided with a node and this removes a child node from the DOM and returns the removed node.
2270  
2271 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild>
2272  
2273 =head2 replaceChild
2274  
2275 Provided with a C<new> node and and an C<old> node and this will replace the C<old> one by the C<new> one. Note that if the C<new> node is already present somewhere else in the C<DOM>, it is first removed from that position.
2276  
2277 This returns the C<old> node removed.
2278  
2279 See the document in L<HTML::Object::DOM::Node/replaceChild> for more details.
2280  
2281 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Node/replaceChild>
2282  
2283 =head2 replaceChildren
2284  
2285 Replaces the existing children of a document with a specified new set of children.
2286  
2287 Example:
2288  
2289 $doc->replaceChildren();
2290 $doc->children; # HTMLCollection []
2291  
2292 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/replaceChildren>
2293  
2294 =head2 requestStorageAccess
2295  
2296 This always returns C<undef> under perl.
2297  
2298 Normally, under JavaScript, this returns a C<Promise> that resolves if the access to first-party storage was granted, and rejects if access was denied.
2299  
2300 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccess>
2301  
2302 =head2 string_value
2303  
2304 This always return C<undef>.
2305  
2306 =head2 write
2307  
2308 Provided with a list of nodes and this will write them to the body of this document. If the document is already closed, such as when it has already loaded, this will call L</open>, which will cause to empty the document.
2309  
2310 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/write>
2311  
2312 =head2 writeln
2313  
2314 Same as with L</write>, except this will add a new line.
2315  
2316 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/writeln>
2317  
2318 =head1 EVENTS
2319  
2320 There is only limited support for events under perl, but you can trigger yourself any event.
2321  
2322 Event listeners for those events can also be found by prepending C<on> before the event type:
2323  
2324 C<click> event listeners can be set also with C<onclick> method:
2325  
2326 $e->onclick(sub{ # do something });
2327 # or as an lvalue method
2328 $e->onclick = sub{ # do something };
2329  
2330 Below are some key ones, but you can see the full lists on the L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document#events>
2331  
2332 =head2 DOMContentLoaded
2333  
2334 Fired when the document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading.
2335  
2336 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event>
2337  
2338 =head2 readystatechange
2339  
2340 Fired when the readyState attribute of a document has changed.
2341  
2342 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/readystatechange_event>
2343  
2344 =head2 visibilitychange
2345  
2346 Fired when the content of a tab has become visible or has been hidden. Also available via the onvisibilitychange property.
2347  
2348 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilitychange_event>
2349  
2350 =head1 EVENT HANDLERS
2351  
2352 Listen to these events using L<HTML::Object::EventTarget/addEventListener> or by assigning an event listener to the C<oneventname> property of this interface.
2353  
2354 Under perl, few events are actually "fired" by L<HTML::Object::DOM::Document> and L<for the others|https://developer.mozilla.org/en-US/docs/Web/API/Element#events>, nothing prevents you from L<triggering|HTML::Object::EventTarget/dispatchEvent> whatever events you want on any L<element|HTML::Object::DOM::Element>, even private non-standard ones, and set up listeners for them.
2355  
2356 Below are the ones actually "fired" by L<HTML::Object>.
2357  
2358 =head2 onabort
2359  
2360 This takes a code reference (a reference to a subroutine or an anonymous subroutine) as its unique argument.
2361  
2362 The C<onabort> property is the L<event|HTML::Object::Event> handler for processing C<abort> events sent to the perl script.
2363  
2364 It returns C<undef> and sets an C<HTML::Object::TypeError> error if the value provided is not a code reference, i.e. a reference to an existing subroutine or an anonymous subroutine.
2365  
2366 It returns true upon success.
2367  
2368 Upon an abort signal (C<ABRT>, C<INT> or C<TERM>), this will execute the code reference, passing it an L<error event object|HTML::Object::ErrorEvent>
2369  
2370 Example:
2371  
2372 use HTML::Object::DOM;
2373 my $p = HTML::Object::DOM->new;
2374 $doc = $p->parse_data( $some_html_string );
2375 $doc->onabort = sub
2376 {
2377 my $event = shift( @_ );
2378 print( "Oh no: ", $event->trace, "\n" );
2379 };
2380 # or
2381 $doc->onabort = \&exception_handler;
2382  
2383 =head2 onafterscriptexecute
2384  
2385 Under perl, no such event is fired, but you can trigger one yourself.
2386  
2387 This property references a function that fires when a static <script> element finishes executing its script. It does not fire if the element is added dynamically, such as with appendChild().
2388  
2389 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/onafterscriptexecute>
2390  
2391 =head2 onbeforescriptexecute
2392  
2393 Under perl, no such event is fired, but you can trigger one yourself.
2394  
2395 This is fired when the code in a <script> element declared in an HTML document is about to start executing. Does not fire if the element is added dynamically, eg with appendChild().
2396  
2397 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/onbeforescriptexecute>
2398  
2399 =head2 oncopy
2400  
2401 Under perl, no such event is fired, but you can trigger one yourself.
2402  
2403 This represents the event handling code for the copy event.
2404  
2405 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/oncopy>
2406  
2407 =head2 oncut
2408  
2409 Under perl, no such event is fired, but you can trigger one yourself.
2410  
2411 This represents the event handling code for the cut event.
2412  
2413 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/oncut>
2414  
2415 =head2 onerror
2416  
2417 The C<onerror> property is an L<event|HTML::Object::Event> handler that processes error events triggered by a L<perlfunc/warn> or L<perlfunc/die>
2418  
2419 Upon an error signal (C<__WARN__>, or C<__DIE__>), this will execute the code reference, passing it an L<error event object|HTML::Object::ErrorEvent>
2420  
2421 Example:
2422  
2423 use HTML::Object::DOM;
2424 my $p = HTML::Object::DOM->new;
2425 $doc = $p->parse_data( $some_html_string );
2426 $doc->onerror = sub
2427 {
2428 my $event = shift( @_ );
2429 print( "Oh no: ", $event->trace, "\n" );
2430 };
2431 # or
2432 $doc->onerror = \&exception_handler;
2433  
2434 =head2 onfullscreenchange
2435  
2436 Under perl, no such event is fired, but you can trigger one yourself.
2437  
2438 This property is an event handler for the fullscreenchange event that is fired immediately before a document transitions into or out of full-screen mode.
2439  
2440 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/onfullscreenchange>
2441  
2442 =head2 onfullscreenerror
2443  
2444 Under perl, no such event is fired, but you can trigger one yourself.
2445  
2446 This property is an event handler for the fullscreenerror event that is sent to the document when it fails to transition into full-screen mode after a prior call to Element.requestFullscreen().
2447  
2448 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/onfullscreenerror>
2449  
2450 =head2 onload
2451  
2452 The C<onload> property is an event handler for the C<load> event that fires when the initial HTML L<document|HTML::Object::DOM::Document> has been completely loaded and parsed. It is fired after the L</readyState> has changed to C<complete>
2453  
2454 Contrary to the JavaScript environment, under perl, there is obviously no window and thus no difference between the JavaScript L<window load|https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event> event and the L<DOMContentLoaded|https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event> event
2455  
2456 For example:
2457  
2458 $doc->addEventListener( load => sub
2459 {
2460 say( 'Document fully loaded and parsed' );
2461 });
2462  
2463 sub doSomething
2464 {
2465 say( 'Document loaded' );
2466 }
2467  
2468 # Loading has not finished yet
2469 if( $doc->readyState eq 'loading' )
2470 {
2471 $doc->addEventListener( load => \&doSomething );
2472 }
2473 # 'load' has already fired
2474 else
2475 {
2476 doSomething();
2477 }
2478  
2479 Upon execution, a new L<event|HTML::Object::Event> is passed of type C<readstate> and with the C<detail> property having the following data available:
2480  
2481 =over 4
2482  
2483 =item document
2484  
2485 The L<document object|HTML::Object::DOM::Document>
2486  
2487 =item state
2488  
2489 The state of the document parsing.
2490  
2491 =back
2492  
2493 The event C<target> property is also set to the L<document object|HTML::Object::DOM::Document>.
2494  
2495 =head2 onpaste
2496  
2497 Under perl, no such event is fired, but you can trigger one yourself.
2498  
2499 This property interface is an event handler that processes paste events.
2500  
2501 The paste event fires when the user attempts to paste text.
2502  
2503 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/onpaste>
2504  
2505 =head2 onreadystatechange
2506  
2507 The C<onreadystatechange> property is an event handler for the C<readystatechange> event that is fired when the L</readyState> attribute of a L<document|HTML::Object::DOM::Document> has changed.
2508  
2509 There are 3 state: C<loading>, C<interactive> and C<complete> (which is the same, under perl, as C<loading>)
2510  
2511 This event does not bubble and is not cancelable
2512  
2513 Upon execution, a new L<event|HTML::Object::Event> is passed of type C<readstate> and with the C<detail> property having the following data available:
2514  
2515 =over 4
2516  
2517 =item document
2518  
2519 The L<document object|HTML::Object::DOM::Document>
2520  
2521 =item state
2522  
2523 The state of the document parsing.
2524  
2525 =back
2526  
2527 The event C<target> property is also set to the L<document object|HTML::Object::DOM::Document>.
2528  
2529 See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Document/readystatechange_event>
2530  
2531 =head2 onscroll
2532  
2533 Under perl, no such event is fired, but you can trigger one yourself.
2534  
2535 This property interface is an event handler that processes events when the document view or an element has been scrolled, whether by the user, a Web API, or the user agent.
2536  
2537 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onscroll>
2538  
2539 =head2 onselectionchange
2540  
2541 Under perl, no such event is fired, but you can trigger one yourself.
2542  
2543 This is fired when the Selection of a Document is changed. The Selection consists of a starting position and (optionally) a range of HTML nodes from that position. Clicking or starting a selection outside of a text field will generally fire this event.
2544  
2545 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onselectionchange>
2546  
2547 =head2 onvisibilitychange
2548  
2549 Is an event handler representing the code to be called when the visibilitychange event is raised.
2550  
2551 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Document/onvisibilitychange>
2552  
2553 =head2 onwheel
2554  
2555 Under perl, no such event is fired, but you can trigger one yourself.
2556  
2557 This event is fired when the user rotates the mouse (or other pointing device) wheel.
2558  
2559 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onwheel>
2560  
2561 =head1 AUTHOR
2562  
2563 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
2564  
2565 =head1 SEE ALSO
2566  
2567 L<HTML::Object::Document>, L<HTML::Object::DOM::Element>
2568  
2569 L<Mozilla documentation on DOM|https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model>, L<Mozilla documentation on Document object|https://developer.mozilla.org/en-US/docs/Web/API/Document>
2570  
2571 =head1 COPYRIGHT & LICENSE
2572  
2573 Copyright(c) 2021 DEGUEST Pte. Ltd.
2574  
2575 All rights reserved
2576  
2577 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2578  
2579 =cut
« lib/HTML/Object/DOM/Implementation.pm ↑ Summary lib/HTML/Object/DOM/NodeIteratorShared.pm »