Object/DOM/Node.pm

filter: Statementstmt 66.8% 355 / 531 Branchbran 48.9% 137 / 280 Conditioncond 33.7% 77 / 228 MC/DCmcdc 6.8% 8 / 117 Subroutinesub 67.3% 66 / 98 Podpod 100% 65 / 65 totaltotal 53.6% 708 / 1319 CC 231 SCAR 42.6
CC
231
Cov
55%
replaceChild
344.2
_list_to_nodes
182.0
appendChild
127.0
CRAP 70.5
« Object/DOM/CharacterData.pm ↑ Summary Object.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Node.pm
3 ## Version v0.3.0_1
4 ## Copyright(c) 2025 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/13
7 ## Modified 2026/03/29
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::Node;
15 BEGIN
16 36 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 36 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 36 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 36 warnings::register_categories( 'HTML::Object' );
20 36 ▶ use parent qw( HTML::Object::EventTarget );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 36 ▶ use vars qw( @EXPORT $XP $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 36 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 36 ▶ use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
24 36 DOCUMENT_POSITION_IDENTICAL => 0,
25 DOCUMENT_POSITION_DISCONNECTED => 1,
26 DOCUMENT_POSITION_PRECEDING => 2,
27 DOCUMENT_POSITION_FOLLOWING => 4,
28 DOCUMENT_POSITION_CONTAINS => 8,
29 DOCUMENT_POSITION_CONTAINED_BY => 16,
30 DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC => 32,
31 XML_DEFAULT_NAMESPACE => 'http://www.w3.org/XML/1998/namespace',
32 ELEMENT_NODE => 1,
33 ATTRIBUTE_NODE => 2,
34 TEXT_NODE => 3,
35 CDATA_SECTION_NODE => 4,
36 # Deprecated
37 ENTITY_REFERENCE_NODE => 5,
38 # Deprecated
39 ENTITY_NODE => 6,
40 PROCESSING_INSTRUCTION_NODE => 7,
41 COMMENT_NODE => 8,
42 DOCUMENT_NODE => 9,
43 DOCUMENT_TYPE_NODE => 10,
44 DOCUMENT_FRAGMENT_NODE => 11,
45 NOTATION_NODE => 12,
46 SPACE_NODE => 13,
47 36 };
48 36 our @EXPORT = qw(
49 DOCUMENT_POSITION_IDENTICAL
50 DOCUMENT_POSITION_DISCONNECTED
51 DOCUMENT_POSITION_PRECEDING
52 DOCUMENT_POSITION_FOLLOWING
53 DOCUMENT_POSITION_CONTAINS
54 DOCUMENT_POSITION_CONTAINED_BY
55 DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
56  
57 ELEMENT_NODE
58 ATTRIBUTE_NODE
59 TEXT_NODE
60 CDATA_SECTION_NODE
61 ENTITY_REFERENCE_NODE
62 ENTITY_NODE
63 PROCESSING_INSTRUCTION_NODE
64 COMMENT_NODE
65 DOCUMENT_NODE
66 DOCUMENT_TYPE_NODE
67 DOCUMENT_FRAGMENT_NODE
68 NOTATION_NODE
69 SPACE_NODE
70 );
71 36 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
72 36 '==' => \&isSameNode,
73 'eq' => \&isSameNode,
74 fallback => 1,
75 36 );
76 36 our $XP;
77 36 our $VERSION = 'v0.3.0_1';
78 };
79  
80 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83 sub init
84 519 ▶{
Subroutine init: called CC=2 SCAR=7.0
Pod documented
85 519 my $self = shift( @_ );
86 519 $self->{_init_strict_use_sub} = 1;
87 519 ▶ $self->HTML::Object::Element::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->HTML::Object::Element::init(@_) or return $self->pass_error 519 0 519
88 519 return( $self );
89 }
90  
91 sub appendChild
92 7 ▶{
Subroutine appendChild: called CC=27 SCAR=48.4
Pod documented
93 7 my $self = shift( @_ );
94 7 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ < 1 0 7 7
95 message => sprintf( "At least 1 arguments is required, but only %d provided.", scalar( @_ ) ),
96 class => 'HTML::Object::TypeError',
97 }) ) if( scalar( @_ ) < 1 );
98 7 my $new = shift( @_ );
99 7 my $new_parent = $new->parent;
100 7 my $parent = $self->parent;
101 # We use 'nodes' rather than 'children' so this works well with HTML::Object::DOM::Document
102 7 my $nodes = $self->nodes;
103 7 ▶ if( $new_parent &&
Branch: 8 branches
BranchTrueFalseTotal
if ($new_parent and not $self->_is_a($new_parent, 'HTML::Object::DOM::Document') and not $self->_is_a($new_parent, 'HTML::Object::DOM::DocumentFragment') and not $self->_is_a($new_parent, 'HTML::Object::DOM::Element')) { } 0 7 7
elsif (not $self->_is_a($new, 'HTML::Object::DOM::DocumentFragment') || $self->_is_a($new, 'HTML::Object::DOM::Declaration') || $self->_is_a($new, 'HTML::Object::DOM::Element') || $self->_is_a($new, 'HTML::Object::DOM::CharacterData')) { } 0 7 7
elsif ($self->lineage->has($new)) { } 0 7 7
elsif ($self->_is_a($new, 'HTML::Object::DOM::Text') || $self->_is_a($new, 'HTML::Object::DOM::Space') and $self->_is_a($new_parent, 'HTML::Object::DOM::Document')) { } 0 7 7
elsif ($self->isa('HTML::Object::DOM::Declaration') and not $self->_is_a($parent, 'HTML::Object::DOM::Document')) { } 0 7 7
elsif ($self->_is_a($parent, 'HTML::Object::DOM::Document') and $self->_is_a($new, 'HTML::Object::DOM::DocumentFragment') and $new->childElementCount > 1 || $new->children->grep(sub { $self->_is_a($_, 'HTML::Object::DOM::Text'); } )->length) { } 0 7 7
elsif ($self->_is_a($parent, 'HTML::Object::DOM::Document') and $parent->childElementCount > 0 and $self->_is_a($new, 'HTML::Object::DOM::Element')) { } 0 7 7
elsif ($self->_is_a($new, 'HTML::Object::DOM::Declaration') and $self->_is_a($nodes->last, 'HTML::Object::DOM::Element')) { } 0 14 14
Condition33%3/9
$new_parent and not $self->_is_a($new_parent, "HTML::Object::DOM::Document") and not $self->_is_a($new_parent, "HTML::Object::DOM::DocumentFragment") and not $self->_is_a($new_parent, "HTML::Object::DOM::Element")
!ll&&!rl&&r
700
$new_parent and not $self->_is_a($new_parent, "HTML::Object::DOM::Document") and not $self->_is_a($new_parent, "HTML::Object::DOM::DocumentFragment")
!ll&&!rl&&r
700
$new_parent and not $self->_is_a($new_parent, "HTML::Object::DOM::Document")
!ll&&!rl&&r
700
MC/DC0%0/4
$new_parent and not $self->_is_a($new_parent, "HTML::Object::DOM::Document") and not $self->_is_a($new_parent, "HTML::Object::DOM::DocumentFragment") and not $self->_is_a($new_parent, "HTML::Object::DOM::Element")
$new_parent not $self->_is_a($new_parent, "HTML::Object::DOM::Document") not $self->_is_a($new_parent, "HTML::Object::DOM::DocumentFragment") not $self->_is_a($new_parent, "HTML::Object::DOM::Element")
Truth table20%1/5
A and not(B) and not(C) and not(D)
A= $new_parentB= not $self->_is_a($new_parent, "HTML::Object::DOM::Document")C= not $self->_is_a($new_parent, "HTML::Object::DOM::DocumentFragment")D= not $self->_is_a($new_parent, "HTML::Object::DOM::Element")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
104 !$self->_is_a( $new_parent => 'HTML::Object::DOM::Document' ) &&
105 !$self->_is_a( $new_parent => 'HTML::Object::DOM::DocumentFragment' ) &&
106 !$self->_is_a( $new_parent => 'HTML::Object::DOM::Element' ) )
107 {
108 0 return( $self->error({
109 message => "Node's parent is not an HTML::Object::DOM::Document, HTML::Object::DOM::DocumentFragment or HTML::Object::DOM::Element object.",
110 class => 'HTML::Object::HierarchyRequestError',
111 }) );
112 }
113 # All other conditions below are strictly similar to replaceChild()
114 ▶ elsif( !$self->_is_a( $new => 'HTML::Object::DOM::DocumentFragment' ) &&
Condition55%5/9
$self->_is_a($new, 'HTML::Object::DOM::DocumentFragment') || $self->_is_a($new, 'HTML::Object::DOM::Declaration') || $self->_is_a($new, 'HTML::Object::DOM::Element') || $self->_is_a($new, 'HTML::Object::DOM::CharacterData')
l!l&&r!l&&!r
610
$self->_is_a($new, "HTML::Object::DOM::DocumentFragment") or $self->_is_a($new, "HTML::Object::DOM::Declaration") or $self->_is_a($new, "HTML::Object::DOM::Element")
l!l&&r!l&&!r
061
$self->_is_a($new, "HTML::Object::DOM::DocumentFragment") or $self->_is_a($new, "HTML::Object::DOM::Declaration")
l!l&&r!l&&!r
007
MC/DC0%0/4
$self->_is_a($new, 'HTML::Object::DOM::DocumentFragment') || $self->_is_a($new, 'HTML::Object::DOM::Declaration') || $self->_is_a($new, 'HTML::Object::DOM::Element') || $self->_is_a($new, 'HTML::Object::DOM::CharacterData')
$self->_is_a($new, "HTML::Object::DOM::DocumentFragment") $self->_is_a($new, "HTML::Object::DOM::Declaration") $self->_is_a($new, "HTML::Object::DOM::Element") $self->_is_a($new, 'HTML::Object::DOM::CharacterData')
Truth table40%2/5
A or B or C || D
A= $self->_is_a($new, "HTML::Object::DOM::DocumentFragment")B= $self->_is_a($new, "HTML::Object::DOM::Declaration")C= $self->_is_a($new, "HTML::Object::DOM::Element")D= $self->_is_a($new, 'HTML::Object::DOM::CharacterData')
ABCDresult
1XXX1
01XX1
001X1
00011
00000
115 !$self->_is_a( $new => 'HTML::Object::DOM::Declaration' ) &&
116 !$self->_is_a( $new => 'HTML::Object::DOM::Element' ) &&
117 !$self->_is_a( $new => 'HTML::Object::DOM::CharacterData' ) )
118 {
119 0 return( $self->error({
120 message => "New node is not an HTML::Object::DOM::DocumentFragment, HTML::Object::DOM::Declaration, HTML::Object::DOM::Element or HTML::Object::DOM::CharacterData object.",
121 class => 'HTML::Object::HierarchyRequestError',
122 }) );
123 }
124 elsif( $self->lineage->has( $new ) )
125 {
126 0 return( $self->error({
127 message => "New node provided is an ancestor of the current node.",
128 class => 'HTML::Object::HierarchyRequestError',
129 }) );
130 }
131 ▶ elsif( ( $self->_is_a( $new => 'HTML::Object::DOM::Text' ) || $self->_is_a( $new => 'HTML::Object::DOM::Space' ) ) &&
Condition66%4/6
$self->_is_a($new, "HTML::Object::DOM::Text") || $self->_is_a($new, "HTML::Object::DOM::Space") and $self->_is_a($new_parent, "HTML::Object::DOM::Document")
!ll&&!rl&&r
610
$self->_is_a($new, "HTML::Object::DOM::Text") or $self->_is_a($new, "HTML::Object::DOM::Space")
l!l&&r!l&&!r
106
MC/DC0%0/3
$self->_is_a($new, "HTML::Object::DOM::Text") || $self->_is_a($new, "HTML::Object::DOM::Space") and $self->_is_a($new_parent, "HTML::Object::DOM::Document")
$self->_is_a($new, "HTML::Object::DOM::Text") $self->_is_a($new, "HTML::Object::DOM::Space") $self->_is_a($new_parent, "HTML::Object::DOM::Document")
Truth table40%2/5
A or B and C
A= $self->_is_a($new, "HTML::Object::DOM::Text")B= $self->_is_a($new, "HTML::Object::DOM::Space")C= $self->_is_a($new_parent, "HTML::Object::DOM::Document")
ABCresult
00X0
1X00
0100
1X11
0111
132 $self->_is_a( $new_parent => 'HTML::Object::DOM::Document' ) )
133 {
134 0 return( $self->error({
135 message => "New node is a HTML::Object::DOM::Text or HTML::Object::DOM::Space node and its parent is a HTML::Object::DOM::Document node.",
136 class => 'HTML::Object::HierarchyRequestError',
137 }) );
138 }
139 ▶ elsif( $self->isa( 'HTML::Object::DOM::Declaration' ) && !$self->_is_a( $parent => 'HTML::Object::DOM::Document' ) )
Condition33%1/3
$self->isa("HTML::Object::DOM::Declaration") and not $self->_is_a($parent, "HTML::Object::DOM::Document")
!ll&&!rl&&r
700
MC/DC0%0/2
$self->isa("HTML::Object::DOM::Declaration") and not $self->_is_a($parent, "HTML::Object::DOM::Document")
$self->isa("HTML::Object::DOM::Declaration") not $self->_is_a($parent, "HTML::Object::DOM::Document")
Truth table33%1/3
A and not(B)
A= $self->isa("HTML::Object::DOM::Declaration")B= not $self->_is_a($parent, "HTML::Object::DOM::Document")
ABresult
0X0
100
111
140 {
141 0 return( $self->error({
142 message => "Current node is a DocumentType, but its parent is not an HTML::Object::DOM::Document object.",
143 class => 'HTML::Object::HierarchyRequestError',
144 }) );
145 }
146 ▶ elsif( $self->_is_a( $parent => 'HTML::Object::DOM::Document' ) &&
Condition22%2/9
$self->_is_a($parent, "HTML::Object::DOM::Document") and $self->_is_a($new, "HTML::Object::DOM::DocumentFragment") and $new->childElementCount > 1 || $new->children->grep(sub { $self->_is_a($_, "HTML::Object::DOM::Text"); } )->length
!ll&&!rl&&r
700
$self->_is_a($parent, "HTML::Object::DOM::Document") and $self->_is_a($new, "HTML::Object::DOM::DocumentFragment")
!ll&&!rl&&r
700
$new->childElementCount > 1 or $new->children->grep(sub { $self->_is_a($_, "HTML::Object::DOM::Text"); } )->length
l!l&&r!l&&!r
000
MC/DC0%0/4
$self->_is_a($parent, "HTML::Object::DOM::Document") and $self->_is_a($new, "HTML::Object::DOM::DocumentFragment") and $new->childElementCount > 1 || $new->children->grep(sub { $self->_is_a($_, "HTML::Object::DOM::Text"); } )->length
$self->_is_a($parent, "HTML::Object::DOM::Document") $self->_is_a($new, "HTML::Object::DOM::DocumentFragment") $new->childElementCount > 1 $new->children->grep(sub { $self->_is_a($_, "HTML::Object::DOM::Text"); } )->length
Truth table20%1/5
A and B and C or D
A= $self->_is_a($parent, "HTML::Object::DOM::Document")B= $self->_is_a($new, "HTML::Object::DOM::DocumentFragment")C= $new->childElementCount > 1D= $new->children->grep(sub { $self->_is_a($_, "HTML::Object::DOM::Text"); } )->length
ABCDresult
0XXX0
10XX0
11000
111X1
11011
147 $self->_is_a( $new => 'HTML::Object::DOM::DocumentFragment' ) &&
148 0 ▶ ( $new->childElementCount > 1 || $new->children->grep(sub{ $self->_is_a( $_ => 'HTML::Object::DOM::Text' ) })->length ) )
Subroutine __ANON__: not called CC=1 SCAR=6.9
149 {
150 0 return( $self->error({
151 message => "Current node parent is a HTML::Object::DOM::Document object and new node is a HTML::Object::DOM::DocumentFragment object that has either more than 1 element or has a HTML::Object::DOM::Text node.",
152 class => 'HTML::Object::HierarchyRequestError',
153 }) );
154 }
155 # This is different from replaceChild()
156 ▶ elsif( $self->_is_a( $parent => 'HTML::Object::DOM::Document' ) &&
Condition33%2/6
$self->_is_a($parent, "HTML::Object::DOM::Document") and $parent->childElementCount > 0 and $self->_is_a($new, "HTML::Object::DOM::Element")
!ll&&!rl&&r
700
$self->_is_a($parent, "HTML::Object::DOM::Document") and $parent->childElementCount > 0
!ll&&!rl&&r
700
MC/DC0%0/3
$self->_is_a($parent, "HTML::Object::DOM::Document") and $parent->childElementCount > 0 and $self->_is_a($new, "HTML::Object::DOM::Element")
$self->_is_a($parent, "HTML::Object::DOM::Document") $parent->childElementCount > 0 $self->_is_a($new, "HTML::Object::DOM::Element")
Truth table25%1/4
A and B and C
A= $self->_is_a($parent, "HTML::Object::DOM::Document")B= $parent->childElementCount > 0C= $self->_is_a($new, "HTML::Object::DOM::Element")
ABCresult
0XX0
10X0
1100
1111
157 $parent->childElementCount > 0 &&
158 $self->_is_a( $new => 'HTML::Object::DOM::Element' ) )
159 {
160 0 return( $self->error({
161 message => "Attempting to replace a child element in a Document with another non HTML-tag element. Document can have only one Element: the HTML-tag element.",
162 class => 'HTML::Object::HierarchyRequestError',
163 }) );
164 }
165 # If the node to append is a doctype and the curent last node is an element, this would put a doctype after an element, which is forbidden
166 ▶ elsif( $self->_is_a( $new => 'HTML::Object::DOM::Declaration' ) &&
Condition33%1/3
$self->_is_a($new, "HTML::Object::DOM::Declaration") and $self->_is_a($nodes->last, "HTML::Object::DOM::Element")
!ll&&!rl&&r
700
MC/DC0%0/2
$self->_is_a($new, "HTML::Object::DOM::Declaration") and $self->_is_a($nodes->last, "HTML::Object::DOM::Element")
$self->_is_a($new, "HTML::Object::DOM::Declaration") $self->_is_a($nodes->last, "HTML::Object::DOM::Element")
Truth table33%1/3
A and B
A= $self->_is_a($new, "HTML::Object::DOM::Declaration")B= $self->_is_a($nodes->last, "HTML::Object::DOM::Element")
ABresult
0X0
100
111
167 $self->_is_a( $nodes->last, 'HTML::Object::DOM::Element' ) )
168 {
169 0 return( $self->error({
170 message => "The last node is an element. Appending the DocumentType would place it after.",
171 class => 'HTML::Object::HierarchyRequestError',
172 }) );
173 }
174  
175 7 $new->detach;
176 7 ▶ my $new_array = $self->new_array( $self->_is_a( $new => 'HTML::Object::DOM::DocumentFragment' ) ? $new->children : $new );
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_a($new, 'HTML::Object::DOM::DocumentFragment') ? : 0 7 7
177 $new_array->foreach(sub
178 7 ▶ {
Subroutine __ANON__: called CC=2 SCAR=7.2
179 7 ▶ return(1) if( !$self->_is_a( $_ => 'HTML::Object::DOM::Node' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($_, "HTML::Object::DOM::Node") 0 7 7
180 7 $_->parent( $self );
181 7 });
182 7 $nodes->push( $new_array->list );
183 7 $self->reset(1);
184 7 ▶ if( $self->_is_a( $new => 'HTML::Object::DOM::DocumentFragment' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($new, "HTML::Object::DOM::DocumentFragment")) 0 7 7
185 {
186 0 $new->children->reset;
187 }
188 7 return( $new );
189 }
190  
191 sub appendNodes
192 0 ▶{
Subroutine appendNodes: not called CC=3 SCAR=24.8
Pod documented
193 0 my $self = shift( @_ );
194 0 my $children = $self->children;
195 0 foreach my $this ( @_ )
196 {
197 0 ▶ if( $self->_is_a( $this => 'HTML::Object::DOM::Node' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($this, "HTML::Object::DOM::Node")) 0 0 0
198 {
199 0 $this->parent( $self );
200 0 $children->push( $this );
201 }
202 }
203 0 return( $self );
204 }
205  
206 # Note: Property
207 # Example: <base href="https://www.example.com/">
208 1 ▶sub baseURI : lvalue { return( shift->_set_get_callback({
Subroutine baseURI: called CC=1 SCAR=1.9
Pod documented
209 get => sub
210 1 ▶ {
Subroutine __ANON__: called CC=9 SCAR=24.1
211 1 my $self = shift( @_ );
212 1 my $root = $self->root;
213 1 ▶ return( $self->new_null ) if( !$root );
Branch: 1 branch
BranchTrueFalseTotal
unless $root 0 1 1
214 1 ▶ return( $self->new_null ) if( !$root->can( 'uri' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $root->can("uri") 0 1 1
215 1 ▶ return( $root->uri ) if( $root->uri );
Branch: 1 branch
BranchTrueFalseTotal
if $root->uri 0 1 1
216 1 my $nodes = $self->findNode( 'base' );
217 1 ▶ return( $self->new_null ) if( $nodes->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $nodes->is_empty 0 1 1
218 1 my $node = $nodes->first;
219 1 ▶ return( $self->new_null ) if( !$node );
Branch: 1 branch
BranchTrueFalseTotal
unless $node 0 1 1
220 1 ▶ return( $self->new_null ) if( !$node->attributes->has( 'href' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $node->attributes->has("href") 0 1 1
221 1 my $uri = $node->attributes->get( 'href' );
222 1 ▶ return( $self->new_null ) if( !defined( $uri ) || !CORE::length( "$uri" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uri and length "$uri" 0 1 1
Condition33%1/3
defined $uri and length "$uri"
!ll&&!rl&&r
001
MC/DC0%0/2
defined $uri and length "$uri"
defined $uri length "$uri"
Truth table33%1/3
A and B
A= defined $uriB= length "$uri"
ABresult
0X0
100
111
223 1 return( $self->_set_get_uri( 'uri', $uri ) );
224 },
225 set => sub
226 0 ▶ {
Subroutine __ANON__: not called CC=6 SCAR=37.4
227 0 my $self = shift( @_ );
228 0 my $uri = shift( @_ );
229 0 my $root = $self->root;
230 0 ▶ return( $self->new_null ) if( !$root );
Branch: 1 branch
BranchTrueFalseTotal
unless $root 0 0 0
231 0 my $nodes = $root->findNode( 'base' );
232 0 my $base;
233 0 ▶ if( $nodes->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
if ($nodes->is_empty) { } 0 0 0
234 {
235 0 ▶ $base = $root->createElement( 'base' ) || return( $self->error( $root->pass_error ) );
Condition0%0/2
$root->createElement('base') || (return $self->error($root->pass_error))
l!l
00
MC/DC0%0/1
$root->createElement('base') || (return $self->error($root->pass_error))
$root->createElement('base')
Truth table0%0/2
A
A= $root->createElement('base')
Aresult
11
00
236 0 ▶ my $head = $root->findNode( 'head' )->first ||
Condition0%0/2
$root->findNode('head')->first || (return $self->error('No base uri can be set, because there is no head element in this document.'))
l!l
00
MC/DC0%0/1
$root->findNode('head')->first || (return $self->error('No base uri can be set, because there is no head element in this document.'))
$root->findNode('head')->first
Truth table0%0/2
A
A= $root->findNode('head')->first
Aresult
11
00
237 return( $self->error( "No base uri can be set, because there is no head element in this document." ) );
238 0 $head->appendChild( $base );
239 }
240 else
241 {
242 0 $base = $nodes->first;
243 }
244 0 ▶ $base->href( $uri ) || return( $self->error( $base->pass_error ) );
Branch: 1 branch
BranchTrueFalseTotal
$base->href($uri) or return $self->error($base->pass_error) 0 0 0
245 0 return( $uri );
246 },
247 1 }, @_ ) ); }
248  
249 5 ▶sub childNodes { return( shift->children ); }
Subroutine childNodes: called CC=1 SCAR=0.0
Pod documented
250  
251 sub cloneNode
252 1 ▶{
Subroutine cloneNode: called CC=1 SCAR=0.0
Pod documented
253 1 my $self = shift( @_ );
254 1 my $clone = $self->clone;
255 1 $clone->parent( undef );
256 1 return( $clone );
257 }
258  
259 sub compareDocumentPosition
260 17 ▶{
Subroutine compareDocumentPosition: called CC=37 SCAR=40.1
Pod documented
261 17 my $self = shift( @_ );
262 17 ▶ my $elem = shift( @_ ) || return( $self->error( "No element was provided to append." ) );
Condition50%1/2
shift @_ || (return $self->error('No element was provided to append.'))
l!l
170
MC/DC0%0/1
shift @_ || (return $self->error('No element was provided to append.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
263 17 ▶ return( $self->error( "Element provided (", overload::StrVal( $elem ), ") is actually not an HTML element." ) ) if( !$self->_is_a( $elem => 'HTML::Object::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($elem, "HTML::Object::Element") 0 17 17
264 # 0 - Elements are identical.
265 # -> DOCUMENT_POSITION_IDENTICAL
266 # 1 - No relationship, both nodes are in different documents or different trees in the same document.
267 # -> DOCUMENT_POSITION_DISCONNECTED
268 # 2 - The specified node precedes the current node.
269 # otherNode precedes the node in either a pre-order depth-first traversal of a tree containing both (e.g., as an ancestor or previous sibling or a descendant of a previous sibling or previous sibling of an ancestor) or (if they are disconnected) in an arbitrary but consistent ordering.
270 # -> DOCUMENT_POSITION_PRECEDING
271 # 4 - The specified node follows the current node.
272 # The otherNode follows the node in either a pre-order depth-first traversal of a tree containing both (e.g., as a descendant or following sibling or a descendant of a following sibling or following sibling of an ancestor) or (if they are disconnected) in an arbitrary but consistent ordering.
273 # -> DOCUMENT_POSITION_FOLLOWING
274 # 8 - The otherNode is an ancestor of / contains the current node.
275 # -> DOCUMENT_POSITION_CONTAINS
276 # 16 - The otherNode is a descendant of / contained by the node.
277 # -> DOCUMENT_POSITION_CONTAINED_BY
278 # 32 - The specified node and the current node have no common container node or the two nodes are different attributes of the same node.
279 # -> DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
280  
281 # "If the two nodes being compared are the same node, then no flags are set on the return."
282 # <https://www.w3.org/TR/DOM-Level-3-Core/core.html#DocumentPosition>
283 17 ▶ return(0) if( Scalar::Util::refaddr( $self ) eq Scalar::Util::refaddr( $elem ) );
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($self) eq builtin::refaddr($elem) 1 16 17
284 # Current object and other element are both attributes of the same element (ownerElement)
285 # "If neither of the two determining node is a child node and nodeType is the same for both determining nodes, then an implementation-dependent order between the determining nodes is returned."
286 # <https://www.w3.org/TR/DOM-Level-3-Core/core.html#DocumentPosition>
287 16 ▶ if( $self->nodeType == ATTRIBUTE_NODE && $elem->nodeType == ATTRIBUTE_NODE )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->nodeType == 2 and $elem->nodeType == 2) 1 15 16
Condition66%2/3
$self->nodeType == 2 and $elem->nodeType == 2
!ll&&!rl&&r
1501
MC/DC50%1/2
$self->nodeType == 2 and $elem->nodeType == 2
$self->nodeType == 2 $elem->nodeType == 2
Truth table66%2/3
A and B
A= $self->nodeType == 2B= $elem->nodeType == 2
ABresult
0X0
100
111
288 {
289 # 2 attributes of the same node
290 1 ▶ return(32) if( $self->ownerElement && $self->ownerElement eq $elem->ownerElement );
Branch: 1 branch
BranchTrueFalseTotal
if $self->ownerElement and $self->ownerElement eq $elem->ownerElement 1 0 1
Condition33%1/3
$self->ownerElement and $self->ownerElement eq $elem->ownerElement
!ll&&!rl&&r
001
MC/DC0%0/2
$self->ownerElement and $self->ownerElement eq $elem->ownerElement
$self->ownerElement $self->ownerElement eq $elem->ownerElement
Truth table33%1/3
A and B
A= $self->ownerElementB= $self->ownerElement eq $elem->ownerElement
ABresult
0X0
100
111
291 }
292  
293 15 my $parent = $self->parent;
294 15 my $parent2 = $elem->parent;
295 # "If neither of the two determining node is a child node and one determining node has a greater value of nodeType than the other, then the corresponding node precedes the other."
296 # <https://www.w3.org/TR/DOM-Level-3-Core/core.html#DocumentPosition>
297 15 ▶ if( !$parent && !$parent2 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($parent or $parent2) 0 15 15
Condition33%1/3
$parent or $parent2
l!l&&r!l&&!r
1500
MC/DC0%0/2
$parent or $parent2
$parent $parent2
Truth table33%1/3
A or B
A= $parentB= $parent2
ABresult
1X1
011
000
298 {
299 0 ▶ return( $self->nodeType < $elem->nodeType ? DOCUMENT_POSITION_FOLLOWING : DOCUMENT_POSITION_PRECEDING );
Branch: 1 branch
BranchTrueFalseTotal
$self->nodeType < $elem->nodeType ? : 0 0 0
300 }
301  
302 15 my $root = $self->root;
303 15 my $root2 = $elem->root;
304 # Both elements are in different documents
305 15 ▶ if( $root ne $root2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($root ne $root2) 1 14 15
306 {
307 1 return( DOCUMENT_POSITION_DISCONNECTED );
308 }
309  
310 14 my $bit = 0;
311 14 my $lineage = $self->lineage;
312 14 my $lineage2 = $elem->lineage;
313 14 my $prev_siblings = $self->left;
314 14 my $next_siblings = $self->right;
315 14 my $seen = {};
316 14 my $crawl;
317 $crawl = sub
318 140 ▶ {
Subroutine __ANON__: called CC=8 SCAR=21.8
319 140 my $kid = shift( @_ );
320 140 my $addr = Scalar::Util::refaddr( $kid );
321 140 ▶ return if( ++$seen->{ $addr } > 1 );
Branch: 1 branch
BranchTrueFalseTotal
if ++$seen->{$addr} > 1 0 140 140
322 140 my $children = $kid->children;
323 140 foreach( @$children )
324 {
325 64 ▶ if( $_->can( 'eid' ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($_->can("eid") and defined $_->eid and defined $elem->eid and $_->eid eq $elem->eid) 2 62 64
Condition66%6/9
$_->can("eid") and defined $_->eid and defined $elem->eid and $_->eid eq $elem->eid
!ll&&!rl&&r
2602
$_->can("eid") and defined $_->eid and defined $elem->eid
!ll&&!rl&&r
0262
$_->can("eid") and defined $_->eid
!ll&&!rl&&r
0064
MC/DC50%2/4
$_->can("eid") and defined $_->eid and defined $elem->eid and $_->eid eq $elem->eid
$_->can("eid") defined $_->eid defined $elem->eid $_->eid eq $elem->eid
Truth table60%3/5
A and B and C and D
A= $_->can("eid")B= defined $_->eidC= defined $elem->eidD= $_->eid eq $elem->eid
ABCDresult
0XXX0
10XX0
110X0
11100
11111
326 defined( $_->eid ) &&
327 defined( $elem->eid ) &&
328 $_->eid eq $elem->eid )
329 {
330 2 return( $_ );
331 }
332 62 ▶ if( my $e = $crawl->( $_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = &$crawl($_)) 0 62 62
333 {
334 0 return( $e );
335 }
336 }
337 138 return;
338 14 };
339  
340 # Check if our parent is among the other element's parents
341 14 my $parent_pos = $lineage2->pos( $parent );
342 # Check if the other element's parent is among our parents
343 14 my $parent2_pos = $lineage->pos( $parent2 );
344 # Then check their position, if found
345 14 ▶ if( defined( $parent_pos ) && defined( $parent2_pos ) )
Branch: 3 branches
BranchTrueFalseTotal
if (defined $parent_pos and defined $parent2_pos) { } 9 5 14
elsif (defined $parent_pos) { } 4 1 5
elsif (defined $parent2_pos) { } 1 0 1
Condition100%3/3
defined $parent_pos and defined $parent2_pos
!ll&&!rl&&r
149
MC/DC100%2/2
defined $parent_pos and defined $parent2_pos
defined $parent_pos defined $parent2_pos
Truth table100%3/3
A and B
A= defined $parent_posB= defined $parent2_pos
ABresult
0X0
100
111
346 {
347 9 ▶ if( $parent_pos > $parent2_pos )
Branch: 2 branches
BranchTrueFalseTotal
if ($parent_pos > $parent2_pos) { } 0 9 9
elsif ($parent2_pos > $parent_pos) { } 0 9 9
348 {
349 0 $bit |= DOCUMENT_POSITION_FOLLOWING;
350 }
351 elsif( $parent2_pos > $parent_pos )
352 {
353 0 $bit |= DOCUMENT_POSITION_PRECEDING;
354 }
355 else
356 {
357 # Nodes share the same parent, and thus are siblings
358 }
359 }
360 elsif( defined( $parent_pos ) )
361 {
362 4 $bit |= DOCUMENT_POSITION_FOLLOWING;
363 }
364 elsif( defined( $parent2_pos ) )
365 {
366 1 $bit |= DOCUMENT_POSITION_PRECEDING;
367 }
368 # Otherwise neither our parent or the other's parent is in either lineage
369 else
370 {
371 # Neither our parent, nor the other's parent is in either lineage.
372 }
373  
374 14 ▶ if( $lineage->intersection( $lineage2 )->is_empty &&
Branch: 1 branch
BranchTrueFalseTotal
if ($lineage->intersection($lineage2)->is_empty and $lineage2->intersection($lineage)->is_empty) { } 0 14 14
Condition33%1/3
$lineage->intersection($lineage2)->is_empty and $lineage2->intersection($lineage)->is_empty
!ll&&!rl&&r
1400
MC/DC0%0/2
$lineage->intersection($lineage2)->is_empty and $lineage2->intersection($lineage)->is_empty
$lineage->intersection($lineage2)->is_empty $lineage2->intersection($lineage)->is_empty
Truth table33%1/3
A and B
A= $lineage->intersection($lineage2)->is_emptyB= $lineage2->intersection($lineage)->is_empty
ABresult
0X0
100
111
375 $lineage2->intersection( $lineage )->is_empty )
376 {
377 0 $bit |= DOCUMENT_POSITION_DISCONNECTED;
378 }
379 else
380 {
381 # Our lineage or the other or both lineages intersect
382 }
383 # Check for the other node in:
384 # 1) ancestor
385 # 2) previous sibling
386 # 3) descendant of previous sibling
387 # 4) previous sibling of an ancestor
388  
389 # "If one of the nodes being compared contains the other node, then the container precedes the contained node, and reversely the contained node follows the container."
390 # <https://www.w3.org/TR/DOM-Level-3-Core/core.html#DocumentPosition>
391 14 ▶ if( $lineage->has( $elem ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($lineage->has($elem)) { } 1 13 14
elsif ($prev_siblings->has($elem)) { } 1 12 13
392 {
393 1 $bit |= DOCUMENT_POSITION_PRECEDING;
394 1 $bit |= DOCUMENT_POSITION_CONTAINS;
395 }
396 # check previous sibling
397 elsif( $prev_siblings->has( $elem ) )
398 {
399 1 $bit |= DOCUMENT_POSITION_PRECEDING;
400 }
401 else
402 {
403 # check for descendant of previous sibling
404 12 $seen = {};
405 12 foreach( @$prev_siblings )
406 {
407 47 ▶ if( my $e = $crawl->( $_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = &$crawl($_)) 1 46 47
408 {
409 1 $bit |= DOCUMENT_POSITION_PRECEDING;
410 1 last;
411 }
412 }
413  
414 # no luck so far. Checking previous sibling of an ancestor
415 12 ▶ if( !( $bit & DOCUMENT_POSITION_PRECEDING ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($bit & 2) 11 1 12
416 {
417 # Go through each ancestor
418 11 foreach( @$lineage )
419 {
420 # then get its previous siblings
421 31 my $ancestor_siblings = $_->left;
422 # and check if the other element is one of them
423 31 ▶ if( $ancestor_siblings && $ancestor_siblings->has( $elem ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($ancestor_siblings and $ancestor_siblings->has($elem)) 0 31 31
Condition33%1/3
$ancestor_siblings and $ancestor_siblings->has($elem)
!ll&&!rl&&r
0310
MC/DC0%0/2
$ancestor_siblings and $ancestor_siblings->has($elem)
$ancestor_siblings $ancestor_siblings->has($elem)
Truth table33%1/3
A and B
A= $ancestor_siblingsB= $ancestor_siblings->has($elem)
ABresult
0X0
100
111
424 {
425 0 $bit |= DOCUMENT_POSITION_PRECEDING;
426 0 last;
427 }
428 }
429 }
430 }
431  
432 # still no luck, check
433 # 1) descendants
434 # 2) following sibling
435 # 3) a descendant of a following sibling
436 # 4) following sibling of an ancestor
437 14 $seen = {};
438 # e.g. a child or an attribute of our element:
439 # "when comparing an element against its own attribute or child, the element node precedes its attribute node and its child node, which both follow it."
440 # <https://www.w3.org/TR/DOM-Level-3-Core/core.html#DocumentPosition>
441 14 ▶ if( $lineage2->has( $self ) )
Branch: 3 branches
BranchTrueFalseTotal
if ($lineage2->has($self)) { } 2 12 14
elsif ($next_siblings->has($elem)) { } 8 4 12
elsif (my $e = &$crawl($self)) { } 0 4 4
442 {
443 2 $bit |= ( DOCUMENT_POSITION_CONTAINED_BY | DOCUMENT_POSITION_FOLLOWING )
444 }
445 # Now check for following siblings
446 elsif( $next_siblings->has( $elem ) )
447 {
448 8 $bit |= DOCUMENT_POSITION_FOLLOWING;
449 }
450 # "If one of the nodes being compared contains the other node, then the container precedes the contained node, and reversely the contained node follows the container."
451 # <https://www.w3.org/TR/DOM-Level-3-Core/core.html#DocumentPosition>
452 # We look deeper than our direct child
453 elsif( my $e = $crawl->( $self ) )
454 {
455 0 $bit |= ( DOCUMENT_POSITION_CONTAINED_BY | DOCUMENT_POSITION_FOLLOWING )
456 }
457 # check for a descendant of a following sibling
458 else
459 {
460 4 $seen = {};
461 4 foreach( @$next_siblings )
462 {
463 27 ▶ if( my $e = $crawl->( $_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = &$crawl($_)) 1 26 27
464 {
465 1 $bit |= DOCUMENT_POSITION_FOLLOWING;
466 1 last;
467 }
468 }
469  
470 # no luck so far. Checking previous sibling of an ancestor
471 4 ▶ if( !( $bit & DOCUMENT_POSITION_FOLLOWING ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($bit & 4) 2 2 4
472 {
473 # Go through each ancestor
474 2 foreach( @$lineage )
475 {
476 # then get its following siblings
477 5 my $ancestor_siblings = $_->right;
478 # and check if the other element is one of them
479 5 ▶ if( $ancestor_siblings && $ancestor_siblings->has( $elem ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($ancestor_siblings and $ancestor_siblings->has($elem)) 0 5 5
Condition66%2/3
$ancestor_siblings and $ancestor_siblings->has($elem)
!ll&&!rl&&r
230
MC/DC0%0/2
$ancestor_siblings and $ancestor_siblings->has($elem)
$ancestor_siblings $ancestor_siblings->has($elem)
Truth table66%2/3
A and B
A= $ancestor_siblingsB= $ancestor_siblings->has($elem)
ABresult
0X0
100
111
480 {
481 0 $bit |= DOCUMENT_POSITION_PRECEDING;
482 0 last;
483 }
484 }
485 }
486 }
487 14 return( $bit );
488 }
489  
490 sub contains
491 2 ▶{
Subroutine contains: called CC=4 SCAR=14.2
Pod documented
492 2 my $self = shift( @_ );
493 2 ▶ my $elem = shift( @_ ) || return( $self->error( "No element was provided to append." ) );
Condition50%1/2
shift @_ || (return $self->error('No element was provided to append.'))
l!l
20
MC/DC0%0/1
shift @_ || (return $self->error('No element was provided to append.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
494 2 ▶ return( $self->error( "Element provided (", overload::StrVal( $elem ), ") is actually not an HTML element." ) ) if( !$self->_is_a( $elem => 'HTML::Object::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($elem, "HTML::Object::Element") 0 2 2
495 # Object and comparison object are the same
496 2 ▶ return(1) if( Scalar::Util::refaddr( $self ) eq Scalar::Util::refaddr( $elem ) );
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($self) eq builtin::refaddr($elem) 0 2 2
497 2 my $found = 0;
498 2 my $seen = {};
499 2 my $traverse;
500 $traverse = sub
501 40 ▶ {
Subroutine __ANON__: called CC=4 SCAR=14.2
502 40 my $e = shift( @_ );
503 40 ▶ return if( !defined( $e ) || !CORE::length( $e ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $e and length $e 0 40 40
Condition33%1/3
defined $e and length $e
!ll&&!rl&&r
0040
MC/DC0%0/2
defined $e and length $e
defined $e length $e
Truth table33%1/3
A and B
A= defined $eB= length $e
ABresult
0X0
100
111
504 40 my $addr = Scalar::Util::refaddr( $e );
505 40 ▶ return if( CORE::exists( $seen->{ $addr } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $seen->{$addr} 0 40 40
506 40 $seen->{ $addr }++;
507 $e->children->foreach(sub
508 40 ▶ {
Subroutine __ANON__: called CC=2 SCAR=6.9
509 40 ▶ if( $_->eid eq $elem->eid )
Branch: 1 branch
BranchTrueFalseTotal
if ($_->eid eq $elem->eid) 2 38 40
510 {
511 2 $found++;
512 2 return(1);
513 }
514 38 return( $traverse->( $_ ) );
515 40 });
516 2 };
517 2 $traverse->( $self );
518 2 return( $found );
519 }
520  
521 # Takes a selector; or
522 # Element object
523 # We alias find to findNode(), because find(9 get redefined by HTML::Object::XQuery and
524 # we need internally to continue to rely on this method
525 3 ▶sub find { return( shift->findNode( @_ ) ); }
Subroutine find: called CC=1 SCAR=0.0
Pod documented
526  
527 sub find_xpath
528 0 ▶{
Subroutine find_xpath: not called CC=1 SCAR=6.9
Pod documented
529 0 my( $self, $path ) = @_;
530 0 return( $self->xp->find( $path, $self ) );
531 }
532  
533 sub findNode
534 21 ▶{
Subroutine findNode: called CC=11 SCAR=38.1
Pod documented
535 21 my $self = shift( @_ );
536 21 my $this = shift( @_ );
537 21 my $opts = $self->_get_args_as_hash( @_ );
538 21 my $results = $self->new_array;
539  
540 21 ▶ if( ref( $this ) && $self->_is_object( $this ) && $this->isa( 'HTML::Object::DOM::Element' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this and $self->_is_object($this) and $this->isa('HTML::Object::DOM::Element')) { } 0 21 21
Condition33%2/6
ref $this and $self->_is_object($this) and $this->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
2100
ref $this and $self->_is_object($this)
!ll&&!rl&&r
2100
MC/DC0%0/3
ref $this and $self->_is_object($this) and $this->isa("HTML::Object::DOM::Element")
ref $this $self->_is_object($this) $this->isa("HTML::Object::DOM::Element")
Truth table25%1/4
A and B and C
A= ref $thisB= $self->_is_object($this)C= $this->isa("HTML::Object::DOM::Element")
ABCresult
0XX0
10X0
1100
1111
541 {
542 0 my $a = $self->new_array( [ $this ] );
543 0 my $lookup;
544 $lookup = sub
545 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
546 0 my $kids = shift( @_ );
547 $kids->foreach(sub
548 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
549 0 my $child = shift( @_ );
550 $a->foreach(sub
551 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
552 0 my $candidate = shift( @_ );
553 0 ▶ if( $child->eid eq $candidate->eid )
Branch: 1 branch
BranchTrueFalseTotal
if ($child->eid eq $candidate->eid) 0 0 0
554 {
555 0 $results->push( $child );
556 # We've added this child. Move to next child.
557 0 return(1);
558 }
559 0 });
560 0 ▶ if( $child->children->length > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($child->children->length > 0) 0 0 0
561 {
562 0 $lookup->( $child->children );
563 }
564 0 });
565 0 };
566 # Wether this is a collection or just an element object, we check our children
567 0 $lookup->( $self->children );
568 }
569 # I am expecting an xpath value
570 else
571 {
572 21 ▶ if( ref( $this ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this and !overload::Overloaded($this) || overload::Overloaded($this) && !overload::Method($this, "\"\"")) 0 21 21
Condition11%1/9
ref $this and !overload::Overloaded($this) || overload::Overloaded($this) && !overload::Method($this, "\"\"")
!ll&&!rl&&r
2100
not overload::Overloaded($this) or overload::Overloaded($this) and not overload::Method($this, "\"\"")
l!l&&r!l&&!r
000
overload::Overloaded($this) and not overload::Method($this, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/4
ref $this and !overload::Overloaded($this) || overload::Overloaded($this) && !overload::Method($this, "\"\"")
ref $this not overload::Overloaded($this) overload::Overloaded($this) not overload::Method($this, "\"\"")
Truth table20%1/5
A and not(B) or C and not(D)
A= ref $thisB= not overload::Overloaded($this)C= overload::Overloaded($this)D= not overload::Method($this, "\"\"")
ABCDresult
0XXX0
100X0
10100
11XX1
10111
573 (
574 !overload::Overloaded( $this ) ||
575 ( overload::Overloaded( $this ) && !overload::Method( $this, '""' ) )
576 ) )
577 {
578 0 return( $self->error( "I was expecting an xpath string, but instead I got '$this'." ) );
579 }
580 21 ▶ my $xpath = $self->_xpath_value( $this, $opts ) || return( $self->pass_error );
Condition50%1/2
$self->_xpath_value($this, $opts) || (return $self->pass_error)
l!l
210
MC/DC0%0/1
$self->_xpath_value($this, $opts) || (return $self->pass_error)
$self->_xpath_value($this, $opts)
Truth table50%1/2
A
A= $self->_xpath_value($this, $opts)
Aresult
11
00
581 # $self->children->foreach(sub
582 # {
583 # my $child = shift( @_ );
584 # return(1) if( !$child->isElementNode );
585 # # Propagate debug value
586 # $child->debug( $self->debug );
587 # try
588 # {
589 # my @nodes = $child->findnodes( $xpath );
590 # # $self->messagef( 4, "%d nodes found under child element '$child' whose tag is '%s' -> '%s'", scalar( @nodes ), $child->tag, join( "', '", map( overload::StrVal( $_ ), @nodes ) ) );
591 # $results->push( @nodes );
592 # }
593 # catch( $e )
594 # {
595 # warn( "Error while calling findnodes on element id \"", $_->id, "\" and tag \"", $_->tag, "\": $e\n" );
596 # }
597 # });
598 # try-catch
599 21 local $@;
600 eval
601 21 {
602 21 my @nodes = $self->findnodes( $xpath );
603 21 $results->push( @nodes );
604 };
605 21 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 21 21
606 {
607 0 ▶ warn( "Error while calling findnodes on element with tag \"", ( $self->tag // '' ), "\": $@\n" );
Condition0%0/2
$self->tag // ""
l!l
00
MC/DC0%0/1
$self->tag // ""
$self->tag
Truth table0%0/2
A
A= $self->tag
Aresult
11
00
608 }
609 }
610 21 return( $results );
611 }
612  
613 sub findnodes
614 20 ▶{
Subroutine findnodes: called CC=1 SCAR=0.0
Pod documented
615 20 my( $self, $path ) = @_;
616 20 return( $self->xp->findnodes( $path, $self ) );
617 }
618  
619 sub findnodes_as_string
620 0 ▶{
Subroutine findnodes_as_string: not called CC=1 SCAR=6.9
Pod documented
621 0 my( $self, $path ) = @_;
622 0 return( $self->xp->findnodes_as_string( $path, $self ) );
623 }
624  
625 sub findnodes_as_strings
626 0 ▶{
Subroutine findnodes_as_strings: not called CC=1 SCAR=6.9
Pod documented
627 0 my( $self, $path ) = @_;
628 0 return( $self->xp->findnodes_as_strings( $path, $self ) );
629 }
630  
631 sub findvalue
632 0 ▶{
Subroutine findvalue: not called CC=1 SCAR=6.9
Pod documented
633 0 my( $self, $path ) = @_;
634 0 return( $self->xp->findvalue( $path, $self ) );
635 }
636  
637 sub findvalues
638 0 ▶{
Subroutine findvalues: not called CC=1 SCAR=6.9
Pod documented
639 0 my( $self, $path ) = @_;
640 0 return( $self->xp->findvalues( $path, $self ) );
641 }
642  
643 # Note: Property
644 6 ▶sub firstChild { return( shift->nodes->first ); }
Subroutine firstChild: called CC=1 SCAR=0.0
Pod documented
645  
646 sub getAttributes
647 28 ▶{
Subroutine getAttributes: called CC=2 SCAR=7.0
Pod documented
648 28 my $self = shift( @_ );
649 28 my $rank = 0;
650 my $a = $self->attributes_sequence->map(sub
651 26 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
652 26 return( $self->new_attribute(
653 name => $_,
654 element => $self,
655 rank => $rank++,
656 value => $self->attributes->get( $_ ),
657 ) );
658 28 });
659 28 ▶ return( wantarray() ? $a->list : $a );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 28 28
660 }
661  
662 sub getChildNodes
663 543 ▶{
Subroutine getChildNodes: called CC=2 SCAR=6.9
Pod documented
664 543 my $self = shift( @_ );
665 543 my $nodes = $self->nodes;
666 543 ▶ return( wantarray() ? $nodes->list : $nodes );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 440 103 543
667 }
668  
669 0 ▶sub getElementById { return; }
Subroutine getElementById: not called CC=1 SCAR=6.9
Pod documented
670  
671 # sub getFirstChild { return; }
672 1 ▶sub getFirstChild { return( shift->nodes->first ); }
Subroutine getFirstChild: called CC=1 SCAR=0.0
Pod documented
673  
674 # sub getLastChild { return; }
675 0 ▶sub getLastChild { return( shift->nodes->last ); }
Subroutine getLastChild: not called CC=1 SCAR=6.9
Pod documented
676  
677 0 ▶sub getName { return; }
Subroutine getName: not called CC=1 SCAR=6.9
Pod documented
678  
679 67 ▶sub getNextSibling { return( shift->nextSibling ); }
Subroutine getNextSibling: called CC=1 SCAR=0.0
Pod documented
680  
681 0 ▶sub getParentNode { return( shift->parent ); }
Subroutine getParentNode: not called CC=1 SCAR=6.9
Pod documented
682  
683 82 ▶sub getPreviousSibling { return( shift->previousSibling ); }
Subroutine getPreviousSibling: called CC=1 SCAR=0.0
Pod documented
684  
685 sub getRootNode
686 10 ▶{
Subroutine getRootNode: called CC=1 SCAR=0.0
Pod documented
687 10 my $self = shift( @_ );
688 # The parent of root is a HTML::Object::Root
689 # that helps getting the tree to mimic a DOM tree
690 # return( $self->root->getParentNode );
691 10 return( $self->root );
692 }
693  
694 1 ▶sub hasChildNodes { return( !shift->nodes->is_empty ); }
Subroutine hasChildNodes: called CC=1 SCAR=0.0
Pod documented
695  
696 sub insertAfter
697 0 ▶{
Subroutine insertAfter: not called CC=9 SCAR=45.0
Pod documented
698 0 my $self = shift( @_ );
699 0 ▶ my $e = shift( @_ ) || return( $self->error( "No node was provided to insert." ) );
Condition0%0/2
shift @_ || (return $self->error('No node was provided to insert.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No node was provided to insert.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
700 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($e, "HTML::Object::DOM::Node") 0 0 0
701 message => "Node provided (" . overload::StrVal( $e ) . ") is not an HTML::Object::DOM::Node.",
702 class => 'HTML::Object::TypeError',
703 }) ) if( !$self->_is_a( $e => 'HTML::Object::DOM::Node' ) );
704 0 my $refNode = shift( @_ );
705 0 my $nodes = $self->nodes;
706 0 my $pos;
707 0 ▶ if( !defined( $refNode ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $refNode) { } 0 0 0
708 {
709 0 $pos = $nodes->size;
710 }
711 else
712 {
713 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($refNode, "HTML::Object::DOM::Node") 0 0 0
714 message => "Reference node provided (" . overload::StrVal( $refNode ) . ") is not an HTML::Object::DOM::Node.",
715 class => 'HTML::Object::TypeError',
716 }) ) if( !$self->_is_a( $refNode => 'HTML::Object::DOM::Node' ) );
717 0 $pos = $nodes->pos( $refNode );
718 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
719 message => "Reference node provided (" . overload::StrVal( $refNode ) . ") is not among the document nodes.",
720 class => 'HTML::Object::HierarchyRequestError',
721 }) ) if( !defined( $pos ) );
722 0 ▶ return( $self->error( "Somehow, position for the reference node returned $pos, but I expected an integer equal or above 0" ) ) if( $pos < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 0 0 0
723 }
724 0 ▶ my $list = $self->new_array( $self->_is_a( $e => 'HTML::Object::DOM::DocumentFragment' ) ? $e->children : $e );
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_a($e, 'HTML::Object::DOM::DocumentFragment') ? : 0 0 0
725 0 $nodes->splice( $pos + 1, 0, $list->list );
726 $list->foreach(sub
727 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
728 0 $_->detach;
729 0 $_->parent( $self );
730 0 });
731 0 $self->reset(1);
732 0 ▶ if( $self->_is_a( $e => 'HTML::Object::DOM::DocumentFragment' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($e, "HTML::Object::DOM::DocumentFragment")) 0 0 0
733 {
734 0 $e->children->reset;
735 }
736 0 return( $e );
737 }
738  
739 sub insertBefore
740 2 ▶{
Subroutine insertBefore: called CC=9 SCAR=23.6
Pod documented
741 2 my $self = shift( @_ );
742 2 ▶ my $e = shift( @_ ) || return( $self->error( "No node was provided to insert." ) );
Condition50%1/2
shift @_ || (return $self->error('No node was provided to insert.'))
l!l
20
MC/DC0%0/1
shift @_ || (return $self->error('No node was provided to insert.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
743 2 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($e, "HTML::Object::DOM::Node") 0 2 2
744 message => "Node provided (" . overload::StrVal( $e ) . ") is not an HTML::Object::DOM::Node.",
745 class => 'HTML::Object::TypeError',
746 }) ) if( !$self->_is_a( $e => 'HTML::Object::DOM::Node' ) );
747 2 my $refNode = shift( @_ );
748 2 my $nodes = $self->nodes;
749 2 my $pos;
750 2 ▶ if( !defined( $refNode ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $refNode) { } 0 2 2
751 {
752 0 $pos = $nodes->length; # set the position to size + 1 to make it equivalent to a push()
753 }
754 else
755 {
756 2 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($refNode, "HTML::Object::DOM::Node") 0 2 2
757 message => "Reference node provided (" . overload::StrVal( $refNode ) . ") is not an HTML::Object::DOM::Node.",
758 class => 'HTML::Object::TypeError',
759 }) ) if( !$self->_is_a( $refNode => 'HTML::Object::DOM::Node' ) );
760 2 $pos = $nodes->pos( $refNode );
761 2 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 2 2
762 message => "Reference node provided (" . overload::StrVal( $refNode ) . ") is not among the document nodes.",
763 class => 'HTML::Object::HierarchyRequestError',
764 }) ) if( !defined( $pos ) );
765 2 ▶ return( $self->error( "Somehow, position for the reference node returned $pos, but I expected an integer equal or above 0" ) ) if( $pos < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 0 2 2
766 }
767 2 ▶ my $list = $self->new_array( $self->_is_a( $e => 'HTML::Object::DOM::DocumentFragment' ) ? $e->children : $e );
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_a($e, 'HTML::Object::DOM::DocumentFragment') ? : 0 2 2
768 2 $nodes->splice( $pos, 0, $list->list );
769 $list->foreach(sub
770 2 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
771 2 $_->detach;
772 2 $_->parent( $self );
773 2 });
774 2 $self->reset(1);
775 2 ▶ if( $self->_is_a( $e => 'HTML::Object::DOM::DocumentFragment' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($e, "HTML::Object::DOM::DocumentFragment")) 0 2 2
776 {
777 0 $e->children->reset;
778 }
779 2 return( $e );
780 }
781  
782 0 ▶sub isAttributeNode { return(0); }
Subroutine isAttributeNode: not called CC=1 SCAR=6.9
Pod documented
783  
784 0 ▶sub isCommentNode { return(0); }
Subroutine isCommentNode: not called CC=1 SCAR=6.9
Pod documented
785  
786 # Note: Property
787 sub isConnected
788 1 ▶{
Subroutine isConnected: called CC=3 SCAR=11.4
Pod documented
789 1 my $self = shift( @_ );
790 1 my $root = $self->root;
791 1 ▶ return( $self->false ) if( !$root );
Branch: 1 branch
BranchTrueFalseTotal
unless $root 0 1 1
792 1 ▶ return( $root->isa( 'HTML::Object::Document' ) ? $self->true : $self->false );
Branch: 1 branch
BranchTrueFalseTotal
$root->isa('HTML::Object::Document') ? : 1 0 1
793 }
794  
795 sub isDefaultNamespace
796 0 ▶{
Subroutine isDefaultNamespace: not called CC=3 SCAR=24.8
Pod documented
797 0 my $self = shift( @_ );
798 0 my $uri = shift( @_ );
799 0 ▶ return( $self->error( "No namespace URI was provided to check." ) ) if( !defined( $uri ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uri 0 0 0
800 0 ▶ if( $self->tag eq 'svg' )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->tag eq 'svg') { } 0 0 0
801 {
802 0 return( $self->attributes->get( 'xmlns' ) eq $uri );
803 }
804 else
805 {
806 0 return( $uri eq "" );
807 }
808 }
809  
810 sub isEqualNode
811 1 ▶{
Subroutine isEqualNode: called CC=7 SCAR=21.4
Pod documented
812 1 my $self = shift( @_ );
813 1 ▶ my $e = shift( @_ ) || return( $self->error( "No html element was provided to check for equality." ) );
Condition50%1/2
shift @_ || (return $self->error('No html element was provided to check for equality.'))
l!l
10
MC/DC0%0/1
shift @_ || (return $self->error('No html element was provided to check for equality.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
814 1 ▶ return( $self->error( "Element provided (", overload::StrVal( $e ), ") is not an HTML::Object::Element." ) ) if( !$self->_is_a( $e => 'HTML::Object::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($e, "HTML::Object::Element") 0 1 1
815 1 ▶ return(0) if( $self->nodeType != $e->nodeType );
Branch: 1 branch
BranchTrueFalseTotal
if $self->nodeType != $e->nodeType 0 1 1
816 1 ▶ return(0) if( $self->children->length != $e->children->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->children->length != $e->children->length 0 1 1
817 1 ▶ return(0) if( $self->attributes_sequence->join( ',' ) ne $e->attributes_sequence->join( ',' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->attributes_sequence->join(",") ne $e->attributes_sequence->join(",") 0 1 1
818 1 my $failed = 0;
819 $self->attributes_sequence->foreach(sub
820 3 ▶ {
Subroutine __ANON__: called CC=2 SCAR=8.4
821 3 my $v1 = $self->attributes->get( $_ );
822 3 my $v2 = $e->attributes->get( $_ );
823 3 ▶ if( $v1 ne $v2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($v1 ne $v2) 0 3 3
824 {
825 0 $failed++;
826 0 return(0);
827 }
828 1 });
829 1 ▶ return(0) if( $failed );
Branch: 1 branch
BranchTrueFalseTotal
if $failed 0 1 1
830 1 return(1);
831 }
832  
833 27 ▶sub isElementNode { return(0); }
Subroutine isElementNode: called CC=1 SCAR=0.0
Pod documented
834  
835 0 ▶sub isNamespaceNode { return(0); }
Subroutine isNamespaceNode: not called CC=1 SCAR=6.9
Pod documented
836  
837 0 ▶sub isPINode { return(0); }
Subroutine isPINode: not called CC=1 SCAR=6.9
Pod documented
838  
839 0 ▶sub isProcessingInstructionNode { return(0); }
Subroutine isProcessingInstructionNode: not called CC=1 SCAR=6.9
Pod documented
840  
841 sub isSameNode
842 131 ▶{
Subroutine isSameNode: called CC=4 SCAR=14.1
Pod documented
843 131 ▶ return(0) if( !defined( $_[1] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 131 131
844 131 ▶ if( !$_[0]->_is_a( $_[1] => 'HTML::Object::DOM::Node' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[0]->_is_a($_[1], "HTML::Object::DOM::Node")) 68 63 131
845 {
846 68 ▶ warn( "Value provided ($_[1]) is not a reference.\n" ) if( $_[0]->_warnings_is_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->_warnings_is_enabled 0 68 68
847 68 return(0);
848 }
849 63 return( Scalar::Util::refaddr( $_[0] ) eq Scalar::Util::refaddr( $_[1] ) );
850 }
851  
852 0 ▶sub isTextNode { return(0); }
Subroutine isTextNode: not called CC=1 SCAR=6.9
Pod documented
853  
854 # Node: Property
855 1 ▶sub lastChild { return( shift->nodes->last ); }
Subroutine lastChild: called CC=1 SCAR=0.0
Pod documented
856  
857 sub lookupNamespaceURI
858 1 ▶{
Subroutine lookupNamespaceURI: called CC=3 SCAR=16.5
Pod documented
859 1 my $self = shift( @_ );
860 1 ▶ my $prefix = shift( @_ ) || return( '' );
Condition50%1/2
shift @_ || (return '')
l!l
01
MC/DC0%0/1
shift @_ || (return '')
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
861 0 ▶ return( XML_DEFAULT_NAMESPACE ) if( lc( $prefix ) eq 'xml' );
Branch: 1 branch
BranchTrueFalseTotal
if lc $prefix eq "xml" 0 0 0
862 0 return( '' );
863 }
864  
865 1 ▶sub lookupPrefix { return; }
Subroutine lookupPrefix: called CC=1 SCAR=0.0
Pod documented
866  
867 sub new_closing
868 0 ▶{
Subroutine new_closing: not called CC=3 SCAR=24.8
Pod documented
869 0 my $self = shift( @_ );
870 0 ▶ $self->_load_class( 'HTML::Object::DOM::Closing' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::Closing") or return $self->pass_error 0 0 0
871 0 ▶ my $e = HTML::Object::DOM::Closing->new( @_ ) ||
Condition0%0/2
'HTML::Object::DOM::Closing'->new(@_) || (return $self->pass_error('HTML::Object::DOM::Closing'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::DOM::Closing'->new(@_) || (return $self->pass_error('HTML::Object::DOM::Closing'->error))
'HTML::Object::DOM::Closing'->new(@_)
Truth table0%0/2
A
A= 'HTML::Object::DOM::Closing'->new(@_)
Aresult
11
00
872 return( $self->pass_error( HTML::Object::DOM::Closing->error ) );
873 0 return( $e );
874 }
875  
876 sub new_comment
877 0 ▶{
Subroutine new_comment: not called CC=3 SCAR=24.8
Pod documented
878 0 my $self = shift( @_ );
879 0 ▶ $self->_load_class( 'HTML::Object::DOM::Comment' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::Comment") or return $self->pass_error 0 0 0
880 0 ▶ my $e = HTML::Object::DOM::Comment->new( @_ ) ||
Condition0%0/2
'HTML::Object::DOM::Comment'->new(@_) || (return $self->pass_error('HTML::Object::DOM::Comment'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::DOM::Comment'->new(@_) || (return $self->pass_error('HTML::Object::DOM::Comment'->error))
'HTML::Object::DOM::Comment'->new(@_)
Truth table0%0/2
A
A= 'HTML::Object::DOM::Comment'->new(@_)
Aresult
11
00
881 return( $self->pass_error( HTML::Object::DOM::Comment->error ) );
882 0 return( $e );
883 }
884  
885 sub new_element
886 0 ▶{
Subroutine new_element: not called CC=3 SCAR=24.8
Pod documented
887 0 my $self = shift( @_ );
888 0 ▶ $self->_load_class( 'HTML::Object::DOM::Element' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::Element") or return $self->pass_error 0 0 0
889 0 ▶ my $e = HTML::Object::DOM::Element->new( @_ ) ||
Condition0%0/2
'HTML::Object::DOM::Element'->new(@_) || (return $self->pass_error('HTML::Object::DOM::Element'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::DOM::Element'->new(@_) || (return $self->pass_error('HTML::Object::DOM::Element'->error))
'HTML::Object::DOM::Element'->new(@_)
Truth table0%0/2
A
A= 'HTML::Object::DOM::Element'->new(@_)
Aresult
11
00
890 return( $self->pass_error( HTML::Object::DOM::Element->error ) );
891 0 return( $e );
892 }
893  
894 sub new_parser
895 0 ▶{
Subroutine new_parser: not called CC=3 SCAR=24.8
Pod documented
896 0 my $self = shift( @_ );
897 0 ▶ $self->_load_class( 'HTML::Object::DOM' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM") or return $self->pass_error 0 0 0
898 0 ▶ my $p = HTML::Object::DOM->new( debug => $self->debug ) ||
Condition0%0/2
'HTML::Object::DOM'->new('debug', $self->debug) || (return $self->pass_error('HTML::Object::DOM'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::DOM'->new('debug', $self->debug) || (return $self->pass_error('HTML::Object::DOM'->error))
'HTML::Object::DOM'->new('debug', $self->debug)
Truth table0%0/2
A
A= 'HTML::Object::DOM'->new('debug', $self->debug)
Aresult
11
00
899 return( $self->pass_error( HTML::Object::DOM->error ) );
900 0 return( $p );
901 }
902  
903 sub new_text
904 0 ▶{
Subroutine new_text: not called CC=3 SCAR=24.8
Pod documented
905 0 my $self = shift( @_ );
906 0 ▶ $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 0 0
907 0 ▶ my $e = HTML::Object::DOM::Text->new( @_ ) ||
Condition0%0/2
'HTML::Object::DOM::Text'->new(@_) || (return $self->pass_error('HTML::Object::DOM::Text'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::DOM::Text'->new(@_) || (return $self->pass_error('HTML::Object::DOM::Text'->error))
'HTML::Object::DOM::Text'->new(@_)
Truth table0%0/2
A
A= 'HTML::Object::DOM::Text'->new(@_)
Aresult
11
00
908 return( $self->pass_error( HTML::Object::DOM::Text->error ) );
909 0 return( $e );
910 }
911  
912 # Note: Property
913 85 ▶sub nextSibling { return( shift->right->first ); }
Subroutine nextSibling: called CC=1 SCAR=0.0
Pod documented
914  
915 # Note: Property
916 sub nodeName
917 67 ▶{
Subroutine nodeName: called CC=3 SCAR=11.2
Pod documented
918 67 my $self = shift( @_ );
919 67 ▶ my $class = ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
6700
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
920 67 my $map =
921 {
922 Comment => '#comment',
923 Document => '#document',
924 DocumentFragment => '#documentFragment',
925 Space => '#space',
926 Text => '#text',
927 };
928 67 my $type = [split( /::/, $class )]->[-1];
929 67 ▶ return( CORE::exists( $map->{ $type } ) ? $map->{ $type } : $self->tag );
Branch: 1 branch
BranchTrueFalseTotal
exists $map->{$type} ? : 12 55 67
930 }
931  
932 # For any nodes except for Document, nodes are the same as children
933 529 ▶sub nodes { return( shift->children( @_ ) ); }
Subroutine nodes: called CC=1 SCAR=0.0
Pod documented
934  
935 # ELEMENT_NODE 1
936 # ATTRIBUTE_NODE 2
937 # TEXT_NODE 3
938 # CDATA_SECTION_NODE 4
939 # PROCESSING_INSTRUCTION_NODE 7
940 # COMMENT_NODE 8
941 # DOCUMENT_NODE 9
942 # DOCUMENT_TYPE_NODE 10
943 # DOCUMENT_FRAGMENT_NODE 11
944 # <https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType>
945 # Note: Property
946 sub nodeType
947 1001 ▶{
Subroutine nodeType: called CC=3 SCAR=11.1
Pod documented
948 1001 my $self = shift( @_ );
949 1001 my $map =
950 [
951 # Document also inherits from Element, so we test it first
952 'HTML::Object::DOM::Document' => DOCUMENT_NODE,
953 'HTML::Object::DOM::Element' => ELEMENT_NODE,
954 'HTML::Object::DOM::Attribute' => ATTRIBUTE_NODE,
955 'HTML::Object::DOM::Text' => TEXT_NODE,
956 # Nothing for CData (4) or Processing Instruction (7)
957 'HTML::Object::DOM::Comment' => COMMENT_NODE,
958 'HTML::Object::DOM::Declaration' => DOCUMENT_TYPE_NODE,
959 'HTML::Object::DOM::DocumentFragment' => DOCUMENT_FRAGMENT_NODE,
960 # We treat space separately, but the DOM normally treats it as text
961 'HTML::Object::DOM::Space' => SPACE_NODE,
962 ];
963  
964 # return( $map->{ [split( /::/, ( ref( $self ) || $self ) )]->[-1] } );
965 1001 ▶ for( my $i = 0; $i < scalar( @$map ); $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$map) 3484 0 3484
966 {
967 3484 my $class = $map->[$i];
968 3484 my $const = $map->[$i + 1];
969 3484 ▶ if( $self->isa( $class ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa($class)) 1001 2483 3484
970 {
971 1001 return( $const );
972 }
973 }
974 0 return;
975 }
976  
977 # Note: Property
978 3 ▶sub nodeValue { return; }
Subroutine nodeValue: called CC=1 SCAR=0.0
Pod documented
979  
980 sub normalize
981 1 ▶{
Subroutine normalize: called CC=1 SCAR=0.0
Pod documented
982 1 my $self = shift( @_ );
983 1 my $process;
984 $process = sub
985 1 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
986 1 my $e = shift( @_ );
987 1 my $new = $self->new_array;
988 1 my $found = '';
989 $e->children->foreach(sub
990 4 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.0
991 4 my $kid = shift( @_ );
992 # text
993 4 ▶ if( $kid->nodeType == 3 )
Branch: 1 branch
BranchTrueFalseTotal
if ($kid->nodeType == 3) { } 3 1 4
994 {
995 3 ▶ if( $found )
Branch: 1 branch
BranchTrueFalseTotal
if ($found) { } 1 2 3
996 {
997 # merge it with previous text element and skip it
998 1 $found->value->append( $kid->value->scalar );
999 # next
1000 1 return(1);
1001 }
1002 # We found a text element. Save it and merge it with siblings, if any
1003 else
1004 {
1005 2 $found = $kid;
1006 }
1007 }
1008 else
1009 {
1010 1 $found = '';
1011 }
1012 3 $new->push( $kid );
1013 1 });
1014 # Set the new children elements array object
1015 1 $e->children( $new );
1016 1 };
1017 1 $process->( $self );
1018 1 return( $self );
1019 }
1020  
1021 # Note: Property
1022 sub ownerDocument
1023 1 ▶{
Subroutine ownerDocument: called CC=1 SCAR=0.0
Pod documented
1024 1 my $self = shift( @_ );
1025 1 my $root = $self->root;
1026 1 return( $root );
1027 }
1028  
1029 3294 ▶sub parent { return( shift->_set_get_object_without_init({
Subroutine parent: called CC=1 SCAR=0.0
Pod documented
1030 3294 field => 'parent',
1031 weaken => 1,
1032 }, 'HTML::Object::DOM::Node', @_ ) ); }
1033  
1034 # Note: Property
1035 10 ▶sub parentNode { return( shift->parent ); }
Subroutine parentNode: called CC=1 SCAR=0.0
Pod documented
1036  
1037 # Note: Property
1038 # "Returns an Element that is the parent of this node. If the node has no parent, or if that parent is not an Element, this property returns null."
1039 sub parentElement
1040 5 ▶{
Subroutine parentElement: called CC=3 SCAR=11.0
Pod documented
1041 5 my $self = shift( @_ );
1042 5 my $parent = $self->parent;
1043 5 ▶ return( $parent ) if( defined( $parent ) && $self->_is_a( $parent => 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent and $self->_is_a($parent, "HTML::Object::DOM::Element") 4 1 5
Condition66%2/3
defined $parent and $self->_is_a($parent, "HTML::Object::DOM::Element")
!ll&&!rl&&r
104
MC/DC50%1/2
defined $parent and $self->_is_a($parent, "HTML::Object::DOM::Element")
defined $parent $self->_is_a($parent, "HTML::Object::DOM::Element")
Truth table66%2/3
A and B
A= defined $parentB= $self->_is_a($parent, "HTML::Object::DOM::Element")
ABresult
0X0
100
111
1044 1 return;
1045 }
1046  
1047 # Note: Property
1048 # The last element of our siblings, is our first element on our left
1049 87 ▶sub previousSibling { return( shift->left->last ); }
Subroutine previousSibling: called CC=1 SCAR=0.0
Pod documented
1050  
1051 sub removeChild
1052 2 ▶{
Subroutine removeChild: called CC=6 SCAR=18.5
Pod documented
1053 2 my $self = shift( @_ );
1054 2 ▶ my $elem = shift( @_ ) || return( $self->error({
Condition50%1/2
shift @_ || (return $self->error({'message', 'No element was provided to remove.', 'class', 'HTML::Object::TypeError'}))
l!l
20
MC/DC0%0/1
shift @_ || (return $self->error({'message', 'No element was provided to remove.', 'class', 'HTML::Object::TypeError'}))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1055 message => "No element was provided to remove.",
1056 class => 'HTML::Object::TypeError'
1057 }) );
1058 2 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($elem, "HTML::Object::Element") 0 2 2
1059 message => "Element provided (" . overload::StrVal( $elem ) . ") is actually not an HTML element.",
1060 class => 'HTML::Object::TypeError'
1061 }) ) if( !$self->_is_a( $elem => 'HTML::Object::Element' ) );
1062 2 my $nodes = $self->nodes;
1063 2 my $pos = $nodes->pos( $elem );
1064 2 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 1 1 2
1065 message => "Node to remove was not found among the current object's children.",
1066 class => 'HTML::Object::NotFoundError',
1067 }) ) if( !defined( $pos ) );
1068 1 $nodes->splice( $pos, 1 );
1069 1 $elem->parent( undef );
1070 # Remove the closing tag also, if there are any.
1071 1 ▶ if( my $close = $elem->close_tag )
Branch: 1 branch
BranchTrueFalseTotal
if (my $close = $elem->close_tag) 1 0 1
1072 {
1073 1 ▶ if( defined( $pos = $nodes->pos( $close ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($pos = $nodes->pos($close))) 0 1 1
1074 {
1075 0 $nodes->splice( $pos, 1 );
1076 }
1077 }
1078 1 $self->reset(1);
1079 1 return( $elem );
1080 }
1081  
1082 sub replaceChild
1083 1 ▶{
Subroutine replaceChild: called CC=37 SCAR=58.4
Pod documented
1084 1 my $self = shift( @_ );
1085 1 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ < 2 0 1 1
1086 message => sprintf( "At least 2 arguments are required, but only %d provided.", scalar( @_ ) ),
1087 class => 'HTML::Object::TypeError',
1088 }) ) if( scalar( @_ ) < 2 );
1089 1 my( $new, $old ) = @_;
1090 1 my $new_parent = $new->parent;
1091 1 my $old_parent = $old->parent;
1092 1 my $parent = $self->parent;
1093 1 ▶ if( !$parent )
Branch: 11 branches
BranchTrueFalseTotal
if (not $parent) { } 0 1 1
elsif (not $old_parent) { } 0 1 1
elsif ($old_parent ne $self) { } 0 1 1
elsif (not $self->_is_a($old_parent, 'HTML::Object::DOM::Document') || $self->_is_a($old_parent, 'HTML::Object::DOM::DocumentFragment') || $self->_is_a($old_parent, 'HTML::Object::DOM::Element')) { } 0 1 1
elsif (not $self->_is_a($new, 'HTML::Object::DOM::DocumentFragment') || $self->_is_a($new, 'HTML::Object::DOM::Declaration') || $self->_is_a($new, 'HTML::Object::DOM::Element') || $self->_is_a($new, 'HTML::Object::DOM::CharacterData')) { } 0 1 1
elsif ($self->lineage->has($new)) { } 0 1 1
elsif ($self->_is_a($new, 'HTML::Object::DOM::Text') || $self->_is_a($new, 'HTML::Object::DOM::Space') and $self->_is_a($new_parent, 'HTML::Object::DOM::Document')) { } 0 1 1
elsif ($self->isa('HTML::Object::DOM::Declaration') and not $self->_is_a($parent, 'HTML::Object::DOM::Document')) { } 0 1 1
elsif ($self->_is_a($parent, 'HTML::Object::DOM::Document') and $self->_is_a($new, 'HTML::Object::DOM::DocumentFragment') and $new->childElementCount > 1 || $new->children->grep(sub { $self->_is_a($_, 'HTML::Object::DOM::Text'); } )->length) { } 0 1 1
elsif ($self->_is_a($parent, 'HTML::Object::DOM::Document') and $parent->childElementCount > 0 and $self->_is_a($new, 'HTML::Object::DOM::Element') and not $self->_is_a($old, 'HTML::Object::DOM::Element') && !$self->_is_a($old, 'HTML::Object::DOM::Element::HTML') && $parent->children->grep(sub { $self->_is_a($_, 'HTML::Object::DOM::Element::HTML'); } )->is_empty && $self->_is_a($new, 'HTML::Object::DOM::Element::HTML') || $self->_is_a($old, 'HTML::Object::DOM::Element::HTML') && $self->_is_a($new, 'HTML::Object::DOM::Element::HTML')) { } 0 1 1
elsif ($self->_is_a($new, 'HTML::Object::DOM::Element') and $self->_is_a($old->previousSibling, 'HTML::Object::DOM::Declaration')) { } 0 1 1
1094 {
1095 0 return( $self->error({
1096 message => "Current node does not have any parent.",
1097 class => 'HTML::Object::HierarchyRequestError',
1098 }) );
1099 }
1100 elsif( !$old_parent )
1101 {
1102 0 return( $self->error({
1103 message => "Old node provided does not have any parent",
1104 class => 'HTML::Object::HierarchyRequestError',
1105 }) );
1106 }
1107 elsif( $old_parent ne $self )
1108 {
1109 0 return( $self->error({
1110 message => "Old node parent is not the current node.",
1111 class => 'HTML::Object::NotFoundError',
1112 }) );
1113 }
1114 ▶ elsif( !$self->_is_a( $old_parent => 'HTML::Object::DOM::Document' ) &&
Condition33%2/6
$self->_is_a($old_parent, 'HTML::Object::DOM::Document') || $self->_is_a($old_parent, 'HTML::Object::DOM::DocumentFragment') || $self->_is_a($old_parent, 'HTML::Object::DOM::Element')
l!l&&r!l&&!r
010
$self->_is_a($old_parent, "HTML::Object::DOM::Document") or $self->_is_a($old_parent, "HTML::Object::DOM::DocumentFragment")
l!l&&r!l&&!r
001
MC/DC0%0/3
$self->_is_a($old_parent, 'HTML::Object::DOM::Document') || $self->_is_a($old_parent, 'HTML::Object::DOM::DocumentFragment') || $self->_is_a($old_parent, 'HTML::Object::DOM::Element')
$self->_is_a($old_parent, "HTML::Object::DOM::Document") $self->_is_a($old_parent, "HTML::Object::DOM::DocumentFragment") $self->_is_a($old_parent, 'HTML::Object::DOM::Element')
Truth table25%1/4
A or B || C
A= $self->_is_a($old_parent, "HTML::Object::DOM::Document")B= $self->_is_a($old_parent, "HTML::Object::DOM::DocumentFragment")C= $self->_is_a($old_parent, 'HTML::Object::DOM::Element')
ABCresult
1XX1
01X1
0011
0000
1115 !$self->_is_a( $old_parent => 'HTML::Object::DOM::DocumentFragment' ) &&
1116 !$self->_is_a( $old_parent => 'HTML::Object::DOM::Element' ) )
1117 {
1118 0 return( $self->error({
1119 message => "Old node's parent is not an HTML::Object::DOM::Document, HTML::Object::DOM::DocumentFragment or HTML::Object::DOM::Element object.",
1120 class => 'HTML::Object::HierarchyRequestError',
1121 }) );
1122 }
1123 ▶ elsif( !$self->_is_a( $new => 'HTML::Object::DOM::DocumentFragment' ) &&
Condition33%3/9
$self->_is_a($new, 'HTML::Object::DOM::DocumentFragment') || $self->_is_a($new, 'HTML::Object::DOM::Declaration') || $self->_is_a($new, 'HTML::Object::DOM::Element') || $self->_is_a($new, 'HTML::Object::DOM::CharacterData')
l!l&&r!l&&!r
100
$self->_is_a($new, "HTML::Object::DOM::DocumentFragment") or $self->_is_a($new, "HTML::Object::DOM::Declaration") or $self->_is_a($new, "HTML::Object::DOM::Element")
l!l&&r!l&&!r
010
$self->_is_a($new, "HTML::Object::DOM::DocumentFragment") or $self->_is_a($new, "HTML::Object::DOM::Declaration")
l!l&&r!l&&!r
001
MC/DC0%0/4
$self->_is_a($new, 'HTML::Object::DOM::DocumentFragment') || $self->_is_a($new, 'HTML::Object::DOM::Declaration') || $self->_is_a($new, 'HTML::Object::DOM::Element') || $self->_is_a($new, 'HTML::Object::DOM::CharacterData')
$self->_is_a($new, "HTML::Object::DOM::DocumentFragment") $self->_is_a($new, "HTML::Object::DOM::Declaration") $self->_is_a($new, "HTML::Object::DOM::Element") $self->_is_a($new, 'HTML::Object::DOM::CharacterData')
Truth table20%1/5
A or B or C || D
A= $self->_is_a($new, "HTML::Object::DOM::DocumentFragment")B= $self->_is_a($new, "HTML::Object::DOM::Declaration")C= $self->_is_a($new, "HTML::Object::DOM::Element")D= $self->_is_a($new, 'HTML::Object::DOM::CharacterData')
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1124 !$self->_is_a( $new => 'HTML::Object::DOM::Declaration' ) &&
1125 !$self->_is_a( $new => 'HTML::Object::DOM::Element' ) &&
1126 !$self->_is_a( $new => 'HTML::Object::DOM::CharacterData' ) )
1127 {
1128 0 return( $self->error({
1129 message => "New node is not an HTML::Object::DOM::DocumentFragment, HTML::Object::DOM::Declaration, HTML::Object::DOM::Element or HTML::Object::DOM::CharacterData object.",
1130 class => 'HTML::Object::HierarchyRequestError',
1131 }) );
1132 }
1133 elsif( $self->lineage->has( $new ) )
1134 {
1135 0 return( $self->error({
1136 message => "New node provided is an ancestor of the current node.",
1137 class => 'HTML::Object::HierarchyRequestError',
1138 }) );
1139 }
1140 ▶ elsif( ( $self->_is_a( $new => 'HTML::Object::DOM::Text' ) || $self->_is_a( $new => 'HTML::Object::DOM::Space' ) ) &&
Condition33%2/6
$self->_is_a($new, "HTML::Object::DOM::Text") || $self->_is_a($new, "HTML::Object::DOM::Space") and $self->_is_a($new_parent, "HTML::Object::DOM::Document")
!ll&&!rl&&r
100
$self->_is_a($new, "HTML::Object::DOM::Text") or $self->_is_a($new, "HTML::Object::DOM::Space")
l!l&&r!l&&!r
001
MC/DC0%0/3
$self->_is_a($new, "HTML::Object::DOM::Text") || $self->_is_a($new, "HTML::Object::DOM::Space") and $self->_is_a($new_parent, "HTML::Object::DOM::Document")
$self->_is_a($new, "HTML::Object::DOM::Text") $self->_is_a($new, "HTML::Object::DOM::Space") $self->_is_a($new_parent, "HTML::Object::DOM::Document")
Truth table20%1/5
A or B and C
A= $self->_is_a($new, "HTML::Object::DOM::Text")B= $self->_is_a($new, "HTML::Object::DOM::Space")C= $self->_is_a($new_parent, "HTML::Object::DOM::Document")
ABCresult
00X0
1X00
0100
1X11
0111
1141 $self->_is_a( $new_parent => 'HTML::Object::DOM::Document' ) )
1142 {
1143 0 return( $self->error({
1144 message => "New node is a HTML::Object::DOM::Text or HTML::Object::DOM::Space node and its parent is a HTML::Object::DOM::Document node.",
1145 class => 'HTML::Object::HierarchyRequestError',
1146 }) );
1147 }
1148 ▶ elsif( $self->isa( 'HTML::Object::DOM::Declaration' ) && !$self->_is_a( $parent => 'HTML::Object::DOM::Document' ) )
Condition33%1/3
$self->isa("HTML::Object::DOM::Declaration") and not $self->_is_a($parent, "HTML::Object::DOM::Document")
!ll&&!rl&&r
100
MC/DC0%0/2
$self->isa("HTML::Object::DOM::Declaration") and not $self->_is_a($parent, "HTML::Object::DOM::Document")
$self->isa("HTML::Object::DOM::Declaration") not $self->_is_a($parent, "HTML::Object::DOM::Document")
Truth table33%1/3
A and not(B)
A= $self->isa("HTML::Object::DOM::Declaration")B= not $self->_is_a($parent, "HTML::Object::DOM::Document")
ABresult
0X0
100
111
1149 {
1150 0 return( $self->error({
1151 message => "Current node is a DocumentType, but its parent is not an HTML::Object::DOM::Document object.",
1152 class => 'HTML::Object::HierarchyRequestError',
1153 }) );
1154 }
1155 ▶ elsif( $self->_is_a( $parent => 'HTML::Object::DOM::Document' ) &&
Condition22%2/9
$self->_is_a($parent, "HTML::Object::DOM::Document") and $self->_is_a($new, "HTML::Object::DOM::DocumentFragment") and $new->childElementCount > 1 || $new->children->grep(sub { $self->_is_a($_, "HTML::Object::DOM::Text"); } )->length
!ll&&!rl&&r
100
$self->_is_a($parent, "HTML::Object::DOM::Document") and $self->_is_a($new, "HTML::Object::DOM::DocumentFragment")
!ll&&!rl&&r
100
$new->childElementCount > 1 or $new->children->grep(sub { $self->_is_a($_, "HTML::Object::DOM::Text"); } )->length
l!l&&r!l&&!r
000
MC/DC0%0/4
$self->_is_a($parent, "HTML::Object::DOM::Document") and $self->_is_a($new, "HTML::Object::DOM::DocumentFragment") and $new->childElementCount > 1 || $new->children->grep(sub { $self->_is_a($_, "HTML::Object::DOM::Text"); } )->length
$self->_is_a($parent, "HTML::Object::DOM::Document") $self->_is_a($new, "HTML::Object::DOM::DocumentFragment") $new->childElementCount > 1 $new->children->grep(sub { $self->_is_a($_, "HTML::Object::DOM::Text"); } )->length
Truth table20%1/5
A and B and C or D
A= $self->_is_a($parent, "HTML::Object::DOM::Document")B= $self->_is_a($new, "HTML::Object::DOM::DocumentFragment")C= $new->childElementCount > 1D= $new->children->grep(sub { $self->_is_a($_, "HTML::Object::DOM::Text"); } )->length
ABCDresult
0XXX0
10XX0
11000
111X1
11011
1156 $self->_is_a( $new => 'HTML::Object::DOM::DocumentFragment' ) &&
1157 0 ▶ ( $new->childElementCount > 1 || $new->children->grep(sub{ $self->_is_a( $_ => 'HTML::Object::DOM::Text' ) })->length ) )
Subroutine __ANON__: not called CC=1 SCAR=6.9
1158 {
1159 0 return( $self->error({
1160 message => "Current node parent is a HTML::Object::DOM::Document object and new node is a HTML::Object::DOM::DocumentFragment object that has either more than 1 element or has a HTML::Object::DOM::Text node.",
1161 class => 'HTML::Object::HierarchyRequestError',
1162 }) );
1163 }
1164 ▶ elsif( $self->_is_a( $parent => 'HTML::Object::DOM::Document' ) &&
Condition12%3/24
$self->_is_a($parent, "HTML::Object::DOM::Document") and $parent->childElementCount > 0 and $self->_is_a($new, "HTML::Object::DOM::Element") and not $self->_is_a($old, "HTML::Object::DOM::Element") && !$self->_is_a($old, "HTML::Object::DOM::Element::HTML") && $parent->children->grep(sub { $self->_is_a($_, "HTML::Object::DOM::Element::HTML"); } )->is_empty && $self->_is_a($new, "HTML::Object::DOM::Element::HTML") || $self->_is_a($old, "HTML::Object::DOM::Element::HTML") && $self->_is_a($new, "HTML::Object::DOM::Element::HTML")
!ll&&!rl&&r
100
$self->_is_a($parent, "HTML::Object::DOM::Document") and $parent->childElementCount > 0 and $self->_is_a($new, "HTML::Object::DOM::Element")
!ll&&!rl&&r
100
$self->_is_a($parent, "HTML::Object::DOM::Document") and $parent->childElementCount > 0
!ll&&!rl&&r
100
$self->_is_a($old, 'HTML::Object::DOM::Element') && !$self->_is_a($old, 'HTML::Object::DOM::Element::HTML') && $parent->children->grep(sub { $self->_is_a($_, 'HTML::Object::DOM::Element::HTML'); } )->is_empty && $self->_is_a($new, 'HTML::Object::DOM::Element::HTML') || $self->_is_a($old, 'HTML::Object::DOM::Element::HTML') && $self->_is_a($new, 'HTML::Object::DOM::Element::HTML')
l!l&&r!l&&!r
000
$self->_is_a($old, "HTML::Object::DOM::Element") and not $self->_is_a($old, "HTML::Object::DOM::Element::HTML") and $parent->children->grep(sub { $self->_is_a($_, "HTML::Object::DOM::Element::HTML"); } )->is_empty and $self->_is_a($new, "HTML::Object::DOM::Element::HTML")
!ll&&!rl&&r
000
$self->_is_a($old, "HTML::Object::DOM::Element") and not $self->_is_a($old, "HTML::Object::DOM::Element::HTML") and $parent->children->grep(sub { $self->_is_a($_, "HTML::Object::DOM::Element::HTML"); } )->is_empty
!ll&&!rl&&r
000
$self->_is_a($old, "HTML::Object::DOM::Element") and not $self->_is_a($old, "HTML::Object::DOM::Element::HTML")
!ll&&!rl&&r
000
$self->_is_a($old, "HTML::Object::DOM::Element::HTML") and $self->_is_a($new, "HTML::Object::DOM::Element::HTML")
!ll&&!rl&&r
000
MC/DC0%0/9
$self->_is_a($parent, "HTML::Object::DOM::Document") and $parent->childElementCount > 0 and $self->_is_a($new, "HTML::Object::DOM::Element") and not $self->_is_a($old, "HTML::Object::DOM::Element") && !$self->_is_a($old, "HTML::Object::DOM::Element::HTML") && $parent->children->grep(sub { $self->_is_a($_, "HTML::Object::DOM::Element::HTML"); } )->is_empty && $self->_is_a($new, "HTML::Object::DOM::Element::HTML") || $self->_is_a($old, "HTML::Object::DOM::Element::HTML") && $self->_is_a($new, "HTML::Object::DOM::Element::HTML")
$self->_is_a($parent, "HTML::Object::DOM::Document") $parent->childElementCount > 0 $self->_is_a($new, "HTML::Object::DOM::Element") $self->_is_a($old, "HTML::Object::DOM::Element") not $self->_is_a($old, "HTML::Object::DOM::Element::HTML") $parent->children->grep(sub { $self->_is_a($_, "HTML::Object::DOM::Element::HTML"); } )->is_empty $self->_is_a($new, "HTML::Object::DOM::Element::HTML") $self->_is_a($old, "HTML::Object::DOM::Element::HTML") $self->_is_a($new, "HTML::Object::DOM::Element::HTML")
Truth table6%1/16
A and B and C and not(D and not(E) and F and G || H and I)
A= $self->_is_a($parent, "HTML::Object::DOM::Document")B= $parent->childElementCount > 0C= $self->_is_a($new, "HTML::Object::DOM::Element")D= $self->_is_a($old, "HTML::Object::DOM::Element")E= not $self->_is_a($old, "HTML::Object::DOM::Element::HTML")F= $parent->children->grep(sub { $self->_is_a($_, "HTML::Object::DOM::Element::HTML"); } )->is_emptyG= $self->_is_a($new, "HTML::Object::DOM::Element::HTML")H= $self->_is_a($old, "HTML::Object::DOM::Element::HTML")I= $self->_is_a($new, "HTML::Object::DOM::Element::HTML")
ABCDEFGHIresult
0XXXXXXXX0
10XXXXXXX0
110XXXXXX0
1111111XX0
1110XXX110
11110XX110
111110X110
1111110110
1110XXX0X1
1110XXX101
11110XX0X1
11110XX101
111110X0X1
111110X101
11111100X1
1111110101
1165 $parent->childElementCount > 0 &&
1166 $self->_is_a( $new => 'HTML::Object::DOM::Element' ) &&
1167 # Non-standard addition:
1168 # replacement is not forbidden if the user replace an element that is not an HTML element by an HTML element and there is no HTML element yet or
1169 # the user replace an HTML element by another HTML element
1170 !(
1171 ( $self->_is_a( $old => 'HTML::Object::DOM::Element' ) &&
1172 !$self->_is_a( $old => 'HTML::Object::DOM::Element::HTML' ) &&
1173 0 ▶ $parent->children->grep(sub{ $self->_is_a( $_ => 'HTML::Object::DOM::Element::HTML' ) })->is_empty &&
Subroutine __ANON__: not called CC=1 SCAR=6.9
1174 $self->_is_a( $new => 'HTML::Object::DOM::Element::HTML' ) ) ||
1175 ( $self->_is_a( $old => 'HTML::Object::DOM::Element::HTML' ) &&
1176 $self->_is_a( $new => 'HTML::Object::DOM::Element::HTML' ) )
1177 ) )
1178 {
1179 0 return( $self->error({
1180 message => "Attempting to replace a child element in a Document with another non HTML-tag element. Document can have only one Element: the HTML-tag element.",
1181 class => 'HTML::Object::HierarchyRequestError',
1182 }) );
1183 }
1184 ▶ elsif( $self->_is_a( $new => 'HTML::Object::DOM::Element' ) &&
Condition33%1/3
$self->_is_a($new, "HTML::Object::DOM::Element") and $self->_is_a($old->previousSibling, "HTML::Object::DOM::Declaration")
!ll&&!rl&&r
010
MC/DC0%0/2
$self->_is_a($new, "HTML::Object::DOM::Element") and $self->_is_a($old->previousSibling, "HTML::Object::DOM::Declaration")
$self->_is_a($new, "HTML::Object::DOM::Element") $self->_is_a($old->previousSibling, "HTML::Object::DOM::Declaration")
Truth table33%1/3
A and B
A= $self->_is_a($new, "HTML::Object::DOM::Element")B= $self->_is_a($old->previousSibling, "HTML::Object::DOM::Declaration")
ABresult
0X0
100
111
1185 $self->_is_a( $old->previousSibling => 'HTML::Object::DOM::Declaration' ) )
1186 {
1187 0 return( $self->error({
1188 message => "Attempting to add an Element object before a DocumentType object",
1189 class => 'HTML::Object::HierarchyRequestError',
1190 }) );
1191 }
1192 # We use 'nodes' rather than 'children' so this works well with HTML::Object::DOM::Document
1193 1 my $nodes = $self->nodes;
1194 1 my $newPos = $nodes->pos( $new );
1195 1 my $oldPos = $nodes->pos( $old );
1196 1 ▶ if( defined( $newPos ) && !defined( $oldPos ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $newPos and not defined $oldPos) { } 0 1 1
elsif (not defined $oldPos) { } 0 1 1
Condition33%1/3
defined $newPos and not defined $oldPos
!ll&&!rl&&r
100
MC/DC0%0/2
defined $newPos and not defined $oldPos
defined $newPos not defined $oldPos
Truth table33%1/3
A and not(B)
A= defined $newPosB= not defined $oldPos
ABresult
0X0
100
111
1197 {
1198 0 return( $self->error({
1199 message => "New child already has this parent and old child does not. Please check the order of replaceChild's arguments.",
1200 class => 'HTML::Object::NotFoundError',
1201 }) );
1202 }
1203 elsif( !defined( $oldPos ) )
1204 {
1205 0 return( $self->error({
1206 message => "Child to be replaced is not a child of this node",
1207 class => 'HTML::Object::NotFoundError',
1208 }) );
1209 }
1210 1 $new->detach;
1211 1 ▶ my $new_array = $self->new_array( $self->_is_a( $new => 'HTML::Object::DOM::DocumentFragment' ) ? $new->children : $new );
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_a($new, 'HTML::Object::DOM::DocumentFragment') ? : 0 1 1
1212 $new_array->foreach(sub
1213 1 ▶ {
Subroutine __ANON__: called CC=2 SCAR=7.2
1214 1 ▶ return(1) if( !$self->_is_a( $_ => 'HTML::Object::DOM::Node' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($_, "HTML::Object::DOM::Node") 0 1 1
1215 1 $_->parent( $self );
1216 1 });
1217 1 $nodes->splice( $oldPos, 1, $new_array->list );
1218 1 $old->parent( undef );
1219 1 $self->reset(1);
1220 1 return( $old );
1221 }
1222  
1223 16 ▶sub textContent : lvalue { return( shift->_set_get_callback({
Subroutine textContent: called CC=1 SCAR=0.1
Pod documented
1224 get => sub
1225 7 ▶ {
Subroutine __ANON__: called CC=5 SCAR=18.3
1226 7 my $self = shift( @_ );
1227 7 ▶ return if( $self->isa( 'HTML::Object::DOM::Document' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->isa("HTML::Object::DOM::Document") 0 7 7
1228 7 ▶ unless( $self->isa( 'HTML::Object::DOM::Comment' ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->isa("HTML::Object::DOM::Comment") or $self->isa("HTML::Object::DOM::Text") or $self->isa("HTML::Object::DOM::Element")) 0 7 7
Condition33%2/6
$self->isa("HTML::Object::DOM::Comment") or $self->isa("HTML::Object::DOM::Text") or $self->isa("HTML::Object::DOM::Element")
l!l&&r!l&&!r
070
$self->isa("HTML::Object::DOM::Comment") or $self->isa("HTML::Object::DOM::Text")
l!l&&r!l&&!r
007
MC/DC0%0/3
$self->isa("HTML::Object::DOM::Comment") or $self->isa("HTML::Object::DOM::Text") or $self->isa("HTML::Object::DOM::Element")
$self->isa("HTML::Object::DOM::Comment") $self->isa("HTML::Object::DOM::Text") $self->isa("HTML::Object::DOM::Element")
Truth table25%1/4
A or B or C
A= $self->isa("HTML::Object::DOM::Comment")B= $self->isa("HTML::Object::DOM::Text")C= $self->isa("HTML::Object::DOM::Element")
ABCresult
1XX1
01X1
0011
0000
1229 $self->isa( 'HTML::Object::DOM::Text' ) ||
1230 $self->isa( 'HTML::Object::DOM::Element' ) )
1231 {
1232 0 return;
1233 }
1234 7 my $str = $self->as_text;
1235 7 $str =~ s,<br[[:blank:]]*/>\n,\n,gs;
1236 7 $str =~ s/\&gt;/>/gs;
1237 7 $str =~ s/\&lt;/</gs;
1238 7 return( $str );
1239 },
1240 set => sub
1241 9 ▶ {
Subroutine __ANON__: called CC=7 SCAR=19.6
1242 9 my $self = shift( @_ );
1243 9 my $ctx = $_;
1244 9 my $arg = shift( @_ );
1245 9 ▶ return if( $self->isa( 'HTML::Object::DOM::Document' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->isa("HTML::Object::DOM::Document") 0 9 9
1246 9 my $dummy;
1247 9 ▶ if( $self->isa( 'HTML::Object::DOM::Comment' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa("HTML::Object::DOM::Comment") or $self->isa("HTML::Object::DOM::Text") or $self->isa("HTML::Object::DOM::Element")) 9 0 9
Condition83%5/6
$self->isa("HTML::Object::DOM::Comment") or $self->isa("HTML::Object::DOM::Text") or $self->isa("HTML::Object::DOM::Element")
l!l&&r!l&&!r
270
$self->isa("HTML::Object::DOM::Comment") or $self->isa("HTML::Object::DOM::Text")
l!l&&r!l&&!r
117
MC/DC0%0/3
$self->isa("HTML::Object::DOM::Comment") or $self->isa("HTML::Object::DOM::Text") or $self->isa("HTML::Object::DOM::Element")
$self->isa("HTML::Object::DOM::Comment") $self->isa("HTML::Object::DOM::Text") $self->isa("HTML::Object::DOM::Element")
Truth table75%3/4
A or B or C
A= $self->isa("HTML::Object::DOM::Comment")B= $self->isa("HTML::Object::DOM::Text")C= $self->isa("HTML::Object::DOM::Element")
ABCresult
1XX1
01X1
0011
0000
1248 $self->isa( 'HTML::Object::DOM::Text' ) ||
1249 $self->isa( 'HTML::Object::DOM::Element' ) )
1250 {
1251 9 ▶ if( $self->isa( 'HTML::Object::DOM::Comment' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa('HTML::Object::DOM::Comment') or $self->isa('HTML::Object::DOM::Text')) { } 2 7 9
Condition100%3/3
$self->isa("HTML::Object::DOM::Comment") or $self->isa("HTML::Object::DOM::Text")
l!l&&r!l&&!r
117
MC/DC100%2/2
$self->isa("HTML::Object::DOM::Comment") or $self->isa("HTML::Object::DOM::Text")
$self->isa("HTML::Object::DOM::Comment") $self->isa("HTML::Object::DOM::Text")
Truth table100%3/3
A or B
A= $self->isa("HTML::Object::DOM::Comment")B= $self->isa("HTML::Object::DOM::Text")
ABresult
1X1
011
000
1252 $self->isa( 'HTML::Object::DOM::Text' ) )
1253 {
1254 2 $self->value( $arg );
1255 }
1256 else
1257 {
1258 7 my $val = "$arg";
1259 7 $val =~ s/</\&lt;/gs;
1260 7 $val =~ s/>/\&gt;/gs;
1261 7 $val =~ s,\n,<br />\n,gs;
1262 7 my $e = $self->new_text( value => $val, parent => $self );
1263 7 $self->children->set( $e );
1264 }
1265 9 $self->reset(1);
1266 9 $dummy = 1;
1267 9 return( $dummy );
1268 }
1269 0 return( $dummy );
1270 },
1271 16 }, @_ ) ); }
1272  
1273 sub trigger
1274 2 ▶{
Subroutine trigger: called CC=5 SCAR=17.5
Pod documented
1275 2 my $self = shift( @_ );
1276 2 my $type = shift( @_ );
1277 2 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and length "$type" 0 2 2
Condition33%1/3
defined $type and length "$type"
!ll&&!rl&&r
002
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
1278 message => "No event type was provided to trigger.",
1279 class => 'HTML::Object::SyntaxError',
1280 }) ) if( !defined( $type ) || !CORE::length( "$type" ) );
1281 2 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $type =~ /^\w[\w\-]*$/ 0 2 2
1282 message => "Event type provided \"$type\" contains illegal characters. Only alphanuneric, underscore (\"_\") and dash (\"-\") are allowed",
1283 class => 'HTML::Object::TypeError',
1284 }) ) if( $type !~ /^\w[\w\-]*$/ );
1285 2 require HTML::Object::Event;
1286 2 ▶ my $evt = HTML::Object::Event->new( $type, @_ ) ||
Condition50%1/2
'HTML::Object::Event'->new($type, @_) || (return $self->pass_error('HTML::Object::Event'->error))
l!l
20
MC/DC0%0/1
'HTML::Object::Event'->new($type, @_) || (return $self->pass_error('HTML::Object::Event'->error))
'HTML::Object::Event'->new($type, @_)
Truth table50%1/2
A
A= 'HTML::Object::Event'->new($type, @_)
Aresult
11
00
1287 return( $self->pass_error( HTML::Object::Event->error ) );
1288 2 return( $self->dispatchEvent( $evt ) );
1289 }
1290  
1291 sub xp
1292 20 ▶{
Subroutine xp: called CC=3 SCAR=11.0
Pod documented
1293 20 my $self = shift( @_ );
1294 20 ▶ unless( $XP )
Branch: 1 branch
BranchTrueFalseTotal
unless ($HTML::Object::DOM::Node::XP) 5 15 20
1295 {
1296 5 ▶ $self->_load_class( 'HTML::Object::XPath' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::XPath") or return $self->pass_error 5 0 5
1297 5 $XP = HTML::Object::XPath->new;
1298 }
1299 # $XP->debug( $self->debug );
1300 20 return( $XP );
1301 }
1302  
1303 sub _list_to_nodes
1304 0 ▶{
Subroutine _list_to_nodes: not called CC=13 SCAR=52.0
1305 0 my $self = shift( @_ );
1306 0 my $list = $self->new_array;
1307 0 my $p = $self->new_parser;
1308 0 my $prev;
1309 0 foreach( @_ )
1310 {
1311 0 ▶ if( $self->_is_a( $_ => 'HTML::Object::DOM::Node' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($_, 'HTML::Object::DOM::Node')) { } 0 0 0
elsif (not ref $_ or ref $_ and overload::Method($_, '""')) { } 0 0 0
1312 {
1313 0 ▶ if( $self->_is_a( $_ => 'HTML::Object::DOM::DocumentFragment' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($_, 'HTML::Object::DOM::DocumentFragment')) { } 0 0 0
1314 {
1315 0 my $kids = $_->children->clone;
1316 0 $_->children->reset;
1317 0 foreach my $kid ( @$kids )
1318 {
1319 0 $kid->detach;
1320 }
1321 0 $list->push( $kids->list );
1322 }
1323 else
1324 {
1325 0 $list->push( $_ );
1326 0 $_->detach;
1327 }
1328 0 undef( $prev );
1329 }
1330 # HTML string
1331 ▶ elsif( !ref( $_ ) || ( ref( $_ ) && overload::Method( $_, '""' ) ) )
Condition0%0/6
not ref $_ or ref $_ and overload::Method($_, "\"\"")
l!l&&r!l&&!r
000
ref $_ and overload::Method($_, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/3
not ref $_ or ref $_ and overload::Method($_, "\"\"")
not ref $_ ref $_ overload::Method($_, "\"\"")
Truth table0%0/4
not(A) or B and C
A= not ref $_B= ref $_C= overload::Method($_, "\"\"")
ABCresult
1XX1
0111
00X0
0100
1332 {
1333 0 ▶ if( $self->looks_like_html( $_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->looks_like_html($_)) { } 0 0 0
1334 {
1335 0 ▶ my $doc = $p->parse_data( $_ ) ||
Condition0%0/2
$p->parse_data($_) || (return $self->pass_error({'class', 'HTML::Object::TypeError'}))
l!l
00
MC/DC0%0/1
$p->parse_data($_) || (return $self->pass_error({'class', 'HTML::Object::TypeError'}))
$p->parse_data($_)
Truth table0%0/2
A
A= $p->parse_data($_)
Aresult
11
00
1336 return( $self->pass_error({ class => 'HTML::Object::TypeError' }) );
1337 0 ▶ $list->push( $doc->children->list ) if( !$doc->children->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
unless $doc->children->is_empty 0 0 0
1338 0 undef( $prev );
1339 }
1340 else
1341 {
1342 0 ▶ if( defined( $prev ) && $self->_is_a( $prev => 'HTML::Object::DOM::Text' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prev and $self->_is_a($prev, 'HTML::Object::DOM::Text')) { } 0 0 0
Condition0%0/3
defined $prev and $self->_is_a($prev, "HTML::Object::DOM::Text")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $prev and $self->_is_a($prev, "HTML::Object::DOM::Text")
defined $prev $self->_is_a($prev, "HTML::Object::DOM::Text")
Truth table0%0/3
A and B
A= defined $prevB= $self->_is_a($prev, "HTML::Object::DOM::Text")
ABresult
0X0
100
111
1343 {
1344 0 $prev->value->append( $_ );
1345 }
1346 else
1347 {
1348 0 my $e = $self->new_text( value => $_ );
1349 0 $list->push( $e );
1350 0 $prev = $e;
1351 }
1352 }
1353 }
1354 else
1355 {
1356 0 return( $self->error({
1357 message => "Unsupported data provided (" . overload::StrVal( $_ ) . ").",
1358 class => 'HTML::Object::TypeError',
1359 }) );
1360 }
1361 }
1362 0 return( $list );
1363 }
1364  
1365 sub _xpath_value
1366 20 ▶{
Subroutine _xpath_value: called CC=4 SCAR=14.7
1367 20 my $self = shift( @_ );
1368 20 my $this = shift( @_ );
1369 20 my $opts = $self->_get_args_as_hash( @_ );
1370 20 ▶ if( ref( $this ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this) { } 0 20 20
1371 {
1372 0 return( $$this );
1373 }
1374 else
1375 {
1376 20 ▶ $self->_load_class( 'HTML::Selector::XPath' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Selector::XPath") or return $self->pass_error 20 0 20
1377 return( $self->pass_error );
1378 # try-catch
1379 20 local $@;
1380 my $rv = eval
1381 20 {
1382 20 return( HTML::Selector::XPath::selector_to_xpath( $this, %$opts ) );
1383 };
1384 20 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 20 20
1385 {
1386 0 return( $self->error( "Bad selector \"$this\": $@" ) );
1387 }
1388 20 return( $rv );
1389 }
1390 }
1391  
1392 36 1;
1393 # NOTE: POD
1394 __END__
« Object/DOM/CharacterData.pm ↑ Summary Object.pm »