lib/HTML/Object/DOM/TreeWalker.pm

filter: Statementstmt 74.2% 95 / 128 Branchbran 37.5% 24 / 64 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 15 / 15 Podpod 100% 6 / 6 totaltotal 65.7% 140 / 213 CC 33 SCAR 28.7
CC
33
Cov
62%
nextSibling
41.5
previousSibling
40.8
lastChild
8.3
CRAP 17.6
« blib/lib/HTML/Object/DOM/Element/Option.pm ↑ Summary blib/lib/HTML/Object/DOM/Document.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/TreeWalker.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2022/01/02
7 ## Modified 2022/09/18
8 ## All rights reserved
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package HTML::Object::DOM::TreeWalker;
15 BEGIN
16 {
17 2 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶ warnings::register_categories( 'HTML::Object' );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶ use parent qw( HTML::Object::DOM::NodeIteratorShared );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 # To import its constants
23 2 ▶ use HTML::Object::DOM::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶ use HTML::Object::DOM::NodeFilter qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 our $VERSION = 'v0.2.0';
26 };
27  
28 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 # Note: method init is inherited
32  
33 # Note: property currentNode
34 sub currentNode
35 {
36 8 ▶ my $self = shift( @_ );
Subroutine currentNode: called CC=1 SCAR=0.0
Pod documented
37 8 my $elems = $self->_elements;
38 8 return( $elems->index( $self->{_pos} ) );
39 }
40  
41 # Note: property expandEntityReferences read-only is inherited
42  
43 # Note: property filter read-only is inherited
44  
45 sub firstChild
46 {
47 3 ▶ my $self = shift( @_ );
Subroutine firstChild: called CC=8 SCAR=21.2
Pod documented
48 3 my $elems = $self->_elements;
49 3 my $this = $elems->index( $self->{_pos} );
50 3 ▶ return( $self->error( "Unable to find the current node at position '$self->{_pos}' in our tree array!" ) ) if( !defined( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this 0 3 3
51 # Only elements can have children
52 3 ▶ return if( $this->nodeType != ELEMENT_NODE );
Branch: 1 branch
BranchTrueFalseTotal
if $this->nodeType != 1 0 3 3
53 3 my $node;
54 3 my $tmpPos = 0;
55 3 my $children = $this->children;
56 3 my $size = $children->size;
57 # We seek the first appropriate first child depending on the value of $whatToShow
58 3 while(1)
59 {
60 5 ▶ last if( $tmpPos > $size );
Branch: 1 branch
BranchTrueFalseTotal
if $tmpPos > $size 0 5 5
61 5 my $tmpNode = $children->index( $tmpPos );
62 5 my $rv = $self->_check_element( $tmpNode );
63 5 ▶ last if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 5 5
64 5 ▶ $tmpPos++, next if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 2 3 5
65 3 $node = $tmpNode;
66 3 last;
67 }
68 3 ▶ return if( !defined( $node ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 3 3
69 3 my $pos = $elems->pos( $node );
70 # Amazingly enough, the first child of this node cannot be found among the list of all nodes in this tree!
71 3 ▶ return if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 3 3
72 3 $self->{_pos} = $pos;
73 3 return( $node );
74 }
75  
76 sub lastChild
77 {
78 1 ▶ my $self = shift( @_ );
Subroutine lastChild: called CC=8 SCAR=21.2
Pod documented
79 1 my $elems = $self->_elements;
80 1 my $this = $elems->index( $self->{_pos} );
81 1 ▶ return( $self->error( "Unable to find the current node at position '$self->{_pos}' in our tree array!" ) ) if( !defined( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this 0 1 1
82 # Only elements can have children
83 1 ▶ return if( $this->nodeType != ELEMENT_NODE );
Branch: 1 branch
BranchTrueFalseTotal
if $this->nodeType != 1 0 1 1
84 1 my $node;
85 1 my $children = $this->children;
86 1 my $tmpPos = $children->size;
87 # We seek the first appropriate first child depending on the value of $whatToShow
88 1 while(1)
89 {
90 2 ▶ last if( $tmpPos < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $tmpPos < 0 0 2 2
91 2 my $tmpNode = $children->index( $tmpPos );
92 2 my $rv = $self->_check_element( $tmpNode );
93 2 ▶ last if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 2 2
94 2 ▶ $tmpPos--, next if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 1 1 2
95 1 $node = $tmpNode;
96 1 last;
97 }
98 1 ▶ return if( !defined( $node ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 1 1
99 1 my $pos = $elems->pos( $node );
100 # Amazingly enough, the last child of this node cannot be found among the list of all nodes in this tree!
101 1 ▶ return if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 1 1
102 1 $self->{_pos} = $pos;
103 1 return( $node );
104 }
105  
106 # Note: method nextNode is inherited
107  
108 sub nextSibling
109 {
110 1 ▶ my $self = shift( @_ );
Subroutine nextSibling: called CC=8 SCAR=37.2
Pod documented
111 1 my $elems = $self->_elements;
112 1 my $this = $elems->index( $self->{_pos} );
113 1 ▶ return( $self->error( "Unable to find the current node at position '$self->{_pos}' in our tree array!" ) ) if( !defined( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this 0 1 1
114 # No need to bother if our current node is the root node. Its siblings are not part of the tree
115 1 ▶ return if( $this eq $self->root );
Branch: 1 branch
BranchTrueFalseTotal
if $this eq $self->root 1 0 1
116 # Get all next siblings
117 0 my $node;
118 0 my $siblings = $this->right;
119 0 my $size = $siblings->size;
120 0 my $tmpPos = 0;
121 # We seek the first appropriate sibling depending on the value of $whatToShow
122 0 while(1)
123 {
124 0 ▶ last if( $tmpPos > $size );
Branch: 1 branch
BranchTrueFalseTotal
if $tmpPos > $size 0 0 0
125 0 my $tmpNode = $siblings->index( $tmpPos );
126 0 my $rv = $self->_check_element( $tmpNode );
127 0 ▶ last if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
128 0 ▶ $tmpPos++, next if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
129 0 $node = $tmpNode;
130 0 last;
131 }
132 0 ▶ return if( !defined( $node ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
133 0 my $pos = $elems->pos( $node );
134 # Amazingly enough, the next sibling of this node cannot be found among the list of all nodes in this tree!
135 0 ▶ return if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
136 0 $self->{_pos} = $pos;
137 0 return( $node );
138 }
139  
140 sub parentNode
141 {
142 1 ▶ my $self = shift( @_ );
Subroutine parentNode: called CC=5 SCAR=16.5
Pod documented
143 1 my $elems = $self->_elements;
144 1 my $this = $elems->index( $self->{_pos} );
145 1 ▶ return( $self->error( "Unable to find the current node at position '$self->{_pos}' in our tree array!" ) ) if( !defined( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this 0 1 1
146 1 my $root = $self->root;
147 # We should not be here in the first place.
148 1 ▶ return if( $this eq $root );
Branch: 1 branch
BranchTrueFalseTotal
if $this eq $root 0 1 1
149 1 my $node = $this->parent;
150 1 ▶ return if( !defined( $node ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 1 1
151 # We cannot go up to the root, but only within the root itself.
152 # return if( $node eq $root );
153 1 my $pos = $elems->pos( $node );
154 # Amazingly enough, the last child of this node cannot be found among the list of all nodes in this tree!
155 1 ▶ return if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 1 1
156 1 $self->{_pos} = $pos;
157 1 return( $node );
158 }
159  
160 # Note: method previousNode is inherited
161  
162 sub previousSibling
163 {
164 1 ▶ my $self = shift( @_ );
Subroutine previousSibling: called CC=8 SCAR=37.1
Pod documented
165 1 my $elems = $self->_elements;
166 1 my $this = $elems->index( $self->{_pos} );
167 1 ▶ return( $self->error( "Unable to find the current node at position '$self->{_pos}' in our tree array!" ) ) if( !defined( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this 0 1 1
168 # No need to bother if our current node is the root node. Its siblings are not part of the tree
169 1 ▶ return if( $this eq $self->root );
Branch: 1 branch
BranchTrueFalseTotal
if $this eq $self->root 1 0 1
170 # Get all previous siblings
171 0 my $node;
172 0 my $siblings = $this->left;
173 0 my $tmpPos = $siblings->size;
174 # We seek the first appropriate sibling depending on the value of $whatToShow
175 0 while(1)
176 {
177 0 ▶ last if( $tmpPos < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $tmpPos < 0 0 0 0
178 0 my $tmpNode = $siblings->index( $tmpPos );
179 0 my $rv = $self->_check_element( $tmpNode );
180 0 ▶ last if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
181 0 ▶ $tmpPos--, next if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
182 0 $node = $tmpNode;
183 0 last;
184 }
185 0 ▶ return if( !defined( $node ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
186 0 my $pos = $elems->pos( $node );
187 # Amazingly enough, the previous sibling of this node cannot be found among the list of all nodes in this tree!
188 0 ▶ return if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
189 0 $self->{_pos} = $pos;
190 0 return( $node );
191 }
192  
193 # Note: property root read-only is inherited
194  
195 # Note: property whatToShow read-only is inherited
196  
197 2 1;
198 # NOTE: POD
199 __END__
200  
201 =encoding utf-8
202  
203 =head1 NAME
204  
205 HTML::Object::DOM::TreeWalker - HTML Object DOM Tree Walker Class
206  
207 =head1 SYNOPSIS
208  
209 With just one argument, this default to search for everything (C<SHOW_ALL>) and to use the default filter, which always returns C<FILTER_ACCEPT>
210  
211 use HTML::Object::DOM::TreeWalker;
212 my $walker = HTML::Object::DOM::TreeWalker->new( $doc->body ) ||
213 die( HTML::Object::DOM::TreeWalker->error );
214  
215 Or, passing an anonymous subroutine as the filter
216  
217 my $nodes = HTML::Object::DOM::TreeWalker->new(
218 $root_node,
219 $what_to_show_bit,
220 sub{ return( FILTER_ACCEPT ); }
221 ) || die( HTML::Object::DOM::TreeWalker->error );
222  
223 Or, passing an hash reference with a property 'acceptNode' whose value is an anonymous subroutine, as the filter
224  
225 my $nodes = HTML::Object::DOM::TreeWalker->new(
226 $root_node,
227 $what_to_show_bit,
228 {
229 acceptNode => sub{ return( FILTER_ACCEPT ); }
230 }
231 ) || die( HTML::Object::DOM::TreeWalker->error );
232  
233 Or, passing an object that implements the method "acceptNode"
234  
235 my $nodes = HTML::Object::DOM::TreeWalker->new(
236 $root_node,
237 $what_to_show_bit,
238 # This object must implement the acceptNode method
239 My::Customer::NodeFilter->new
240 ) || die( HTML::Object::DOM::TreeWalker->error );
241  
242 There is also L<HTML::Object::DOM::TreeWalker>, which performs a somewhat similar function.
243  
244 Choose L<HTML::Object::DOM::NodeIterator> when you only need a simple iterator to filter and browse the selected nodes, and choose L<HTML::Object::DOM::TreeWalker> when you need to access to the node and its siblings.
245  
246 =head1 VERSION
247  
248 v0.2.0
249  
250 =head1 DESCRIPTION
251  
252 The C<TreeWalker> object represents the nodes of a document subtree and a position within them.
253  
254 =head1 PROPERTIES
255  
256 =head2 currentNode
257  
258 Is the L<Node|HTML::Object::DOM::Node> on which the C<TreeWalker> is currently pointing at.
259  
260 Example:
261  
262 use HTML::Object::DOM::NodeFilter qw( :all );
263 my $treeWalker = $doc->createTreeWalker(
264 $doc->body,
265 SHOW_ELEMENT,
266 sub{ return( FILTER_ACCEPT ); }
267 );
268 my $root = $treeWalker->currentNode; # the root element as it is the first element!
269  
270 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker/currentNode>
271  
272 =head2 expandEntityReferences
273  
274 Normally this is read-only, but under perl you can set whatever boolean value you want.
275  
276 Under JavaScript, this is a boolean value indicating if, when discarding an C<EntityReference> its whole sub-tree must be discarded at the same time.
277  
278 Example:
279  
280 use HTML::Object::DOM::NodeFilter qw( :all );
281 my $treeWalker = $doc->createTreeWalker(
282 $doc->body,
283 SHOW_ELEMENT,
284 sub{ return( FILTER_ACCEPT ); },
285 # or
286 # { acceptNode => sub{ return( FILTER_ACCEPT ); } },
287 );
288 my $expand = $treeWalker->expandEntityReferences;
289  
290 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker/expandEntityReferences>
291  
292 =head2 filter
293  
294 Normally this is read-only, but under perl you can set it to a new L<HTML::Object::DOM::NodeFilter> object you want, even after object instantiation.
295  
296 Returns a L<HTML::Object::DOM::NodeFilter> used to select the relevant nodes.
297  
298 Example:
299  
300 use HTML::Object::DOM::NodeFilter qw( :all );
301 my $treeWalker = $doc->createTreeWalker(
302 $doc->body,
303 SHOW_ELEMENT,
304 sub{ return( FILTER_ACCEPT ); },
305 # or
306 # { acceptNode => sub{ return( FILTER_ACCEPT ); } },
307 );
308 my $nodeFilter = $treeWalker->filter;
309  
310 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker/filter>
311  
312 =head2 root
313  
314 Normally this is read-only, but under perl you can set whatever L<node value|HTML::Object::DOM::Node> you want.
315  
316 Returns a L<Node|HTML::Object::DOM::Node> representing the root node as specified when the C<TreeWalker> was created.
317  
318 Example:
319  
320 use HTML::Object::DOM::NodeFilter qw( :all );
321 my $treeWalker = $doc->createTreeWalker(
322 $doc->body,
323 SHOW_ELEMENT,
324 sub{ return( FILTER_ACCEPT ); },
325 # or
326 # { acceptNode => sub{ return( FILTER_ACCEPT ); } },
327 );
328 my $root = $treeWalker->root; # $doc->body in this case
329  
330 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker/root>
331  
332 =head2 whatToShow
333  
334 Normally this is read-only, but under perl you can set whatever number value you want.
335  
336 Returns an unsigned long being a bitmask made of L<constants|/CONSTANTS> describing the types of L<Node|HTML::Object::DOM::Node> that must to be presented. Non-matching nodes are skipped, but their children may be included, if relevant.
337  
338 Possible constant values (exported by L<HTML::Object::DOM::NodeFilter>) are:
339  
340 =over 4
341  
342 =item SHOW_ALL (4294967295)
343  
344 Shows all nodes.
345  
346 =item SHOW_ELEMENT (1)
347  
348 Shows Element nodes.
349  
350 =item SHOW_ATTRIBUTE (2)
351  
352 Shows attribute L<Attribute nodes|HTML::Object::DOM::Attribute>. This is meaningful only when creating a C<TreeWalker> with an L<Attribute node|HTML::Object::DOM::Attribute> as its root; in this case, it means that the L<attribute node|HTML::Object::DOM::Attribute> will appear in the first position of the iteration or traversal. Since attributes are never children of other L<nodes|HTML::Object::DOM::Node>, they do not appear when traversing over the document tree.
353  
354 =item SHOW_TEXT (4)
355  
356 Shows Text nodes.
357  
358 Example:
359  
360 use HTML::Object::DOM::NodeFilter qw( :all );
361 my $treeWalker = $doc->createTreeWalker(
362 $doc->body,
363 ( SHOW_ELEMENT | SHOW_COMMENT | SHOW_TEXT ),
364 sub{ return( FILTER_ACCEPT ); },
365 # or
366 # { acceptNode => sub{ return( FILTER_ACCEPT ); } },
367 );
368 if( ( $treeWalker->whatToShow & SHOW_ALL ) ||
369 ( $treeWalker->whatToShow & SHOW_COMMENT ) )
370 {
371 # $treeWalker will show comments
372 }
373  
374 =item SHOW_CDATA_SECTION (8)
375  
376 Will always returns nothing, because there is no support for xml documents.
377  
378 =item SHOW_ENTITY_REFERENCE (16)
379  
380 Legacy, no more used.
381  
382 =item SHOW_ENTITY (32)
383  
384 Legacy, no more used.
385  
386 =item SHOW_PROCESSING_INSTRUCTION (64)
387  
388 Shows ProcessingInstruction nodes.
389  
390 =item SHOW_COMMENT (128)
391  
392 Shows Comment nodes.
393  
394 =item SHOW_DOCUMENT (256)
395  
396 Shows Document nodes
397  
398 =item SHOW_DOCUMENT_TYPE (512)
399  
400 Shows C<DocumentType> nodes
401  
402 =item SHOW_DOCUMENT_FRAGMENT (1024)
403  
404 Shows L<HTML::Object::DOM::DocumentFragment> nodes.
405  
406 =item SHOW_NOTATION (2048)
407  
408 Legacy, no more used.
409  
410 =item SHOW_SPACE (4096)
411  
412 Show Space nodes. This is a non-standard extension under this perl framework.
413  
414 =back
415  
416 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker/whatToShow>
417  
418 =head1 METHODS
419  
420 =head2 firstChild
421  
422 Moves the current L<Node|HTML::Object::DOM::Node> to the first visible child of the current node, and returns the found child. It also moves the current node to this child. If no such child exists, returns C<undef> and the current node is not changed.
423  
424 Example:
425  
426 my $treeWalker = $doc->createTreeWalker(
427 $doc->body,
428 SHOW_ELEMENT,
429 sub{ return( FILTER_ACCEPT ); },
430 );
431 my $node = $treeWalker->firstChild(); # returns the first child of the root element, or null if none
432  
433 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker/firstChild>
434  
435 =head2 lastChild
436  
437 Moves the current L<Node|HTML::Object::DOM::Node> to the last visible child of the current node, and returns the found child. It also moves the current node to this child. If no such child exists, C<undef> is returned and the current node is not changed.
438  
439 Example:
440  
441 my $treeWalker = $doc->createTreeWalker(
442 $doc->body,
443 SHOW_ELEMENT,
444 sub{ return( FILTER_ACCEPT ); },
445 );
446 my $node = $treeWalker->lastChild(); # returns the last visible child of the root element
447  
448 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker/lastChild>
449  
450 =head2 nextNode
451  
452 Moves the current L<Node|HTML::Object::DOM::Node> to the next visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, returns C<undef> and the current node is not changed.
453  
454 Example:
455  
456 my $treeWalker = $doc->createTreeWalker(
457 $doc->body,
458 SHOW_ELEMENT,
459 sub{ return( FILTER_ACCEPT ); },
460 );
461 my $node = $treeWalker->nextNode(); # returns the first child of root, as it is the next $node in document order
462  
463 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker/nextNode>
464  
465 =head2 nextSibling
466  
467 Moves the current L<Node|HTML::Object::DOM::Node> to its next sibling, if any, and returns the found sibling. If there is no such node, C<undef> is returned and the current node is not changed.
468  
469 Example:
470  
471 my $treeWalker = $doc->createTreeWalker(
472 $doc->body,
473 SHOW_ELEMENT,
474 sub{ return( FILTER_ACCEPT ); },
475 );
476 $treeWalker->firstChild();
477 my $node = $treeWalker->nextSibling(); # returns null if the first child of the root element has no sibling
478  
479 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker/nextSibling>
480  
481 =head2 parentNode
482  
483 Moves the current L<Node|HTML::Object::DOM::Node> to the first visible ancestor node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns C<undef> and the current node is not changed.
484  
485 Example:
486  
487 my $treeWalker = $doc->createTreeWalker(
488 $doc->body,
489 SHOW_ELEMENT,
490 sub{ return( FILTER_ACCEPT ); },
491 );
492 my $node = $treeWalker->parentNode(); # returns null as there is no parent
493  
494 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker/parentNode>
495  
496 =head2 previousNode
497  
498 Moves the current L<Node|HTML::Object::DOM::Node> to the previous visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns C<undef> and the current node is not changed.
499  
500 Example:
501  
502 my $treeWalker = $doc->createTreeWalker(
503 $doc->body,
504 SHOW_ELEMENT,
505 sub{ return( FILTER_ACCEPT ); },
506 );
507 my $node = $treeWalker->previousNode(); # returns null as there is no parent
508  
509 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker/previousNode>
510  
511 =head2 previousSibling
512  
513 Moves the current L<Node|HTML::Object::DOM::Node> to its previous sibling, if any, and returns the found sibling. If there is no such node, return C<undef> and the current node is not changed.
514  
515 Example:
516  
517 my $treeWalker = $doc->createTreeWalker(
518 $doc->body,
519 SHOW_ELEMENT,
520 sub{ return( FILTER_ACCEPT ); },
521 );
522 my $node = $treeWalker->previousSibling(); # returns null as there is no previous sibiling
523  
524 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker/previousSibling>
525  
526 =head1 AUTHOR
527  
528 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
529  
530 =head1 SEE ALSO
531  
532 L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker>
533  
534 =head1 COPYRIGHT & LICENSE
535  
536 Copyright(c) 2022 DEGUEST Pte. Ltd.
537  
538 All rights reserved
539  
540 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
541  
542 =cut
« blib/lib/HTML/Object/DOM/Element/Option.pm ↑ Summary blib/lib/HTML/Object/DOM/Document.pm »