Object/Element.pm

filter: Statementstmt 45.5% 391 / 858 Branchbran 34.2% 144 / 420 Conditioncond 22.0% 57 / 258 MC/DCmcdc 18.4% 26 / 141 Subroutinesub 50.3% 72 / 143 Podpod 100% 83 / 83 totaltotal 40.6% 773 / 1903 CC 320 SCAR 44.6
CC
320
Cov
39%
__ANON__
812.0
_get_elements_list
240.0
__ANON__
209.2
CRAP 86.4
« Object/XPath/Expr.pm ↑ Summary Object/DOM/CharacterData.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/Element.pm
3 ## Version v0.3.1
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/04/25
7 ## Modified 2026/07/04
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::Element;
15 BEGIN
16 37 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 # For smart match
18 37 ▶ use v5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 37 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 37 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 37 warnings::register_categories( 'HTML::Object' );
22 37 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 37 ▶ use vars qw( $LOOK_LIKE_HTML $LOOK_LIKE_IT_HAS_HTML $ATTRIBUTE_NAME_RE $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
24 37 ▶ use Data::UUID;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 37 ▶ use Digest::MD5 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26 37 ▶ use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27 37 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
28 37 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 37 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
30 37 'eq' => \&_same_as,
31 '==' => \&_same_as,
32 fallback => 1,
33 37 );
34 37 our $LOOK_LIKE_HTML = qr/^[[:blank:]\h]*\<\w+.*?\>/;
35 37 our $LOOK_LIKE_IT_HAS_HTML = qr/\<\w+.*?\>/;
36 37 our $ATTRIBUTE_NAME_RE = qr/\w[\w\-]*/;
37 37 our $VERSION = 'v0.3.1';
38 };
39  
40 37 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 37 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 sub init
44 1841 ▶{
Subroutine init: called CC=15 SCAR=27.2
Pod documented
45 1841 my $self = shift( @_ );
46 1841 my $opts = $self->_get_args_as_hash( @_ );
47 1841 for( qw( attributes attributes_sequence ) )
48 {
49 3682 ▶ delete( $opts->{ $_ } ) if( !defined( $opts->{ $_ } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{$_} 2800 882 3682
50 }
51 1841 my $parent = delete( $opts->{parent} );
52 1841 $opts->{parent} = $parent;
53 1841 ▶ $self->{attr} = {} unless( exists( $self->{attr} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"attr"} 1841 0 1841
54 1841 ▶ $self->{attr_seq} = [] unless( exists( $self->{attr_seq} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"attr_seq"} 1841 0 1841
55 1841 $self->{checksum} = '';
56 1841 ▶ $self->{close_tag} = '' unless( exists( $self->{close_tag} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"close_tag"} 1841 0 1841
57 1841 $self->{column} = 0;
58 # Was there a closing tag for non-void tags?
59 1841 ▶ $self->{is_closed} = 0 unless( exists( $self->{is_closed} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"is_closed"} 1841 0 1841
60 1841 ▶ $self->{is_empty} = 0 unless( exists( $self->{is_empty} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"is_empty"} 696 1145 1841
61 1841 $self->{line} = 0;
62 1841 $self->{modified} = 0;
63 1841 $self->{offset} = 0;
64 1841 $self->{original} = undef;
65 1841 $self->{parent} = undef;
66 1841 $self->{rank} = undef;
67 1841 ▶ $self->{tag} = '' unless( exists( $self->{tag} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"tag"} 533 1308 1841
68 1841 $self->{_init_strict_use_sub} = 1;
69 1841 $self->{_exception_class} = 'HTML::Object::Exception';
70 1841 ▶ $self->SUPER::init( $opts ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init($opts) or return $self->pass_error 1841 0 1841
71 1841 $self->{children} = [];
72 # uuid
73 1841 $self->{eid} = $self->_generate_uuid();
74 # The user is always right, so we check if the tag has a forward slash as attribute
75 # If there is one, this means this tag is an empty (void) tag.
76 # We issue a warning if our dictionary-derived value 'is_empty' says different
77 1841 ▶ $opts->{is_empty} = 0 if( !exists( $opts->{is_empty} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"is_empty"} 1385 456 1841
78 1841 ▶ $opts->{attributes} = {} if( !exists( $opts->{attributes} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"attributes"} 1400 441 1841
79 1841 my $attr = $opts->{attributes};
80 1841 ▶ if( !$opts->{is_empty} && exists( $attr->{'/'} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $opts->{"is_empty"} and exists $attr->{"/"}) 6 1835 1841
Condition100%3/3
not $opts->{"is_empty"} and exists $attr->{"/"}
!ll&&!rl&&r
11917166
MC/DC100%2/2
not $opts->{"is_empty"} and exists $attr->{"/"}
not $opts->{"is_empty"} exists $attr->{"/"}
Truth table100%3/3
not(A) and B
A= not $opts->{"is_empty"}B= exists $attr->{"/"}
ABresult
0X0
100
111
81 {
82 6 ▶ warn( "Tag initiated \"$opts->{tag}\" is marked as non-empty (non-void), but ends with \"/>\" at line $opts->{line} and column $opts->{column}: $opts->{original}\n" ) if( $self->_is_warnings_enabled( 'HTML::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTML::Object") 0 6 6
83 6 $self->is_empty(1);
84 }
85 1841 $self->checksum( $self->set_checksum );
86 1841 $self->{_cache_value} = '';
87 1841 $self->{_internal} = {};
88 1841 return( $self );
89 }
90  
91 # Note: HTML::Element compatibility
92 sub address
93 0 ▶{
Subroutine address: not called CC=8 SCAR=42.8
Pod documented
94 0 my $self = shift( @_ );
95 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
96 {
97 0 my $addr = shift( @_ );
98 0 my $path = $self->new_array( [split( /\./, $addr )] );
99 0 my $root;
100 # relative path, such as .2.5.3
101 0 ▶ if( !length( $path->[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not length $path->[0]) { } 0 0 0
102 {
103 0 $root = $self;
104 }
105 else
106 {
107 0 $root = $self->root;
108 0 ▶ return( $self->error( "First offset position should be 0 for root or a relative path." ) ) if( $path->shift != 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $path->shift != 0 0 0 0
109 }
110 0 my $offset;
111 0 ▶ while( $path->length && ( $offset = $path->shift ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($path->length and $offset = $path->shift) 0 0 0
Condition0%0/3
$path->length and $offset = $path->shift
!ll&&!rl&&r
000
MC/DC0%0/2
$path->length and $offset = $path->shift
$path->length $offset = $path->shift
Truth table0%0/3
A and B
A= $path->lengthB= $offset = $path->shift
ABresult
0X0
100
111
112 {
113 0 ▶ return( $self->error( "Invalid offset '$offset' in path '$addr'. Value is bigger than the actual size of elements (", $root->children->size, "); starting from 0." ) ) if( $offset > $root->children->size );
Branch: 1 branch
BranchTrueFalseTotal
if $offset > $root->children->size 0 0 0
114 0 $root = $root->children->get( $offset );
115 }
116 0 return( $root );
117 }
118 else
119 {
120 0 my $line = $self->new_array;
121 0 ▶ my $pos = $self->pos || 0;
Condition0%0/2
$self->pos || 0
l!l
00
MC/DC0%0/1
$self->pos || 0
$self->pos
Truth table0%0/2
A
A= $self->pos
Aresult
11
00
122 0 $line->push( $pos );
123 0 $line->push( $self->lineage->list );
124 0 return( $line->reverse->join( '.' ) );
125 }
126 }
127  
128 # Note: HTML::Element compatibility
129 sub all_attr
130 0 ▶{
Subroutine all_attr: not called CC=1 SCAR=6.9
Pod documented
131 0 my $self = shift( @_ );
132 0 my $ref = $self->attributes;
133 0 return( %$ref );
134 }
135  
136 # Note: HTML::Element compatibility
137 sub all_attr_names
138 0 ▶{
Subroutine all_attr_names: not called CC=1 SCAR=6.9
Pod documented
139 0 my $self = shift( @_ );
140 0 return( $self->attributes->keys->list );
141 }
142  
143 0 ▶sub as_html { return( shift->as_string( @_ ) ); }
Subroutine as_html: not called CC=1 SCAR=6.9
Pod documented
144  
145 sub as_string
146 144 ▶{
Subroutine as_string: called CC=24 SCAR=32.2
Pod documented
147 144 my $self = shift( @_ );
148 144 my $opts = $self->_get_args_as_hash( @_ );
149 # If the element is called from within a collection, although it still has its
150 # parent, we do not know exactly where is its closing tag, if any.
151 # So this option makes it possible to return the tag and its closing tag, if any.
152 144 ▶ $opts->{inside_collection} = 0 if( !CORE::exists( $opts->{inside_collection} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"inside_collection"} 121 23 144
153 144 ▶ $opts->{inside_collection} //= 0;
Condition50%1/2
$opts->{"inside_collection"} //= 0
l!l
1440
MC/DC0%0/1
$opts->{"inside_collection"} //= 0
$opts->{"inside_collection"}
Truth table50%1/2
A
A= $opts->{"inside_collection"}
Aresult
11
00
154 144 ▶ $opts->{recursive} //= 0;
Condition100%2/2
$opts->{"recursive"} //= 0
l!l
6777
MC/DC100%1/1
$opts->{"recursive"} //= 0
$opts->{"recursive"}
Truth table100%2/2
A
A= $opts->{"recursive"}
Aresult
11
00
155 144 ▶ return( $self->{_cache_value} ) if( $self->{_cache_value} && !CORE::length( $self->{_reset} ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_cache_value"} and not length $self->{"_reset"} 11 133 144
Condition100%3/3
$self->{"_cache_value"} and not length $self->{"_reset"}
!ll&&!rl&&r
1072611
MC/DC100%2/2
$self->{"_cache_value"} and not length $self->{"_reset"}
$self->{"_cache_value"} not length $self->{"_reset"}
Truth table100%3/3
A and not(B)
A= $self->{"_cache_value"}B= not length $self->{"_reset"}
ABresult
0X0
100
111
156 133 my $tag = $self->tag;
157 133 my $res = $self->new_array;
158 133 my $a = $self->new_array( ["<${tag}"] );
159 133 my $hash1 = $self->checksum;
160 133 my $hash2 = $self->set_checksum;
161 133 ▶ if( $self->original->defined && $hash1 eq $hash2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->original->defined and $hash1 eq $hash2) { } 83 50 133
Condition100%3/3
$self->original->defined and $hash1 eq $hash2
!ll&&!rl&&r
361483
MC/DC100%2/2
$self->original->defined and $hash1 eq $hash2
$self->original->defined $hash1 eq $hash2
Truth table100%3/3
A and B
A= $self->original->definedB= $hash1 eq $hash2
ABresult
0X0
100
111
162 {
163 83 $a->set( [ $self->original->scalar ] );
164 }
165 else
166 {
167 50 ▶ if( !$self->attributes_sequence->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->attributes_sequence->is_empty) 32 18 50
168 {
169 32 my $attr = $self->new_array;
170 $self->attributes_sequence->foreach(sub
171 72 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.2
172 72 my $k = shift( @_ );
173 72 ▶ return(1) if( $k eq '/' );
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "/" 0 72 72
174 72 my $v = $self->attributes->get( $k );
175 72 ▶ return if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 72 72
176 # Ensure double quotes are escaped
177 72 $v =~ s/(?<!\\)\"/\\\"/gs;
178 72 $attr->push( sprintf( '%s="%s"', $k, $v ) );
179 32 });
180 32 $a->push( $attr->join( ' ' )->scalar );
181 }
182 }
183 133 ▶ if( !$self->children->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->children->is_empty) { } 90 43 133
184 {
185 90 ▶ if( $self->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_empty) 0 90 90
186 {
187 0 ▶ warn( "This tag \"$tag\" is supposed to be an empty / void one, but it has " . $self->children->length . " children.\n" ) if( $self->_is_warnings_enabled( 'HTML::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTML::Object") 0 0 0
188 }
189 # The user is alway right, so let's add those children
190 90 $res->push( $a->join( ' ' )->scalar );
191 90 ▶ $res->push( '>' ) unless( $self->original->defined && $hash1 eq $hash2 );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->original->defined and $hash1 eq $hash2 14 76 90
Condition100%3/3
$self->original->defined and $hash1 eq $hash2
!ll&&!rl&&r
12276
MC/DC100%2/2
$self->original->defined and $hash1 eq $hash2
$self->original->defined $hash1 eq $hash2
Truth table100%3/3
A and B
A= $self->original->definedB= $hash1 eq $hash2
ABresult
0X0
100
111
192 $self->children->foreach(sub
193 160 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.8
194 160 my $e = shift( @_ );
195 160 my $v;
196 160 ▶ if( $opts->{as_xml} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'as_xml'}) { } 0 160 160
197 {
198 0 $v = $e->as_xml( recursive => 1 );
199 }
200 else
201 {
202 160 $v = $e->as_string( recursive => 1 );
203 }
204 160 ▶ $res->push( defined( $v ) ? $v->scalar : $v );
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 160 0 160
205 90 });
206 # $res->push( "</${tag}>" );
207 # $res->push( "</${tag}>" ) if( !$self->parent && !$self->is_empty );
208 # if( ( $opts->{inside_collection} || !$opts->{recursive} ) && $self->close_tag )
209 90 ▶ if( my $close = $self->close_tag )
Branch: 1 branch
BranchTrueFalseTotal
if (my $close = $self->close_tag) 90 0 90
210 {
211 90 my $parent = $self->parent;
212 90 ▶ unless( $parent && defined( my $pos = $parent->children->pos( $close ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($parent and defined(my $pos = $parent->children->pos($close))) 90 0 90
Condition66%2/3
$parent and defined(my $pos = $parent->children->pos($close))
!ll&&!rl&&r
11790
MC/DC0%0/2
$parent and defined(my $pos = $parent->children->pos($close))
$parent defined(my $pos = $parent->children->pos($close))
Truth table66%2/3
A and B
A= $parentB= defined(my $pos = $parent->children->pos($close))
ABresult
0X0
100
111
213 {
214 90 $res->push( $close->as_string );
215 }
216 }
217 }
218 else
219 {
220 43 ▶ if( $self->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_empty) { } 1 42 43
221 {
222 # No need to add this, because we are re-using the original tag data since it has not changed
223 1 ▶ $a->push( '/>' ) unless( $hash1 eq $hash2 );
Branch: 1 branch
BranchTrueFalseTotal
unless $hash1 eq $hash2 0 1 1
224 1 $res->push( $a->join( ' ' )->scalar );
225 }
226 else
227 {
228 42 $res->push( $a->join( ' ' )->scalar );
229 42 ▶ $res->push( '>' ) unless( $self->original->defined && $hash1 eq $hash2 );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->original->defined and $hash1 eq $hash2 36 6 42
Condition100%3/3
$self->original->defined and $hash1 eq $hash2
!ll&&!rl&&r
24126
MC/DC100%2/2
$self->original->defined and $hash1 eq $hash2
$self->original->defined $hash1 eq $hash2
Truth table100%3/3
A and B
A= $self->original->definedB= $hash1 eq $hash2
ABresult
0X0
100
111
230 # If it has a parent, the parent will contain the closing tag, but
231 # If this element is an element created with a find, such as $('body'), it has no
232 # parent.
233 # $res->push( "</${tag}>" ) if( !$self->parent && !$self->is_empty );
234 42 ▶ if( my $close = $self->close_tag )
Branch: 1 branch
BranchTrueFalseTotal
if (my $close = $self->close_tag) 34 8 42
235 {
236 34 my $parent = $self->parent;
237 34 ▶ unless( $parent && defined( my $pos = $parent->children->pos( $close ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($parent and defined(my $pos = $parent->children->pos($close))) 30 4 34
Condition100%3/3
$parent and defined(my $pos = $parent->children->pos($close))
!ll&&!rl&&r
1294
MC/DC100%2/2
$parent and defined(my $pos = $parent->children->pos($close))
$parent defined(my $pos = $parent->children->pos($close))
Truth table100%3/3
A and B
A= $parentB= defined(my $pos = $parent->children->pos($close))
ABresult
0X0
100
111
238 {
239 30 $res->push( $close->as_string );
240 }
241 }
242 }
243 }
244 133 my $elem = $res->join( '' );
245 133 $self->{_cache_value} = $elem;
246 133 CORE::delete( $self->{_reset} );
247 133 return( $elem );
248 }
249  
250 # Note: HTML::Element compatibility
251 sub as_text
252 730 ▶{
Subroutine as_text: called CC=7 SCAR=20.6
Pod documented
253 730 my $self = shift( @_ );
254 730 ▶ return( $self->{_cache_text} ) if( $self->{_cache_text} && !CORE::length( $self->{_reset} ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_cache_text"} and not length $self->{"_reset"} 331 399 730
Condition100%3/3
$self->{"_cache_text"} and not length $self->{"_reset"}
!ll&&!rl&&r
3963331
MC/DC100%2/2
$self->{"_cache_text"} and not length $self->{"_reset"}
$self->{"_cache_text"} not length $self->{"_reset"}
Truth table100%3/3
A and not(B)
A= $self->{"_cache_text"}B= not length $self->{"_reset"}
ABresult
0X0
100
111
255 399 my $opts = $self->_get_args_as_hash( @_ );
256 399 ▶ $opts->{unescape} //= 0;
Condition100%2/2
$opts->{"unescape"} //= 0
l!l
2397
MC/DC100%1/1
$opts->{"unescape"} //= 0
$opts->{"unescape"}
Truth table100%2/2
A
A= $opts->{"unescape"}
Aresult
11
00
257 399 my $a = $self->new_array;
258 399 my $seen = {};
259 399 my $crawl;
260 $crawl = sub
261 480 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.1
262 480 my $elem = shift( @_ );
263 $elem->children->foreach(sub
264 234 ▶ {
Subroutine __ANON__: called CC=10 SCAR=23.7
265 234 my $e = shift( @_ );
266 234 my $addr = Scalar::Util::refaddr( $e );
267 234 ▶ return(1) if( CORE::exists( $seen->{ $addr } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $seen->{$addr} 0 234 234
268 234 $seen->{ $addr }++;
269 234 ▶ if( $e->isa( 'HTML::Object::Text' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($e->isa("HTML::Object::Text") or $e->isa("HTML::Object::Space")) 153 81 234
Condition100%3/3
$e->isa("HTML::Object::Text") or $e->isa("HTML::Object::Space")
l!l&&r!l&&!r
4910481
MC/DC100%2/2
$e->isa("HTML::Object::Text") or $e->isa("HTML::Object::Space")
$e->isa("HTML::Object::Text") $e->isa("HTML::Object::Space")
Truth table100%3/3
A or B
A= $e->isa("HTML::Object::Text")B= $e->isa("HTML::Object::Space")
ABresult
1X1
011
000
270 $e->isa( 'HTML::Object::Space' ) )
271 {
272 153 ▶ if( exists( $opts->{callback} ) && ref( $opts->{callback} ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"callback"} and ref $opts->{"callback"} eq "CODE") 0 153 153
Condition33%1/3
exists $opts->{"callback"} and ref $opts->{"callback"} eq "CODE"
!ll&&!rl&&r
15300
MC/DC0%0/2
exists $opts->{"callback"} and ref $opts->{"callback"} eq "CODE"
exists $opts->{"callback"} ref $opts->{"callback"} eq "CODE"
Truth table33%1/3
A and B
A= exists $opts->{"callback"}B= ref $opts->{"callback"} eq "CODE"
ABresult
0X0
100
111
273 {
274 # If value returned is not true, we skip this element
275 0 ▶ $opts->{callback}->( $e ) || return(1);
Branch: 1 branch
BranchTrueFalseTotal
$opts->{"callback"}->($e) or return 1 0 0 0
276 }
277 153 ▶ if( $opts->{unescape} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'unescape'}) { } 2 151 153
278 {
279 2 my $txt = $e->as_string->scalar;
280 2 $txt =~ s,<br[[:blank:]]*/>\n,\n,gs;
281 2 $txt =~ s/\&gt;/>/gs;
282 2 $txt =~ s/\&lt;/</gs;
283 2 $a->push( $txt );
284 }
285 else
286 {
287 151 $a->push( $e->as_string->scalar );
288 }
289 }
290  
291 234 ▶ unless( $e->isa( 'HTML::Object::Text' ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless ($e->isa("HTML::Object::Text") or $e->isa("HTML::Object::Space")) 81 153 234
Condition100%3/3
$e->isa("HTML::Object::Text") or $e->isa("HTML::Object::Space")
l!l&&r!l&&!r
4910481
MC/DC100%2/2
$e->isa("HTML::Object::Text") or $e->isa("HTML::Object::Space")
$e->isa("HTML::Object::Text") $e->isa("HTML::Object::Space")
Truth table100%3/3
A or B
A= $e->isa("HTML::Object::Text")B= $e->isa("HTML::Object::Space")
ABresult
1X1
011
000
292 $e->isa( 'HTML::Object::Space' ) )
293 {
294 81 $crawl->( $e );
295 }
296 480 });
297 399 };
298 399 ▶ if( $self->isa( 'HTML::Object::Text' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa('HTML::Object::Text') or $self->isa('HTML::Object::Space')) { } 0 399 399
Condition33%1/3
$self->isa("HTML::Object::Text") or $self->isa("HTML::Object::Space")
l!l&&r!l&&!r
00399
MC/DC0%0/2
$self->isa("HTML::Object::Text") or $self->isa("HTML::Object::Space")
$self->isa("HTML::Object::Text") $self->isa("HTML::Object::Space")
Truth table33%1/3
A or B
A= $self->isa("HTML::Object::Text")B= $self->isa("HTML::Object::Space")
ABresult
1X1
011
000
299 $self->isa( 'HTML::Object::Space' ) )
300 {
301 0 ▶ if( $opts->{unescape} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'unescape'}) { } 0 0 0
302 {
303 0 my $txt = $self->value->scalar;
304 0 $txt =~ s,<br[[:blank:]]*/>\n,\n,gs;
305 0 $txt =~ s/\&gt;/>/gs;
306 0 $txt =~ s/\&lt;/</gs;
307 0 $a->push( $txt );
308 }
309 else
310 {
311 0 $a->push( $self->value->scalar );
312 }
313 }
314 else
315 {
316 399 $crawl->( $self );
317 }
318 399 $self->{_cache_text} = $a->join( '' );
319 399 CORE::delete( $self->{_reset} );
320 399 return( $self->{_cache_text} );
321 }
322  
323 # Note: HTML::Element compatibility
324 sub as_trimmed_text
325 0 ▶{
Subroutine as_trimmed_text: not called CC=2 SCAR=17.9
Pod documented
326 0 my $self = shift( @_ );
327 0 my $opts = $self->_get_args_as_hash( @_ );
328 0 ▶ my $text = $self->as_text( $opts ) || return;
Condition0%0/2
$self->as_text($opts) || (return)
l!l
00
MC/DC0%0/1
$self->as_text($opts) || (return)
$self->as_text($opts)
Truth table0%0/2
A
A= $self->as_text($opts)
Aresult
11
00
329 0 $text->replace( qr/^[[:blank:]\h\v]+|[[:blank:]\h\v]+$/, '' );
330 0 return( $text );
331 }
332  
333 # Note: HTML::Element compatibility
334 # This does the same as for html. Sub classes take care of the differences
335 # sub as_xml { return( shift->as_string( @_ ) ); }
336 sub as_xml
337 0 ▶{
Subroutine as_xml: not called CC=1 SCAR=6.9
Pod documented
338 0 my $self = shift( @_ );
339 0 my $opts = $self->_get_args_as_hash( @_ );
340 0 $opts->{as_xml} = 1;
341 0 return( $self->as_string( $opts ) );
342 }
343  
344 sub attr
345 339 ▶{
Subroutine attr: called CC=11 SCAR=24.5
Pod documented
346 339 my $self = shift( @_ );
347 339 ▶ my $attr = shift( @_ ) || return( $self->error( "No attribute name provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No attribute name provided.'))
l!l
3390
MC/DC0%0/1
shift @_ || (return $self->error('No attribute name provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
348 339 ▶ return( $self->error( "Attribute provided \"${attr}\" contains illegal characters. Only alphanumeric and _ are supported." ) ) if( $attr !~ /^\w+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $attr =~ /^\w+$/ 0 339 339
349 339 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 61 278 339
350 {
351 61 my $v = shift( @_ );
352 61 my $old;
353 61 ▶ if( defined( $v ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) { } 61 0 61
354 {
355 61 $old = $self->attributes->get( $attr );
356 # We do not want to force stringification, because for attribute like 'href' it could have an URI object as a value.
357 # When stringification will be required, it will be done automatically anyway.
358 # $v = "$v" if( ref( $v ) && overload::Method( $v, '""' ) );
359 61 ▶ $v =~ s/^[[:blank:]\h]+|[[:blank:]\h]+$//g if( !ref( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v 37 24 61
360 61 $self->attributes->set( $attr => $v );
361 61 ▶ $self->attributes_sequence->push( $attr ) if( !$self->attributes_sequence->has( $attr ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->attributes_sequence->has($attr) 1 60 61
362 }
363 else
364 {
365 0 $self->attributes_sequence->remove( $attr );
366 0 $old = $self->attributes->delete( $attr );
367 }
368  
369 # Check for attributes callback and execute it.
370 # This is typically used for HTML::Object::TokenList by HTML::Object::DOM::Element and HTML::Object::DOM::AnchorElement
371 61 my $callbacks = $self->{_internal_attribute_callbacks};
372 61 ▶ $callbacks = {} if( ref( $callbacks ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $callbacks ne "HASH" 3 58 61
373 61 ▶ if( CORE::exists( $callbacks->{ $attr } ) && ref( $callbacks->{ $attr } ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$attr} and ref $callbacks->{$attr} eq "CODE") 3 58 61
Condition66%2/3
exists $callbacks->{$attr} and ref $callbacks->{$attr} eq "CODE"
!ll&&!rl&&r
5803
MC/DC50%1/2
exists $callbacks->{$attr} and ref $callbacks->{$attr} eq "CODE"
exists $callbacks->{$attr} ref $callbacks->{$attr} eq "CODE"
Truth table66%2/3
A and B
A= exists $callbacks->{$attr}B= ref $callbacks->{$attr} eq "CODE"
ABresult
0X0
100
111
374 {
375 3 my $cb = $callbacks->{ $attr };
376 # try-catch
377 3 local $@;
378 eval
379 3 {
380 3 $cb->( $self, $v );
381 };
382 3 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 3 3
383 {
384 0 return( $self->error( "Error executing attribute callback for attribute \"$attr\" for element with tag \"", $self->tag, "\": $@" ) );
385 }
386 }
387 61 $self->reset(1);
388 61 return( $old );
389 }
390 else
391 {
392 278 return( $self->attributes->get( $attr ) );
393 }
394 }
395  
396 3455 ▶sub attributes { return( shift->reset(@_)->_set_get_hash_as_mix_object( 'attr', @_ ) ); }
Subroutine attributes: called CC=1 SCAR=0.0
Pod documented
397  
398 sub attributes_sequence
399 1538 ▶{
Subroutine attributes_sequence: called CC=3 SCAR=11.0
Pod documented
400 1538 my $self = shift( @_ );
401 1538 ▶ unless( @_ )
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 1097 441 1538
402 {
403 1097 ▶ if( $self->_set_get_array_as_object( 'attr_seq' )->sort != $self->attributes->keys->sort )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_set_get_array_as_object("attr_seq")->sort != $self->attributes->keys->sort) 55 1042 1097
404 {
405 55 $self->_set_get_array_as_object( 'attr_seq', $self->attributes->keys->sort );
406 }
407 }
408 1538 return( $self->reset(@_)->_set_get_array_as_object( 'attr_seq', @_ ) );
409 }
410  
411 1581 ▶sub checksum { return( shift->reset(@_)->_set_get_scalar_as_object( 'checksum', @_ ) ); }
Subroutine checksum: called CC=1 SCAR=0.0
Pod documented
412  
413 5854 ▶sub children { return( shift->reset(@_)->_set_get_object_array_object( 'children', 'HTML::Object::Element', @_ ) ); }
Subroutine children: called CC=1 SCAR=0.0
Pod documented
414  
415 0 ▶sub class { return( ref( $_[0] ) ); }
Subroutine class: not called CC=1 SCAR=6.9
Pod documented
416  
417 # Note: HTML::Element compatibility
418 sub clone
419 54 ▶{
Subroutine clone: called CC=10 SCAR=33.2
Pod documented
420 54 my $self = shift( @_ );
421 54 my $parent = $self->parent;
422 54 $self->parent( undef );
423 # Array reference of HTML::Object::Element objects
424 54 my $kids = $self->children;
425 54 $self->children( [] );
426 54 my $new = $self->SUPER::clone();
427  
428 # NOTE: temporary diagnostic — body carries nearly all the document's
429 # real weight; dump its own fields by size the same way we did for
430 # Document, to find what's still duplicating something further down.
431 54 ▶ if( $self->tag eq 'body' )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->tag eq "body") 0 54 54
432 {
433 0 foreach my $k ( sort { total_size( $self->{ $b } ) <=> total_size( $self->{ $a } ) } CORE::keys( %$self ) )
434 {
435 0 ▶ next unless( ref( $self->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{$k} 0 0 0
436 }
437 # NOTE: drill one level deeper into close_tag itself, since it weighs
438 # disproportionately (24KB) for what should be a trivial marker object.
439 0 ▶ if( ref( $self->{close_tag} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"close_tag"}) 0 0 0
440 {
441 0 foreach my $k ( CORE::keys( %{ $self->{close_tag} } ) )
442 {
443 0 ▶ next unless( ref( $self->{close_tag}->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"close_tag"}{$k} 0 0 0
444 }
445 }
446 # NOTE: drill into a single Module::Generic::Number instance itself
447 # (body's own 'line' field) — every such field weighs an identical
448 # 10.09KB regardless of context, suggesting something inside the
449 # Number class itself, not the tree structure, is responsible.
450 0 ▶ if( ref( $self->{line} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"line"}) 0 0 0
451 {
452 0 foreach my $k ( CORE::keys( %{ $self->{line} } ) )
453 {
454 0 my $v = $self->{line}->{ $k };
455 0 ▶ if( ref( $v ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v) { } 0 0 0
456 {
457 }
458 else
459 {
460 }
461 }
462 }
463 }
464  
465 54 $new->{eid} = $self->_generate_uuid();
466 54 $self->parent( $parent );
467 54 $self->children( $kids );
468 54 my $children = $self->clone_list;
469 54 $new->children( $children );
470 $children->foreach(sub
471 20 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
472 20 shift->parent( $new );
473 54 });
474 54 $new->parent( undef );
475 54 $new->reset(1);
476 54 return( $new );
477 }
478  
479 # Note: HTML::Element compatibility
480 sub clone_list
481 54 ▶{
Subroutine clone_list: called CC=1 SCAR=0.0
Pod documented
482 54 my $self = shift( @_ );
483 54 my $a = $self->new_array;
484 $self->children->foreach(sub
485 20 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
486 20 my $e = shift( @_ );
487 20 $a->push( $e->clone );
488 54 });
489 54 return( $a );
490 }
491  
492 sub close
493 49 ▶{
Subroutine close: called CC=5 SCAR=16.1
Pod documented
494 49 my $self = shift( @_ );
495 49 my $opts = $self->_get_args_as_hash( @_ );
496 # No need to close
497 49 ▶ return( $self ) if( $self->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_empty 1 48 49
498 # if( !$parent )
499 # {
500 # warn( "No parent set for this element \"" . $self->tag . "\".\n" ) if( $self->_is_warnings_enabled( 'HTML::Object' ) );
501 # return( $self );
502 # }
503 my $e = $self->new_closing({
504 attributes => $opts->{attr},
505 attributes_sequence => $opts->{seq},
506 column => $opts->{col},
507 line => $opts->{line},
508 offset => $opts->{offset},
509 original => $opts->{raw},
510 48 ▶ tag => $self->tag,
Condition50%1/2
$self->new_closing({'attributes', $opts->{'attr'}, 'attributes_sequence', $opts->{'seq'}, 'column', $opts->{'col'}, 'line', $opts->{'line'}, 'offset', $opts->{'offset'}, 'original', $opts->{'raw'}, 'tag', $self->tag, 'debug', $self->debug}) || (return $self->pass_error)
l!l
480
MC/DC0%0/1
$self->new_closing({'attributes', $opts->{'attr'}, 'attributes_sequence', $opts->{'seq'}, 'column', $opts->{'col'}, 'line', $opts->{'line'}, 'offset', $opts->{'offset'}, 'original', $opts->{'raw'}, 'tag', $self->tag, 'debug', $self->debug}) || (return $self->pass_error)
$self->new_closing({'attributes', $opts->{'attr'}, 'attributes_sequence', $opts->{'seq'}, 'column', $opts->{'col'}, 'line', $opts->{'line'}, 'offset', $opts->{'offset'}, 'original', $opts->{'raw'}, 'tag', $self->tag, 'debug', $self->debug})
Truth table50%1/2
A
A= $self->new_closing({'attributes', $opts->{'attr'}, 'attributes_sequence', $opts->{'seq'}, 'column', $opts->{'col'}, 'line', $opts->{'line'}, 'offset', $opts->{'offset'}, 'original', $opts->{'raw'}, 'tag', $self->tag, 'debug', $self->debug})
Aresult
11
00
511 debug => $self->debug,
512 }) || return( $self->pass_error );
513 48 my $parent = $self->parent;
514 48 ▶ if( $parent )
Branch: 1 branch
BranchTrueFalseTotal
if ($parent) 8 40 48
515 {
516 8 my $pos = $parent->children->pos( $self );
517 8 ▶ return( $self->error( "Could not find the opening tag '", $self->tag, "' in our parent." ) ) if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 8 8
518 # We place the closing tag in the parent's child right after our opening tag
519 # $parent->children->splice( $pos + 1, 0, $e );
520 }
521 48 $self->is_closed(1);
522 48 $self->close_tag( $e );
523 48 $self->reset(1);
524 48 return( $self );
525 }
526  
527 506 ▶sub close_tag { return( shift->reset(@_)->_set_get_object( 'close_tag', 'HTML::Object::Element', @_ ) ); }
Subroutine close_tag: called CC=1 SCAR=0.0
Pod documented
528  
529 1486 ▶sub column { return( shift->reset(@_)->_set_get_number_as_object( 'column', @_ ) ); }
Subroutine column: called CC=1 SCAR=0.0
Pod documented
530  
531 # Note: HTML::Element compatibility
532 0 ▶sub content { return( shift->children ); }
Subroutine content: not called CC=1 SCAR=6.9
Pod documented
533  
534 # Note: HTML::Element compatibility
535 0 ▶sub content_array_ref { return( shift->children ); }
Subroutine content_array_ref: not called CC=1 SCAR=6.9
Pod documented
536  
537 # Note: HTML::Element compatibility
538 sub content_list
539 0 ▶{
Subroutine content_list: not called CC=2 SCAR=17.9
Pod documented
540 0 my $self = shift( @_ );
541 0 ▶ if( want( 'LIST' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want('LIST')) { } 0 0 0
542 {
543 0 return( $self->children->list );
544 }
545 else
546 {
547 0 return( $self->children->length );
548 }
549 }
550  
551 # Note: HTML::Element compatibility
552 sub delete
553 4 ▶{
Subroutine delete: called CC=1 SCAR=0.0
Pod documented
554 4 my $self = shift( @_ );
555 4 $self->delete_content;
556 4 $self->detach;
557 4 %$self = ();
558 4 return;
559 }
560  
561 # Note: HTML::Element compatibility
562 sub delete_content
563 4 ▶{
Subroutine delete_content: called CC=1 SCAR=0.1
Pod documented
564 4 my $self = shift( @_ );
565 $self->children->foreach(sub
566 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
567 0 $_->delete;
568 4 });
569 4 $self->reset(1);
570 4 return( $self );
571 }
572  
573 # Note: HTML::Element compatibility
574 # Does not do anything by design
575 0 ▶sub delete_ignorable_whitespace {}
Subroutine delete_ignorable_whitespace: not called CC=1 SCAR=0.0
Pod documented
576  
577 sub depth
578 0 ▶{
Subroutine depth: not called CC=2 SCAR=17.9
Pod documented
579 0 my $self = shift( @_ );
580 0 my $n = 0;
581 0 my $parent = $self;
582 0 ▶ $n++ while( $parent = $parent->parent );
Branch: 1 branch
BranchTrueFalseTotal
$parent = $parent->parent and do { ++$n } 0 0 0
583 0 return( $self->new_number( $n ) );
584 }
585  
586 sub descendants
587 0 ▶{
Subroutine descendants: not called CC=1 SCAR=6.9
Pod documented
588 0 my $self = shift( @_ );
589 0 my $a = $self->new_array;
590 $self->traverse(sub
591 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
592 0 my $e = shift( @_ );
593 0 my $class = $e->class;
594 0 ▶ return(1) unless( $class eq 'HTML::Object::Element' );
Branch: 1 branch
BranchTrueFalseTotal
unless $class eq "HTML::Object::Element" 0 0 0
595 0 $a->push( $e );
596 0 });
597 0 return( $a );
598 }
599  
600 # Note: HTML::Element compatibility
601 0 ▶sub destroy { return( shift->delete( @_ ) ); }
Subroutine destroy: not called CC=1 SCAR=6.9
Pod documented
602  
603 0 ▶sub destroy_content { return( shift->delete_content( @_ ) ); }
Subroutine destroy_content: not called CC=1 SCAR=6.9
Pod documented
604  
605 # Note: HTML::Element compatibility
606 sub detach
607 12 ▶{
Subroutine detach: called CC=3 SCAR=18.4
Pod documented
608 12 my $self = shift( @_ );
609 12 my $parent = $self->parent;
610 12 ▶ return if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 12 0 12
611 0 my $id = $self->eid;
612 0 my $pos = $parent->children->pos( $self );
613 0 ▶ if( defined( $pos ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) 0 0 0
614 {
615 0 $parent->children->splice( $pos, 1 );
616 0 $self->parent( undef() );
617 0 $parent->reset(1);
618 }
619 0 return( $parent );
620 }
621  
622 # Note: HTML::Element compatibility
623 sub detach_content
624 0 ▶{
Subroutine detach_content: not called CC=1 SCAR=6.9
Pod documented
625 0 my $self = shift( @_ );
626 $self->children->foreach(sub
627 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
628 0 shift->parent( undef() );
629 0 });
630 0 my @removed = $self->children->list;
631 0 $self->children->reset;
632 0 return( @removed );
633 }
634  
635 sub dump
636 0 ▶{
Subroutine dump: not called CC=3 SCAR=24.8
Pod documented
637 0 my $self = shift( @_ );
638 0 ▶ my $depth = shift( @_ ) || 0;
Condition0%0/2
shift @_ || 0
l!l
00
MC/DC0%0/1
shift @_ || 0
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
639 0 my $prefix = '.' x $depth;
640 0 $depth++;
641 0 my $tag = $self->tag;
642 0 ▶ printf( STDOUT "${prefix} Tag '$tag' has %d children.\n", $self->children->length ) if( $self->children->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->children->length 0 0 0
643 0 my %esc = (
644 "\a" => "\\a",
645 "\b" => "\\b",
646 "\t" => "\\t",
647 "\n" => "\\n",
648 "\f" => "\\f",
649 "\r" => "\\r",
650 "\e" => "\\e",
651 );
652 $self->children->foreach(sub
653 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
654 0 my $e = shift( @_ );
655 0 my $str = $e->original->scalar;
656 0 $str =~ s/([\a\b\t\n\f\r\e])/$esc{$1}/gs;
657 0 $str =~ s/([\0-\037])(?!\d)/sprintf('\\%o',ord($1))/eg;
658 0 $str =~ s/([\0-\037\177-\377])/sprintf('\\x%02X',ord($1))/eg;
659 0 $str =~ s/([^\040-\176])/sprintf('\\x{%X}',ord($1))/eg;
660 0 print( STDOUT "${prefix}. ${str}\n" );
661 0 ▶ $e->dump( $depth ) if( !$e->is_empty || $e->children->length );
Branch: 1 branch
BranchTrueFalseTotal
if not $e->is_empty or $e->children->length 0 0 0
Condition0%0/3
not $e->is_empty or $e->children->length
l!l&&r!l&&!r
000
MC/DC0%0/2
not $e->is_empty or $e->children->length
not $e->is_empty $e->children->length
Truth table0%0/3
not(A) or B
A= not $e->is_emptyB= $e->children->length
ABresult
1X1
011
000
662 0 });
663 0 return( $self );
664 }
665  
666 1598 ▶sub eid { return( shift->{eid} ); }
Subroutine eid: called CC=1 SCAR=0.0
Pod documented
667  
668 # Returns self, but is overriden in HTML::Object::Collection
669 # See <https://api.jquery.com/end/#end>
670 0 ▶sub end { return( shift( @_ ) ); }
Subroutine end: not called CC=1 SCAR=6.9
Pod documented
671  
672 sub extract_links
673 0 ▶{
Subroutine extract_links: not called CC=2 SCAR=17.9
Pod documented
674 0 my $self = shift( @_ );
675 0 my @tags = @_;
676 0 for( @tags )
677 {
678 0 $_ = lc( $_ );
679 }
680 0 my $wants = {};
681 0 @$wants{ @tags } = (1) x scalar( @tags );
682 0 my $has_expectation = scalar( keys( %$wants ) );
683 0 my $a = $self->new_array;
684 0 my $crawl;
685 0 my $seen = {};
686 $crawl = sub
687 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
688 0 my $kids = shift( @_ );
689 $kids->foreach(sub
690 0 ▶ {
Subroutine __ANON__: not called CC=10 SCAR=47.0
691 0 my $e = shift( @_ );
692 0 my $def;
693 0 my $tag = $e->tag;
694 0 ▶ $def = $HTML::Object::LINK_ELEMENTS->{ "$tag" } if( exists( $HTML::Object::LINK_ELEMENTS->{ "$tag" } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $$HTML::Object::LINK_ELEMENTS{"$tag"} 0 0 0
695 # return(1) if( !defined( $def ) );
696 # return(1) if( $has_expectation && !exists( $wants->{ "$tag" } ) );
697 0 ▶ if( defined( $def ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $def and !$has_expectation || $has_expectation && !exists($$wants{"$tag"})) 0 0 0
Condition0%0/9
defined $def and !$has_expectation || $has_expectation && !exists($$wants{"$tag"})
!ll&&!rl&&r
000
not $has_expectation or $has_expectation and not exists $$wants{"$tag"}
l!l&&r!l&&!r
000
$has_expectation and not exists $$wants{"$tag"}
!ll&&!rl&&r
000
MC/DC0%0/4
defined $def and !$has_expectation || $has_expectation && !exists($$wants{"$tag"})
defined $def not $has_expectation $has_expectation not exists $$wants{"$tag"}
Truth table0%0/5
A and not(B) or C and not(D)
A= defined $defB= not $has_expectationC= $has_expectationD= not exists $$wants{"$tag"}
ABCDresult
0XXX0
100X0
10100
11XX1
10111
698 (
699 !$has_expectation ||
700 ( $has_expectation && !exists( $wants->{ "$tag" } ) )
701 ) )
702 {
703 0 foreach my $attr ( @$def )
704 {
705 0 my $val;
706 0 ▶ if( $e->attributes->exists( $attr ) && length( $val = $e->attributes->get( $attr ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->attributes->exists($attr) and length($val = $e->attributes->get($attr))) 0 0 0
Condition0%0/3
$e->attributes->exists($attr) and length($val = $e->attributes->get($attr))
!ll&&!rl&&r
000
MC/DC0%0/2
$e->attributes->exists($attr) and length($val = $e->attributes->get($attr))
$e->attributes->exists($attr) length($val = $e->attributes->get($attr))
Truth table0%0/3
A and B
A= $e->attributes->exists($attr)B= length($val = $e->attributes->get($attr))
ABresult
0X0
100
111
707 {
708 0 $a->push( $self->new_hash({
709 attribute => $attr,
710 element => $e,
711 tag => $tag,
712 value => $val,
713 }) );
714 }
715 }
716 }
717 0 my $addr = Scalar::Util::refaddr( $e );
718 0 ▶ if( ++$seen->{ $addr } > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (++$seen->{$addr} > 1) 0 0 0
719 {
720 0 return(1);
721 }
722 0 $crawl->( $e->children );
723 0 return(1);
724 0 });
725 0 };
726 0 $crawl->( $self->children );
727 0 return( $a );
728 }
729  
730 # Note: HTML::Element compatibility
731 # sub find { return( shift->find_by_tag_name( @_ ) ); }
732 # find() is a xpath method
733  
734 sub find_by_attribute
735 0 ▶{
Subroutine find_by_attribute: not called CC=5 SCAR=34.0
Pod documented
736 0 my $self = shift( @_ );
737 0 my( $att, $val ) = @_;
738 0 $att = lc( $att );
739 0 ▶ return( $self->error( "No attribute was provided." ) ) if( !length( $att ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $att 0 0 0
740 0 my $a = $self->new_array;
741 0 ▶ $a->push( $self ) if( $self->attributes->exists( $att ) && $self->attributes->get( $att ) eq $val );
Branch: 1 branch
BranchTrueFalseTotal
if $self->attributes->exists($att) and $self->attributes->get($att) eq $val 0 0 0
Condition0%0/3
$self->attributes->exists($att) and $self->attributes->get($att) eq $val
!ll&&!rl&&r
000
MC/DC0%0/2
$self->attributes->exists($att) and $self->attributes->get($att) eq $val
$self->attributes->exists($att) $self->attributes->get($att) eq $val
Truth table0%0/3
A and B
A= $self->attributes->exists($att)B= $self->attributes->get($att) eq $val
ABresult
0X0
100
111
742 0 my $crawl;
743 $crawl = sub
744 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
745 0 my $elems = shift( @_ );
746 $elems->foreach(sub
747 0 ▶ {
Subroutine __ANON__: not called CC=5 SCAR=34.0
748 0 my $e = shift( @_ );
749 0 ▶ return(1) if( $e->class ne 'HTML::Object::Element' );
Branch: 1 branch
BranchTrueFalseTotal
if $e->class ne "HTML::Object::Element" 0 0 0
750 0 ▶ $a->push( $e ) if( $e->attributes->exists( $att ) && $e->attributes->get( $att ) eq $val );
Branch: 1 branch
BranchTrueFalseTotal
if $e->attributes->exists($att) and $e->attributes->get($att) eq $val 0 0 0
Condition0%0/3
$e->attributes->exists($att) and $e->attributes->get($att) eq $val
!ll&&!rl&&r
000
MC/DC0%0/2
$e->attributes->exists($att) and $e->attributes->get($att) eq $val
$e->attributes->exists($att) $e->attributes->get($att) eq $val
Truth table0%0/3
A and B
A= $e->attributes->exists($att)B= $e->attributes->get($att) eq $val
ABresult
0X0
100
111
751 0 ▶ $crawl->( $e->children ) if( $e->children->length > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $e->children->length > 0 0 0 0
752 0 });
753 0 };
754 0 ▶ $crawl->( $self->children ) if( $self->children->length > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->children->length > 0 0 0 0
755 0 return( $a );
756 }
757  
758 sub find_by_tag_name
759 0 ▶{
Subroutine find_by_tag_name: not called CC=4 SCAR=30.0
Pod documented
760 0 my $self = shift( @_ );
761 0 my @tags = @_;
762 0 for( @tags )
763 {
764 0 $_ = lc( $_ );
765 }
766 0 my $tags = {};
767 0 @$tags{ @tags } = (1) x scalar( @tags );
768 0 my $a = $self->new_array;
769 0 ▶ $a->push( $self ) if( exists( $tags->{ $self->tag } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $$tags{$self->tag} 0 0 0
770 0 my $crawl;
771 $crawl = sub
772 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
773 0 my $elems = shift( @_ );
774 $elems->foreach(sub
775 0 ▶ {
Subroutine __ANON__: not called CC=4 SCAR=30.0
776 0 my $e = shift( @_ );
777 # return(1) if( $e->class ne 'HTML::Object::Element' );
778 0 ▶ return(1) if( !$self->_is_a( $e => 'HTML::Object::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($e, "HTML::Object::Element") 0 0 0
779 0 ▶ $a->push( $e ) if( exists( $tags->{ $e->tag } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $$tags{$e->tag} 0 0 0
780 0 ▶ $crawl->( $e->children ) if( $e->children->length > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $e->children->length > 0 0 0 0
781 0 });
782 0 };
783 0 ▶ $crawl->( $self->children ) if( $self->children->length > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->children->length > 0 0 0 0
784 0 return( $a );
785 }
786  
787 0 ▶sub has_children { return( shift->children->is_empty ? 0 : 1 ); }
Subroutine has_children: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
(shift())->children->is_empty ? : 0 0 0
788  
789 19 ▶sub id : lvalue { return( shift->_set_get_id( @_ ) ); }
Subroutine id: called CC=1 SCAR=0.0
Pod documented
790  
791 # Note: Similar to HTML::ELement, but not quite, because we have no concept of pos(), so this just add to the stack of children
792 sub insert_element
793 0 ▶{
Subroutine insert_element: not called CC=4 SCAR=30.0
Pod documented
794 0 my $self = shift( @_ );
795 0 ▶ my $e = shift( @_ ) || return( $self->error( "No html element was provided to insert." ) );
Condition0%0/2
shift @_ || (return $self->error('No html element was provided to insert.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No html element was provided to insert.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
796 0 ▶ return( $self->error( "Element provided (", overload::StrVal( $e ), ") is not an object." ) ) if( !$self->_is_object( $e ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($e) 0 0 0
797 0 ▶ return( $self->error( "Element provided (", overload::StrVal( $e ), ") is not an HTML::Object::Element." ) ) if( !$e->isa( 'HTML::Object::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $e->isa("HTML::Object::Element") 0 0 0
798 0 $self->push_content( $e );
799 0 $self->reset(1);
800 0 return( $e );
801 }
802  
803 # Used to store arbitrarily data for internal purpose
804 38 ▶sub internal { return( shift->reset(@_)->_set_get_hash_as_mix_object( '_internal', @_ ) ); }
Subroutine internal: called CC=1 SCAR=0.0
Pod documented
805  
806 683 ▶sub is_closed { return( shift->reset(@_)->_set_get_boolean( 'is_closed', @_ ) ); }
Subroutine is_closed: called CC=1 SCAR=0.0
Pod documented
807  
808 # Note: Different from HTML::Element in that this is a flag derived from the dictionary. To get the equivalent, one must use has_children()
809 2417 ▶sub is_empty { return( shift->reset(@_)->_set_get_boolean( 'is_empty', @_ ) ); }
Subroutine is_empty: called CC=1 SCAR=0.0
Pod documented
810  
811 10 ▶sub is_valid_attribute { return( $_[1] =~ /^$ATTRIBUTE_NAME_RE$/ ? 1 : 0 ); }
Subroutine is_valid_attribute: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[1] =~ /^$HTML::Object::Element::ATTRIBUTE_NAME_RE$/ ? : 10 0 10
812  
813 0 ▶sub is_void { return( shift->reset(@_)->is_empty( @_ ) ); }
Subroutine is_void: not called CC=1 SCAR=6.9
Pod documented
814  
815 # Note: Compatibility with HTML::Element
816 sub left
817 134 ▶{
Subroutine left: called CC=5 SCAR=16.4
Pod documented
818 134 my $self = shift( @_ );
819 134 ▶ my $offset = @_ ? int( shift( @_ ) ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 134 134
820 134 my $pos = $self->pos;
821 # We return empty if we could not find our object within our parent's children; or
822 # the requested offset position is higher than the position of our object
823 134 ▶ return( $self->new_array ) if( !defined( $pos ) || $offset > $pos );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $pos or $offset > $pos 11 123 134
Condition66%2/3
not defined $pos or $offset > $pos
l!l&&r!l&&!r
110123
MC/DC50%1/2
not defined $pos or $offset > $pos
not defined $pos $offset > $pos
Truth table66%2/3
not(A) or B
A= not defined $posB= $offset > $pos
ABresult
1X1
011
000
824 123 my $kids = $self->parent->children;
825 # I am my parent's only child; no need to bother
826 123 ▶ return( $self->new_array ) if( $kids->length == 1 );
Branch: 1 branch
BranchTrueFalseTotal
if $kids->length == 1 0 123 123
827 # We use position as offset length which will put us right before our own element
828 123 return( $kids->offset( $offset, ( $pos - $offset ) ) );
829 }
830  
831 1486 ▶sub line { return( shift->_set_get_number_as_object( 'line', @_ ) ); }
Subroutine line: called CC=1 SCAR=0.0
Pod documented
832  
833 # Note: HTML::Element compatibility
834 sub lineage
835 115 ▶{
Subroutine lineage: called CC=2 SCAR=6.9
Pod documented
836 115 my $self = shift( @_ );
837 115 my $parent = $self;
838 115 my $lineage = $self->new_array;
839 115 ▶ while( $parent = $parent->parent )
Branch: 1 branch
BranchTrueFalseTotal
if ($parent = $parent->parent) 350 115 465
840 {
841 350 $lineage->push( $parent );
842 }
843 115 return( $lineage );
844 }
845  
846 sub lineage_tag_names
847 0 ▶{
Subroutine lineage_tag_names: not called CC=2 SCAR=17.9
Pod documented
848 0 my $self = shift( @_ );
849 0 my $a = $self->new_array;
850 0 my $parent = $self;
851 0 ▶ while( $parent = $parent->parent )
Branch: 1 branch
BranchTrueFalseTotal
if ($parent = $parent->parent) 0 0 0
852 {
853 0 $a->push( $parent->tag->scalar );
854 }
855 0 return( $a );
856 }
857  
858 sub look
859 3 ▶{
Subroutine look: called CC=5 SCAR=21.2
Pod documented
860 3 my $self = shift( @_ );
861 3 my $opts = {};
862 3 ▶ $opts = pop( @_ ) if( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 3 0 3
863 3 my $p = [];
864 3 ▶ for( my $i = 0; $i < scalar( @_ ); )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @_) 3 3 6
865 {
866 3 ▶ if( ref( $_[$i] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[$i]) { } 0 3 3
867 {
868 0 ▶ return( $self->error( "Reference provided (", overload::StrVal( $_[$i] ), "), but the only reference I accept is code reference." ) ) if( ref( $_[$i] ) ne 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[$i] ne "CODE" 0 0 0
869 0 push( @$p, $_[ $i++ ] );
870 }
871 else
872 {
873 3 push( @$p, {
874 key => $_[$i],
875 val => $_[$i + 1],
876 });
877 3 $i += 2;
878 }
879 }
880 3 my $a = $self->new_array;
881 3 my( $check_elem, $crawl_down );
882 $check_elem = sub
883 107 ▶ {
Subroutine __ANON__: called CC=28 SCAR=53.4
884 107 my $e = shift( @_ );
885 107 my $def = shift( @_ );
886 107 my $attr = $e->attributes;
887 # Assume ok, then check otherwise
888 107 my $ok = 1;
889 107 foreach my $this ( @$p )
890 {
891 107 ▶ if( ref( $this ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this eq 'CODE') { } 0 107 107
892 {
893 0 local $_ = $e;
894 0 my $rc = $this->( $e );
895 0 ▶ $ok = 0, last if( !$rc );
Branch: 1 branch
BranchTrueFalseTotal
unless $rc 0 0 0
896 }
897 else
898 {
899 107 ▶ if( $this->{key} eq '_tag' )
Branch: 2 branches
BranchTrueFalseTotal
if ($this->{'key'} eq '_tag') { } 107 0 107
elsif (not $attr->exists($this->{'key'})) { } 0 0 0
900 {
901 107 ▶ if( ref( $this->{val} ) eq 'Regexp' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this->{'val'} eq 'Regexp') { } 0 107 107
902 {
903 0 ▶ $ok = 0, last if( $e->tag !~ /$this->{val}/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $e->tag =~ /$this->{"val"}/ 0 0 0
904 }
905 else
906 {
907 107 ▶ $ok = 0, last if( $e->tag ne $this->{val} );
Branch: 1 branch
BranchTrueFalseTotal
if $e->tag ne $this->{"val"} 97 10 107
908 }
909 }
910 elsif( !$attr->exists( $this->{key} ) )
911 {
912 0 ▶ if( !defined( $this->{val} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $this->{'val'}) { } 0 0 0
913 {
914 # Good to go; the user searches for an attribute with an undefined value
915 # in other term, the user wants an element whose attribute does not exist
916 }
917 else
918 {
919 0 $ok = 0, last;
920 }
921 }
922 else
923 {
924 0 my $val = $attr->get( $this->{key} );
925 0 ▶ if( defined( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
926 {
927 0 ▶ if( ref( $this->{val} ) eq 'Regexp' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $this->{'val'} eq 'Regexp') { } 0 0 0
elsif (ref $this->{'val'} and ref $this->{'val'} ne ref $val or !ref($val) || overload::Method($val . '""') and lc "$val" ne lc "$this->{'val'}") { } 0 0 0
928 {
929 0 ▶ $ok = 0, last if( $val !~ /$this->{val}/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $val =~ /$this->{"val"}/ 0 0 0
930 }
931 ▶ elsif( (
Condition0%0/12
ref $this->{"val"} and ref $this->{"val"} ne ref $val or !ref($val) || overload::Method($val . '""') and lc "$val" ne lc qq[$this->{"val"}]
l!l&&r!l&&!r
000
ref $this->{"val"} and ref $this->{"val"} ne ref $val
!ll&&!rl&&r
000
!ref($val) || overload::Method($val . '""') and lc "$val" ne lc qq[$this->{"val"}]
!ll&&!rl&&r
000
not ref $val or overload::Method($val . '""')
l!l&&r!l&&!r
000
MC/DC0%0/5
ref $this->{"val"} and ref $this->{"val"} ne ref $val or !ref($val) || overload::Method($val . '""') and lc "$val" ne lc qq[$this->{"val"}]
ref $this->{"val"} ref $this->{"val"} ne ref $val not ref $val overload::Method($val . '""') lc "$val" ne lc qq[$this->{"val"}]
Truth table0%0/11
A and B or not(C) or D and E
A= ref $this->{"val"}B= ref $this->{"val"} ne ref $valC= not ref $valD= overload::Method($val . '""')E= lc "$val" ne lc qq[$this->{"val"}]
ABCDEresult
11XXX1
0X1X11
0X0111
101X11
100111
0X00X0
0X1X00
0X0100
1000X0
101X00
100100
932 ref( $this->{val} ) &&
933 ref( $this->{val} ) ne ref( $val )
934 ) ||
935 (
936 ( !ref( $val ) || overload::Method( $val. '""' ) ) &&
937 lc( "$val" ) ne lc( "$this->{val}" )
938 ) )
939 {
940 0 $ok = 0, last;
941 }
942 }
943 else
944 {
945 0 ▶ $ok = 0, last if( defined( $this->{val} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $this->{"val"} 0 0 0
946 }
947 }
948 }
949 }
950  
951 # We passed all checks, no checking our children
952 107 ▶ $a->push( $e ) if( $ok );
Branch: 1 branch
BranchTrueFalseTotal
if $ok 10 97 107
953 # Stop here since we reached the maximum number of matches
954 107 ▶ return if( CORE::exists( $opts->{max_match} ) && $a->length >= $opts->{max_match} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"max_match"} and $a->length >= $opts->{"max_match"} 0 107 107
Condition33%1/3
exists $opts->{"max_match"} and $a->length >= $opts->{"max_match"}
!ll&&!rl&&r
10700
MC/DC0%0/2
exists $opts->{"max_match"} and $a->length >= $opts->{"max_match"}
exists $opts->{"max_match"} $a->length >= $opts->{"max_match"}
Truth table33%1/3
A and B
A= exists $opts->{"max_match"}B= $a->length >= $opts->{"max_match"}
ABresult
0X0
100
111
955 # Don't go down or up further if we reached the maximum level
956 107 ▶ return(1) if( CORE::exists( $opts->{max_level} ) && ( $def->{level} + 1 ) > $opts->{max_level} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"max_level"} and $def->{"level"} + 1 > $opts->{"max_level"} 7 100 107
Condition100%3/3
exists $opts->{"max_level"} and $def->{"level"} + 1 > $opts->{"max_level"}
!ll&&!rl&&r
9917
MC/DC100%2/2
exists $opts->{"max_level"} and $def->{"level"} + 1 > $opts->{"max_level"}
exists $opts->{"max_level"} $def->{"level"} + 1 > $opts->{"max_level"}
Truth table100%3/3
A and B
A= exists $opts->{"max_level"}B= $def->{"level"} + 1 > $opts->{"max_level"}
ABresult
0X0
100
111
957 100 $def->{level}++;
958 100 ▶ if( $opts->{direction} eq 'down' )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'direction'} eq 'down') { } 100 0 100
elsif ($opts->{'direction'} eq 'up') { } 0 0 0
959 {
960 100 ▶ $crawl_down->( $e->children, $def ) if( $e->children->length > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $e->children->length > 0 22 78 100
961 }
962 elsif( $opts->{direction} eq 'up' )
963 {
964 0 ▶ $check_elem->( $e->parent ) if( $e->parent );
Branch: 1 branch
BranchTrueFalseTotal
if $e->parent 0 0 0
965 }
966 100 $def->{level}--;
967 100 return(1);
968 3 };
969  
970 $crawl_down = sub
971 22 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
972 22 my $kids = shift( @_ );
973 22 my $def = shift( @_ );
974 # $kids->foreach( $check_elem );
975 $kids->foreach(sub
976 104 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
977 104 $check_elem->( $_, $def );
978 22 });
979 3 };
980  
981 3 my $def = { level => 0 };
982 3 $check_elem->( $self, $def );
983 # return( $a->length > 0 ? $a : '' );
984 3 return( $a );
985 }
986  
987 sub look_down
988 3 ▶{
Subroutine look_down: called CC=2 SCAR=6.9
Pod documented
989 3 my $self = shift( @_ );
990 3 my $opts = {};
991 3 ▶ $opts = pop( @_ ) if( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 1 2 3
992 3 $opts->{direction} = 'down';
993 3 return( $self->look( @_, $opts ) );
994 }
995  
996 sub look_up
997 0 ▶{
Subroutine look_up: not called CC=2 SCAR=17.9
Pod documented
998 0 my $self = shift( @_ );
999 0 my $opts = {};
1000 0 ▶ $opts = pop( @_ ) if( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 0 0
1001 0 $opts->{direction} = 'up';
1002 0 return( $self->look( @_, $opts ) );
1003 }
1004  
1005 0 ▶sub looks_like_html { return( $_[1] =~ /$LOOK_LIKE_HTML/ ? 1 : 0 ); }
Subroutine looks_like_html: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[1] =~ /$HTML::Object::Element::LOOK_LIKE_HTML/ ? : 0 0 0
1006  
1007 # sub looks_like_it_has_html { return( $_[1] =~ /$LOOK_LIKE_IT_HAS_HTML/ ? 1 : 0 ); }
1008 sub looks_like_it_has_html
1009 2 ▶{
Subroutine looks_like_it_has_html: called CC=2 SCAR=6.9
Pod documented
1010 2 my $self = shift( @_ );
1011 2 ▶ return( $_[0] =~ /$LOOK_LIKE_IT_HAS_HTML/ ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /$HTML::Object::Element::LOOK_LIKE_IT_HAS_HTML/ ? : 1 1 2
1012 }
1013  
1014 0 ▶sub modified { return( shift->_set_get_boolean( 'modified', @_ ) ); }
Subroutine modified: not called CC=1 SCAR=6.9
Pod documented
1015  
1016 sub new_attribute
1017 0 ▶{
Subroutine new_attribute: not called CC=3 SCAR=24.8
Pod documented
1018 0 my $self = shift( @_ );
1019 0 ▶ $self->_load_class( 'HTML::Object::Attribute' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::Attribute") or return $self->pass_error 0 0 0
1020 0 ▶ my $att = HTML::Object::Attribute->new( @_ ) ||
Condition0%0/2
'HTML::Object::Attribute'->new(@_) || (return $self->pass_error('HTML::Object::Attribute'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::Attribute'->new(@_) || (return $self->pass_error('HTML::Object::Attribute'->error))
'HTML::Object::Attribute'->new(@_)
Truth table0%0/2
A
A= 'HTML::Object::Attribute'->new(@_)
Aresult
11
00
1021 return( $self->pass_error( HTML::Object::Attribute->error ) );
1022 0 return( $att );
1023 }
1024  
1025 sub new_closing
1026 0 ▶{
Subroutine new_closing: not called CC=3 SCAR=24.8
Pod documented
1027 0 my $self = shift( @_ );
1028 0 ▶ $self->_load_class( 'HTML::Object::Closing' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::Closing") or return $self->pass_error 0 0 0
1029 0 ▶ my $e = HTML::Object::Closing->new( @_ ) ||
Condition0%0/2
'HTML::Object::Closing'->new(@_) || (return $self->pass_error('HTML::Object::Closing'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::Closing'->new(@_) || (return $self->pass_error('HTML::Object::Closing'->error))
'HTML::Object::Closing'->new(@_)
Truth table0%0/2
A
A= 'HTML::Object::Closing'->new(@_)
Aresult
11
00
1030 return( $self->pass_error( HTML::Object::Closing->error ) );
1031 0 return( $e );
1032 }
1033  
1034 sub new_document
1035 0 ▶{
Subroutine new_document: not called CC=3 SCAR=24.8
Pod documented
1036 0 my $self = shift( @_ );
1037 0 ▶ $self->_load_class( 'HTML::Object::Document' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::Document") or return $self->pass_error 0 0 0
1038 0 ▶ my $e = HTML::Object::Document->new( debug => $self->debug ) ||
Condition0%0/2
'HTML::Object::Document'->new('debug', $self->debug) || (return $self->pass_error('HTML::Object::Document'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::Document'->new('debug', $self->debug) || (return $self->pass_error('HTML::Object::Document'->error))
'HTML::Object::Document'->new('debug', $self->debug)
Truth table0%0/2
A
A= 'HTML::Object::Document'->new('debug', $self->debug)
Aresult
11
00
1039 return( $self->pass_error( HTML::Object::Document->error ) );
1040 0 return( $e );
1041 }
1042  
1043 sub new_element
1044 0 ▶{
Subroutine new_element: not called CC=4 SCAR=30.0
Pod documented
1045 0 my $self = shift( @_ );
1046 0 ▶ my $tag = shift( @_ ) || return( $self->error( "No tag was provided to create an element." ) );
Condition0%0/2
shift @_ || (return $self->error('No tag was provided to create an element.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No tag was provided to create an element.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1047 0 ▶ my $dict = HTML::Object->get_definition( $tag ) || return( $self->pass_error( HTML::Object->error ) );
Condition0%0/2
'HTML::Object'->get_definition($tag) || (return $self->pass_error('HTML::Object'->error))
l!l
00
MC/DC0%0/1
'HTML::Object'->get_definition($tag) || (return $self->pass_error('HTML::Object'->error))
'HTML::Object'->get_definition($tag)
Truth table0%0/2
A
A= 'HTML::Object'->get_definition($tag)
Aresult
11
00
1048 my $e = HTML::Object::Element->new({
1049 is_empty => $dict->{is_empty},
1050 tag => $dict->{tag},
1051 0 ▶ debug => $self->debug,
Condition0%0/2
'HTML::Object::Element'->new({'is_empty', $dict->{'is_empty'}, 'tag', $dict->{'tag'}, 'debug', $self->debug}) || (return $self->pass_error('HTML::Object::Element'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::Element'->new({'is_empty', $dict->{'is_empty'}, 'tag', $dict->{'tag'}, 'debug', $self->debug}) || (return $self->pass_error('HTML::Object::Element'->error))
'HTML::Object::Element'->new({'is_empty', $dict->{'is_empty'}, 'tag', $dict->{'tag'}, 'debug', $self->debug})
Truth table0%0/2
A
A= 'HTML::Object::Element'->new({'is_empty', $dict->{'is_empty'}, 'tag', $dict->{'tag'}, 'debug', $self->debug})
Aresult
11
00
1052 }) || return( $self->pass_error( HTML::Object::Element->error ) );
1053 0 return( $e );
1054 }
1055  
1056 sub new_from_lol
1057 0 ▶{
Subroutine new_from_lol: not called CC=7 SCAR=40.3
Pod documented
1058 0 my $self = shift( @_ );
1059 0 my $a = $self->new_array;
1060 0 my @args = @_;
1061 0 my $crawl;
1062 $crawl = sub
1063 0 ▶ {
Subroutine __ANON__: not called CC=28 SCAR=67.0
1064 0 my $ref = shift( @_ );
1065 0 my $parent;
1066 0 ▶ $parent = shift( @_ ) if( scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 0 0 0
1067 0 my $elem;
1068 0 foreach my $this ( @$ref )
1069 {
1070 0 ▶ if( $self->_is_array( $this ) )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_is_array($this)) { } 0 0 0
elsif ($self->_is_hash($this)) { } 0 0 0
elsif ($self->_is_object($this) and $this->isa('HTML::Object::Element')) { } 0 0 0
1071 {
1072 0 ▶ my $e = $crawl->( $this, ( $elem // $parent ) ) || return;
Condition0%0/5
&$crawl($this, $elem // $parent) || (return)
l!l
00
$elem // $parent
l!l&&r!l&&!r
000
MC/DC0%0/1
&$crawl($this, $elem // $parent) || (return)
&$crawl($this, $elem // $parent)
MC/DC0%0/2
$elem // $parent
$elem $parent
Truth table0%0/2
A
A= &$crawl($this, $elem // $parent)
Aresult
11
00
Truth table0%0/3
A // B
A= $elemB= $parent
ABresult
1X1
011
000
1073 0 ▶ if( defined( $elem ) || defined( $parent ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $elem or defined $parent) 0 0 0
Condition0%0/3
defined $elem or defined $parent
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $elem or defined $parent
defined $elem defined $parent
Truth table0%0/3
A or B
A= defined $elemB= defined $parent
ABresult
1X1
011
000
1074 {
1075 0 ▶ $e->parent( $elem // $parent );
Condition0%0/3
$elem // $parent
l!l&&r!l&&!r
000
MC/DC0%0/2
$elem // $parent
$elem $parent
Truth table0%0/3
A // B
A= $elemB= $parent
ABresult
1X1
011
000
1076 0 ▶ ( $elem // $parent )->children->push( $e );
Condition0%0/3
$elem // $parent
l!l&&r!l&&!r
000
MC/DC0%0/2
$elem // $parent
$elem $parent
Truth table0%0/3
A // B
A= $elemB= $parent
ABresult
1X1
011
000
1077 }
1078 }
1079 elsif( $self->_is_hash( $this ) )
1080 {
1081 0 ▶ return( $self->error( "Hash of attributes set found before tag name definition" ) ) if( !defined( $elem ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elem 0 0 0
1082 0 $elem->attributes( $this );
1083 }
1084 ▶ elsif( $self->_is_object( $this ) && $this->isa( 'HTML::Object::Element' ) )
Condition0%0/3
$self->_is_object($this) and $this->isa("HTML::Object::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($this) and $this->isa("HTML::Object::Element")
$self->_is_object($this) $this->isa("HTML::Object::Element")
Truth table0%0/3
A and B
A= $self->_is_object($this)B= $this->isa("HTML::Object::Element")
ABresult
0X0
100
111
1085 {
1086 0 ▶ my $custodian = ( $elem // $parent );
Condition0%0/3
$elem // $parent
l!l&&r!l&&!r
000
MC/DC0%0/2
$elem // $parent
$elem $parent
Truth table0%0/3
A // B
A= $elemB= $parent
ABresult
1X1
011
000
1087 0 ▶ my $e = $this->parent ? $this->clone : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->parent ? : 0 0 0
1088 0 ▶ return( $self->error( "Found an element object \"", $e->tag, "\" to add to the tree, but no parent was provided nor any element was initiated yet." ) ) if( !defined( $custodian ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $custodian 0 0 0
1089 0 $e->parent( $custodian );
1090 0 $custodian->children->push( $e );
1091 }
1092 else
1093 {
1094 0 ▶ return( $self->error( "Found an object ($this), but I do not know what to do with it." ) ) if( $self->_is_object( $this ) && ( !overload::Overloaded( $this ) || ( overload::Overloaded( $this ) && !overload::Method( $this => '""' ) ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_object($this) and !overload::Overloaded($this) || overload::Overloaded($this) && !overload::Method($this, "\"\"") 0 0 0
Condition0%0/9
$self->_is_object($this) and !overload::Overloaded($this) || overload::Overloaded($this) && !overload::Method($this, "\"\"")
!ll&&!rl&&r
000
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
$self->_is_object($this) and !overload::Overloaded($this) || overload::Overloaded($this) && !overload::Method($this, "\"\"")
$self->_is_object($this) not overload::Overloaded($this) overload::Overloaded($this) not overload::Method($this, "\"\"")
Truth table0%0/5
A and not(B) or C and not(D)
A= $self->_is_object($this)B= not overload::Overloaded($this)C= overload::Overloaded($this)D= not overload::Method($this, "\"\"")
ABCDresult
0XXX0
100X0
10100
11XX1
10111
1095 # This is the element tag name
1096 0 ▶ if( !defined( $elem ) && "$this" =~ /^\w+$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $elem and "$this" =~ /^\w+$/) { } 0 0 0
Condition0%0/3
not defined $elem and "$this" =~ /^\w+$/
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $elem and "$this" =~ /^\w+$/
not defined $elem "$this" =~ /^\w+$/
Truth table0%0/3
not(A) and B
A= not defined $elemB= "$this" =~ /^\w+$/
ABresult
0X0
100
111
1097 {
1098 0 ▶ $elem = $self->new_element( "$this" ) || return;
Condition0%0/2
$self->new_element("$this") || (return)
l!l
00
MC/DC0%0/1
$self->new_element("$this") || (return)
$self->new_element("$this")
Truth table0%0/2
A
A= $self->new_element("$this")
Aresult
11
00
1099 0 ▶ if( defined( $parent ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent) 0 0 0
1100 {
1101 0 $elem->parent( $parent );
1102 0 $parent->children->push( $elem );
1103 }
1104 }
1105 # Text node added as a child
1106 else
1107 {
1108 0 ▶ my $custodian = ( $elem // $parent );
Condition0%0/3
$elem // $parent
l!l&&r!l&&!r
000
MC/DC0%0/2
$elem // $parent
$elem $parent
Truth table0%0/3
A // B
A= $elemB= $parent
ABresult
1X1
011
000
1109 0 ▶ return( $self->error( "Found a text to add to the tree, but no parent was provided nor any element was initiated yet." ) ) if( !defined( $custodian ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $custodian 0 0 0
1110 0 ▶ my $t = $self->new_text( "$this" ) || return;
Condition0%0/2
$self->new_text("$this") || (return)
l!l
00
MC/DC0%0/1
$self->new_text("$this") || (return)
$self->new_text("$this")
Truth table0%0/2
A
A= $self->new_text("$this")
Aresult
11
00
1111 0 $t->parent( $custodian );
1112 0 $custodian->children->push( $t );
1113 }
1114 }
1115 }
1116 0 return( $elem );
1117 0 };
1118  
1119 0 foreach my $this ( @args )
1120 {
1121 0 ▶ return( $self->error( "I was expecting an array reference, but instead got '$this'." ) ) if( !$self->_is_array( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($this) 0 0 0
1122 # There are more than one elements provided in this array definition, i.e. multiple html tags at the top level
1123 # so we create a special document html element to contain them
1124 0 ▶ if( scalar( @$this ) > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$this > 0) { } 0 0 0
1125 {
1126 0 ▶ my $doc = $self->new_document || return;
Condition0%0/2
$self->new_document || (return)
l!l
00
MC/DC0%0/1
$self->new_document || (return)
$self->new_document
Truth table0%0/2
A
A= $self->new_document
Aresult
11
00
1127 0 ▶ $crawl->( $this => $doc ) || return;
Branch: 1 branch
BranchTrueFalseTotal
&$crawl($this, $doc) or return 0 0 0
1128 0 $a->push( $doc );
1129 }
1130 else
1131 {
1132 0 ▶ my $e = $crawl->( $this ) || return;
Condition0%0/2
&$crawl($this) || (return)
l!l
00
MC/DC0%0/1
&$crawl($this) || (return)
&$crawl($this)
Truth table0%0/2
A
A= &$crawl($this)
Aresult
11
00
1133 0 $a->push( $e );
1134 }
1135 }
1136 0 return( $a );
1137 }
1138  
1139 sub new_parser
1140 0 ▶{
Subroutine new_parser: not called CC=3 SCAR=24.8
Pod documented
1141 0 my $self = shift( @_ );
1142 0 ▶ $self->_load_class( 'HTML::Object' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object") or return $self->pass_error 0 0 0
1143 0 ▶ my $p = HTML::Object->new( debug => $self->debug ) ||
Condition0%0/2
'HTML::Object'->new('debug', $self->debug) || (return $self->pass_error('HTML::Object'->error))
l!l
00
MC/DC0%0/1
'HTML::Object'->new('debug', $self->debug) || (return $self->pass_error('HTML::Object'->error))
'HTML::Object'->new('debug', $self->debug)
Truth table0%0/2
A
A= 'HTML::Object'->new('debug', $self->debug)
Aresult
11
00
1144 return( $self->pass_error( HTML::Object->error ) );
1145 0 return( $p );
1146 }
1147  
1148 sub new_text
1149 0 ▶{
Subroutine new_text: not called CC=5 SCAR=34.0
Pod documented
1150 0 my $self = shift( @_ );
1151 0 my $p = {};
1152 0 ▶ if( scalar( @_ ) == 1 && ref( $_[0] ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and ref $_[0] eq 'HASH') { } 0 0 0
Condition0%0/3
scalar @_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
1153 {
1154 0 $p = shift( @_ );
1155 }
1156 else
1157 {
1158 0 $p->{value} = join( '', @_ );
1159 }
1160 0 $p->{debug} = $self->debug;
1161 0 ▶ $self->_load_class( 'HTML::Object::Text' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::Text") or return $self->pass_error 0 0 0
1162 0 ▶ my $e = HTML::Object::Text->new( $p ) ||
Condition0%0/2
'HTML::Object::Text'->new($p) || (return $self->pass_error('HTML::Object::Text'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::Text'->new($p) || (return $self->pass_error('HTML::Object::Text'->error))
'HTML::Object::Text'->new($p)
Truth table0%0/2
A
A= 'HTML::Object::Text'->new($p)
Aresult
11
00
1163 return( $self->pass_error( HTML::Object::Text->error ) );
1164 0 return( $e );
1165 }
1166  
1167 # TODO: next()
1168  
1169 # Note: HTML::Element compatibility
1170 sub normalize_content
1171 0 ▶{
Subroutine normalize_content: not called CC=1 SCAR=6.9
Pod documented
1172 0 my $self = shift( @_ );
1173 0 my $children = $self->children;
1174 0 my $new = $self->new_array;
1175 0 my $prev;
1176 $children->foreach(sub
1177 0 ▶ {
Subroutine __ANON__: not called CC=9 SCAR=45.0
1178 0 ▶ if( ( defined( $_ ) && $self->_is_a( $_ => 'HTML::Object::Text' ) && defined( $prev ) && $self->_is_a( $prev => 'HTML::Object::Text' ) ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_ and $self->_is_a($_, "HTML::Object::Text") and defined $prev and $self->_is_a($prev, "HTML::Object::Text") or defined $_ and $self->_is_a($_, "HTML::Object::Space") and defined $prev and $self->_is_a($prev, "HTML::Object::Space")) 0 0 0
Condition0%0/21
defined $_ and $self->_is_a($_, "HTML::Object::Text") and defined $prev and $self->_is_a($prev, "HTML::Object::Text") or defined $_ and $self->_is_a($_, "HTML::Object::Space") and defined $prev and $self->_is_a($prev, "HTML::Object::Space")
l!l&&r!l&&!r
000
defined $_ and $self->_is_a($_, "HTML::Object::Text") and defined $prev and $self->_is_a($prev, "HTML::Object::Text")
!ll&&!rl&&r
000
defined $_ and $self->_is_a($_, "HTML::Object::Text") and defined $prev
!ll&&!rl&&r
000
defined $_ and $self->_is_a($_, "HTML::Object::Text")
!ll&&!rl&&r
000
defined $_ and $self->_is_a($_, "HTML::Object::Space") and defined $prev and $self->_is_a($prev, "HTML::Object::Space")
!ll&&!rl&&r
000
defined $_ and $self->_is_a($_, "HTML::Object::Space") and defined $prev
!ll&&!rl&&r
000
defined $_ and $self->_is_a($_, "HTML::Object::Space")
!ll&&!rl&&r
000
MC/DC0%0/8
defined $_ and $self->_is_a($_, "HTML::Object::Text") and defined $prev and $self->_is_a($prev, "HTML::Object::Text") or defined $_ and $self->_is_a($_, "HTML::Object::Space") and defined $prev and $self->_is_a($prev, "HTML::Object::Space")
defined $_ $self->_is_a($_, "HTML::Object::Text") defined $prev $self->_is_a($prev, "HTML::Object::Text") defined $_ $self->_is_a($_, "HTML::Object::Space") defined $prev $self->_is_a($prev, "HTML::Object::Space")
Truth table0%0/21
A and B and C and D or E and F and G and H
A= defined $_B= $self->_is_a($_, "HTML::Object::Text")C= defined $prevD= $self->_is_a($prev, "HTML::Object::Text")E= defined $_F= $self->_is_a($_, "HTML::Object::Space")G= defined $prevH= $self->_is_a($prev, "HTML::Object::Space")
ABCDEFGHresult
1111XXXX1
0XXX11111
10XX11111
110X11111
111011111
0XXX0XXX0
0XXX10XX0
0XXX110X0
0XXX11100
10XX0XXX0
10XX10XX0
10XX110X0
10XX11100
110X0XXX0
110X10XX0
110X110X0
110X11100
11100XXX0
111010XX0
1110110X0
111011100
1179 ( defined( $_ ) && $self->_is_a( $_ => 'HTML::Object::Space' ) && defined( $prev ) && $self->_is_a( $prev => 'HTML::Object::Space' ) ) )
1180 {
1181 0 $prev->value->append( $_->value );
1182 0 return(1);
1183 }
1184 0 $prev = $_;
1185 0 $new->push( $_ );
1186 0 });
1187 0 $self->children( $new );
1188 0 return( $self );
1189 }
1190  
1191 1486 ▶sub offset { return( shift->reset(@_)->_set_get_number_as_object( 'offset', @_ ) ); }
Subroutine offset: called CC=1 SCAR=0.0
Pod documented
1192  
1193 2056 ▶sub original { return( shift->_set_get_scalar_as_object( 'original', @_ ) ); }
Subroutine original: called CC=1 SCAR=0.0
Pod documented
1194  
1195 1552 ▶sub parent { return( shift->_set_get_object_without_init({
Subroutine parent: called CC=1 SCAR=0.0
Pod documented
1196 1552 field => 'parent',
1197 weaken => 1,
1198 }, 'HTML::Object::Element', @_ ) ); }
1199  
1200 # Note: Different from the one in HTML::Element
1201 sub pos
1202 243 ▶{
Subroutine pos: called CC=2 SCAR=6.9
Pod documented
1203 243 my $self = shift( @_ );
1204 243 my $parent = $self->parent;
1205 243 ▶ return( $self->new_null ) if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 11 232 243
1206 232 my $kids = $parent->children;
1207 #my $id = $self->eid;
1208 #my( $pos ) = grep{ $kids->[$_]->eid eq $id } 0..$#$kids;
1209 #return( $pos );
1210 232 return( $kids->pos( $self ) );
1211 }
1212  
1213 0 ▶sub pindex { return( shift->pos( @_ ) ); }
Subroutine pindex: not called CC=1 SCAR=6.9
Pod documented
1214  
1215 # TODO: previous()
1216  
1217 # Note: HTML::Element compatibility
1218 sub postinsert
1219 0 ▶{
Subroutine postinsert: not called CC=4 SCAR=30.0
Pod documented
1220 0 my $self = shift( @_ );
1221 0 my $parent = $self->parent;
1222 0 ▶ return( $self->error( "Element has no parent." ) ) if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
1223 0 my $pos = $parent->children->pos( $self );
1224 0 ▶ return( $self->error( "Element is not found among parent's children elements." ) ) if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
1225 0 ▶ my $new = $self->_get_elements_list( @_ ) || return( $self->pass_error );
Condition0%0/2
$self->_get_elements_list(@_) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_get_elements_list(@_) || (return $self->pass_error)
$self->_get_elements_list(@_)
Truth table0%0/2
A
A= $self->_get_elements_list(@_)
Aresult
11
00
1226 $new->foreach(sub
1227 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1228 0 ▶ $_->detach if( $_->parent );
Branch: 1 branch
BranchTrueFalseTotal
if $_->parent 0 0 0
1229 0 $_->parent( $parent );
1230 0 });
1231 0 $parent->children->splice( $pos + 1, 0, $new->list );
1232 0 $parent->reset(1);
1233 0 return( $self );
1234 }
1235  
1236 # Note: HTML::Element compatibility
1237 sub preinsert
1238 0 ▶{
Subroutine preinsert: not called CC=4 SCAR=30.0
Pod documented
1239 0 my $self = shift( @_ );
1240 0 my $parent = $self->parent;
1241 0 ▶ return( $self->error( "Element has no parent." ) ) if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
1242 0 my $pos = $parent->children->pos( $self );
1243 0 ▶ return( $self->error( "Element is not found among parent's children elements." ) ) if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
1244 0 ▶ my $new = $self->_get_elements_list( @_ ) || return( $self->pass_error );
Condition0%0/2
$self->_get_elements_list(@_) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_get_elements_list(@_) || (return $self->pass_error)
$self->_get_elements_list(@_)
Truth table0%0/2
A
A= $self->_get_elements_list(@_)
Aresult
11
00
1245 $new->foreach(sub
1246 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1247 0 ▶ $_->detach if( $_->parent );
Branch: 1 branch
BranchTrueFalseTotal
if $_->parent 0 0 0
1248 0 $_->parent( $parent );
1249 0 });
1250 0 $parent->children->splice( $pos, 0, $new->list );
1251 0 $parent->reset(1);
1252 0 return( $self );
1253 }
1254  
1255 # Note: HTML::Element compatibility
1256 sub push_content
1257 0 ▶{
Subroutine push_content: not called CC=3 SCAR=24.8
Pod documented
1258 0 my $self = shift( @_ );
1259 0 ▶ return( $self ) unless( @_ );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
1260 0 my $children = $self->children;
1261 0 ▶ my $new = $self->_get_elements_list( @_ ) || return( $self->pass_error );
Condition0%0/2
$self->_get_elements_list(@_) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_get_elements_list(@_) || (return $self->pass_error)
$self->_get_elements_list(@_)
Truth table0%0/2
A
A= $self->_get_elements_list(@_)
Aresult
11
00
1262 $new->foreach(sub
1263 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1264 0 ▶ $_->detach if( $_->parent );
Branch: 1 branch
BranchTrueFalseTotal
if $_->parent 0 0 0
1265 0 $_->parent( $self );
1266 0 $children->push( $_ );
1267 0 });
1268 0 $self->reset(1);
1269 0 return( $self );
1270 }
1271  
1272 # Note: HTML::Element compatibility
1273 sub replace_with
1274 0 ▶{
Subroutine replace_with: not called CC=4 SCAR=30.0
Pod documented
1275 0 my $self = shift( @_ );
1276 0 my $parent = $self->parent;
1277 0 ▶ return( $self->error( "Element has no parent." ) ) if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
1278 0 my $pos = $parent->children->pos( $self );
1279 0 ▶ return( $self->error( "Element is not found among parent's children elements." ) ) if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
1280 0 ▶ my $new = $self->_get_elements_list( @_ ) || return( $self->pass_error );
Condition0%0/2
$self->_get_elements_list(@_) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_get_elements_list(@_) || (return $self->pass_error)
$self->_get_elements_list(@_)
Truth table0%0/2
A
A= $self->_get_elements_list(@_)
Aresult
11
00
1281 $new->foreach(sub
1282 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1283 0 ▶ $_->detach if( $_->parent );
Branch: 1 branch
BranchTrueFalseTotal
if $_->parent 0 0 0
1284 0 $_->parent( $parent );
1285 0 });
1286 0 $parent->children->splice( $pos, 1, $new->list );
1287 0 $parent->reset(1);
1288 0 return( $self );
1289 }
1290  
1291 sub replace_with_content
1292 0 ▶{
Subroutine replace_with_content: not called CC=3 SCAR=24.8
Pod documented
1293 0 my $self = shift( @_ );
1294 0 my $parent = $self->parent;
1295 0 my $children = $self->children;
1296 0 ▶ return( $self->error( "This element has no parent." ) ) if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
1297 0 my $pos = $parent->children->pos( $self );
1298 0 ▶ return( $self->error( "Unable to find the current element among its parent's children." ) ) if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
1299 $children->foreach(sub
1300 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1301 0 $_->parent( $parent );
1302 0 });
1303 0 $parent->splice( $pos, 1, $children->list );
1304 0 $self->parent( undef() );
1305 0 $parent->reset(1);
1306 0 return( $self );
1307 }
1308  
1309 sub reset
1310 24329 ▶{
Subroutine reset: called CC=4 SCAR=13.9
Pod documented
1311 24329 my $self = shift( @_ );
1312 24329 ▶ if( !CORE::length( $self->{_reset} ) && scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not length $self->{"_reset"} and scalar @_) 1886 22443 24329
Condition100%2/2
not length $self->{"_reset"} and scalar @_
!ll
200204309
MC/DC100%1/1
not length $self->{"_reset"} and scalar @_
not length $self->{"_reset"}
Truth table100%2/2
not(A)
A= not length $self->{"_reset"}
Aresult
00
11
1313 {
1314 1886 $self->{_reset} = scalar( @_ );
1315 1886 ▶ if( my $parent = $self->parent )
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent = $self->parent) 334 1552 1886
1316 {
1317 334 $parent->reset(1);
1318 }
1319 }
1320 24329 return( $self );
1321 }
1322  
1323 # Note: HTML::Element compatibility
1324 sub right
1325 107 ▶{
Subroutine right: called CC=6 SCAR=18.8
Pod documented
1326 107 my $self = shift( @_ );
1327 107 my $parent = $self->parent;
1328 107 ▶ return( $self->new_null ) if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 2 105 107
1329 105 my $kids = $parent->children;
1330 105 my $pos = $self->pos;
1331 105 ▶ my $offset = @_ ? int( shift( @_ ) ) : $kids->size;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 105 105
1332 105 ▶ return( $self->new_array ) if( !defined( $pos ) || $offset < $pos );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $pos or $offset < $pos 0 105 105
Condition33%1/3
not defined $pos or $offset < $pos
l!l&&r!l&&!r
00105
MC/DC0%0/2
not defined $pos or $offset < $pos
not defined $pos $offset < $pos
Truth table33%1/3
not(A) or B
A= not defined $posB= $offset < $pos
ABresult
1X1
011
000
1333 105 ▶ return( $self->new_array ) if( $kids->length == 1 );
Branch: 1 branch
BranchTrueFalseTotal
if $kids->length == 1 0 105 105
1334 # my $results = $kids->offset( $pos + 1, ( $offset - $pos ) );
1335 105 return( $kids->offset( $pos + 1, ( $offset - $pos ) ) );
1336 }
1337  
1338 # Note: HTML::Element compatibility
1339 sub root
1340 65 ▶{
Subroutine root: called CC=2 SCAR=6.9
Pod documented
1341 65 my $self = shift( @_ );
1342 65 my $root = $self;
1343 65 my $parent;
1344 65 ▶ while( $parent = $root->parent )
Branch: 1 branch
BranchTrueFalseTotal
if ($parent = $root->parent) 133 65 198
1345 {
1346 133 $root = $parent;
1347 }
1348 # Typically a HTML::Object::Document
1349 65 return( $root );
1350 }
1351  
1352 sub same_as
1353 0 ▶{
Subroutine same_as: not called CC=6 SCAR=37.4
Pod documented
1354 0 my $self = shift( @_ );
1355 0 ▶ my $elem = shift( @_ ) || return( $self->error( "No element object was provided to compare against." ) );
Condition0%0/2
shift @_ || (return $self->error('No element object was provided to compare against.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No element object was provided to compare against.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1356 0 ▶ return( $self->error( "Element provided (", overload::StrVal( $elem ), ") is not an object." ) ) if( !$self->_is_object( $elem ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($elem) 0 0 0
1357 0 ▶ return( $self->error( "Element provided (", overload::StrVal( $elem ), ") is not an HTML::Object::Element object." ) ) if( !$elem->isa( 'HTML::Object::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->isa("HTML::Object::Element") 0 0 0
1358 0 my $my_attr = $self->attributes->keys->sort;
1359 0 my $her_attr = $elem->attributes->keys->sort;
1360 0 ▶ return(0) unless( $my_attr eq $her_attr );
Branch: 1 branch
BranchTrueFalseTotal
unless $my_attr eq $her_attr 0 0 0
1361 $my_attr->foreach(sub
1362 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1363 0 ▶ return(0) if( $self->attributes->get( $_ ) ne $elem->attributes->get( $_ ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->attributes->get($_) ne $elem->attributes->get($_) 0 0 0
1364 0 });
1365 0 ▶ return(0) if( $self->children->length != $elem->children->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->children->length != $elem->children->length 0 0 0
1366 0 my $her_kids = $elem->children;
1367 $self->children->for(sub
1368 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1369 0 my( $i, $e ) = @_;
1370 0 ▶ return(0) if( !$e->same_as( $her_kids->[$i] ) );
Branch: 1 branch
BranchTrueFalseTotal
if not $e->same_as($her_kids->[$i]) 0 0 0
1371 0 });
1372 0 return(1);
1373 }
1374  
1375 sub set_checksum
1376 912 ▶{
Subroutine set_checksum: called CC=1 SCAR=0.0
Pod documented
1377 912 my $self = shift( @_ );
1378 912 my $tag = $self->_tag;
1379 912 my $a = $self->new_array( [$tag] );
1380 $self->attributes_sequence->foreach(sub
1381 644 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
1382 644 my $attr = shift( @_ );
1383 644 $a->push( $self->attributes->get( $attr ) );
1384 912 });
1385 912 return( $self->_get_md5_hash( $a->join( ';' )->scalar ) );
1386 }
1387  
1388 # Note: HTML::Element compatibility
1389 sub splice_content
1390 0 ▶{
Subroutine splice_content: not called CC=5 SCAR=34.0
Pod documented
1391 0 my $self = shift( @_ );
1392 0 my $offset = shift( @_ );
1393 0 my $length = shift( @_ );
1394 0 ▶ return( $self ) unless( @_ );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
1395 0 ▶ return( $self->error( "Offset value provided '$offset' is not an integer." ) ) if( !$self->_is_integer( $offset ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_integer($offset) 0 0 0
1396 0 ▶ return( $self->error( "Length value provided '$length' is not an integer." ) ) if( !$self->_is_integer( $length ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_integer($length) 0 0 0
1397 0 my $children = $self->children;
1398 0 ▶ my $new = $self->_get_elements_list( @_ ) || return( $self->pass_error );
Condition0%0/2
$self->_get_elements_list(@_) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_get_elements_list(@_) || (return $self->pass_error)
$self->_get_elements_list(@_)
Truth table0%0/2
A
A= $self->_get_elements_list(@_)
Aresult
11
00
1399 $new->foreach(sub
1400 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1401 0 ▶ $_->detach if( $_->parent );
Branch: 1 branch
BranchTrueFalseTotal
if $_->parent 0 0 0
1402 0 $_->parent( $self );
1403 0 });
1404 0 $children->splice( $offset, $length, $new->list );
1405 0 $self->reset(1);
1406 0 return( $self );
1407 }
1408  
1409 4071 ▶sub tag { return( shift->reset(@_)->_set_get_scalar_as_object( 'tag', @_ ) ); }
Subroutine tag: called CC=1 SCAR=0.0
Pod documented
1410  
1411 # Note: HTML::Element compatibility
1412 sub traverse
1413 0 ▶{
Subroutine traverse: not called CC=4 SCAR=30.0
Pod documented
1414 0 my $self = shift( @_ );
1415 0 ▶ my $code = shift( @_ ) || return( $self->error( "No code provided to traverse the html tree." ) );
Condition0%0/2
shift @_ || (return $self->error('No code provided to traverse the html tree.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No code provided to traverse the html tree.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1416 0 ▶ return( $self->error( "The argument provided (", overload::StrVal( $code ), ") is not an anonymous subroutine." ) ) if( ref( $code ) ne 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $code ne "CODE" 0 0 0
1417 0 my $opts = $self->_get_args_as_hash( @_ );
1418 0 ▶ $opts->{bottom_up} //= 0;
Condition0%0/2
$opts->{"bottom_up"} //= 0
l!l
00
MC/DC0%0/1
$opts->{"bottom_up"} //= 0
$opts->{"bottom_up"}
Truth table0%0/2
A
A= $opts->{"bottom_up"}
Aresult
11
00
1419 0 my $seen = {};
1420 0 my $crawl;
1421 $crawl = sub
1422 0 ▶ {
Subroutine __ANON__: not called CC=4 SCAR=30.0
1423 0 my $e = shift( @_ );
1424 0 my $addr = Scalar::Util::refaddr( $e );
1425 # Duplicate
1426 0 ▶ return if( ++$seen->{ $addr } > 1 );
Branch: 1 branch
BranchTrueFalseTotal
if ++$seen->{$addr} > 1 0 0 0
1427 0 local $_ = $e;
1428 0 ▶ $code->( $e ) unless( $opts->{bottom_up} );
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"bottom_up"} 0 0 0
1429 $e->children->foreach(sub
1430 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1431 0 $crawl->( $_[0] );
1432 0 });
1433 0 ▶ $code->( $e ) if( $opts->{bottom_up} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"bottom_up"} 0 0 0
1434 0 };
1435 0 $crawl->( $self );
1436 0 return( $self );
1437 }
1438  
1439 # Note: HTML::Element compatibility
1440 sub unshift_content
1441 0 ▶{
Subroutine unshift_content: not called CC=3 SCAR=24.8
Pod documented
1442 0 my $self = shift( @_ );
1443 0 ▶ return( $self ) unless( @_ );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
1444 0 my $children = $self->children;
1445 0 ▶ my $new = $self->_get_elements_list( @_ ) || return( $self->pass_error );
Condition0%0/2
$self->_get_elements_list(@_) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_get_elements_list(@_) || (return $self->pass_error)
$self->_get_elements_list(@_)
Truth table0%0/2
A
A= $self->_get_elements_list(@_)
Aresult
11
00
1446 $new->foreach(sub
1447 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1448 0 $_->parent( $self );
1449 0 });
1450 0 $children->splice( 0, 0, $new->list );
1451 0 $self->reset(1);
1452 0 return( $self );
1453 }
1454  
1455 # called on a parent, with a child as second argument and its rank as third
1456 # returns the child if it is already an element, or
1457 # a new HTML::Object::Text element if it is a plain string
1458 sub _child_as_object
1459 0 ▶{
Subroutine _child_as_object: not called CC=5 SCAR=34.0
1460 0 my( $self, $elt_or_text, $rank ) = @_;
1461 0 ▶ return unless( defined( $elt_or_text ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elt_or_text 0 0 0
1462 0 ▶ if( !ref( $elt_or_text ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $elt_or_text) 0 0 0
1463 {
1464 0 require HTML::Object::Text;
1465 # $elt_or_text is a string, turn it into a TextNode object
1466 0 $elt_or_text = HTML::Object::Text->new(
1467 parent => $self,
1468 value => $elt_or_text,
1469 );
1470 }
1471 0 ▶ warn( "rank is a ", ref( $rank ), " elt_or_text is a ", ref( $elt_or_text ) ) if( ref( $rank ) && !$self->_is_a( $rank, 'Module::Generic::Number' ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $rank and not $self->_is_a($rank, "Module::Generic::Number") 0 0 0
Condition0%0/3
ref $rank and not $self->_is_a($rank, "Module::Generic::Number")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $rank and not $self->_is_a($rank, "Module::Generic::Number")
ref $rank not $self->_is_a($rank, "Module::Generic::Number")
Truth table0%0/3
A and not(B)
A= ref $rankB= not $self->_is_a($rank, "Module::Generic::Number")
ABresult
0X0
100
111
1472 # used for sorting
1473 0 $elt_or_text->rank( $rank );
1474 0 return( $elt_or_text );
1475 }
1476  
1477 sub _generate_uuid
1478 1895 ▶{
Subroutine _generate_uuid: called CC=1 SCAR=0.0
1479 1895 return( lc( Data::UUID->new->create_str ) );
1480 }
1481  
1482 sub _get_elements_list
1483 0 ▶{
Subroutine _get_elements_list: not called CC=15 SCAR=54.8
1484 0 my $self = shift( @_ );
1485 0 my $new = $self->new_array;
1486 0 my $seen = {};
1487 0 my $prev;
1488 0 my $self_addr = Scalar::Util::refaddr( $self );
1489 0 my $parent_addr;
1490 0 my $parent = $self->parent;
1491 0 ▶ $parent_addr = Scalar::Util::refaddr( $parent ) if( defined( $parent ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent 0 0 0
1492 0 for( @_ )
1493 {
1494 0 ▶ return( $self->error( "Replacement element is not an HTML::Object::Element" ) ) if( !$self->_is_a( $_ => 'HTML::Object::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($_, "HTML::Object::Element") 0 0 0
1495 0 my $addr = Scalar::Util::refaddr( $_ );
1496 0 ▶ if( ++$seen->{ $addr } > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (++$seen->{$addr} > 1) 0 0 0
1497 {
1498 0 ▶ warn( "Warnings only: found duplicate element with tag '" . $_->tag . "' provided in replace_with()\n" ) if( $self->_is_warnings_enabled( 'HTML::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTML::Object") 0 0 0
1499 0 next;
1500 }
1501 0 ▶ return( $self->error( "Replacement list contains a copy of target!" ) ) if( $self_addr eq $addr );
Branch: 1 branch
BranchTrueFalseTotal
if $self_addr eq $addr 0 0 0
1502 0 ▶ return( $self->error( "Cannot replace an item with its parent!" ) ) if( defined( $parent_addr ) && $addr eq $parent_addr );
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent_addr and $addr eq $parent_addr 0 0 0
Condition0%0/3
defined $parent_addr and $addr eq $parent_addr
!ll&&!rl&&r
000
MC/DC0%0/2
defined $parent_addr and $addr eq $parent_addr
defined $parent_addr $addr eq $parent_addr
Truth table0%0/3
A and B
A= defined $parent_addrB= $addr eq $parent_addr
ABresult
0X0
100
111
1503 0 ▶ if( ( $_->isa( 'HTML::Object::Text' ) && defined( $prev ) && $prev->isa( 'HTML::Object::Text' ) ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($_->isa("HTML::Object::Text") and defined $prev and $prev->isa("HTML::Object::Text") or $_->isa("HTML::Object::Space") and defined $prev and $prev->isa("HTML::Object::Space")) 0 0 0
Condition0%0/15
$_->isa("HTML::Object::Text") and defined $prev and $prev->isa("HTML::Object::Text") or $_->isa("HTML::Object::Space") and defined $prev and $prev->isa("HTML::Object::Space")
l!l&&r!l&&!r
000
$_->isa("HTML::Object::Text") and defined $prev and $prev->isa("HTML::Object::Text")
!ll&&!rl&&r
000
$_->isa("HTML::Object::Text") and defined $prev
!ll&&!rl&&r
000
$_->isa("HTML::Object::Space") and defined $prev and $prev->isa("HTML::Object::Space")
!ll&&!rl&&r
000
$_->isa("HTML::Object::Space") and defined $prev
!ll&&!rl&&r
000
MC/DC0%0/6
$_->isa("HTML::Object::Text") and defined $prev and $prev->isa("HTML::Object::Text") or $_->isa("HTML::Object::Space") and defined $prev and $prev->isa("HTML::Object::Space")
$_->isa("HTML::Object::Text") defined $prev $prev->isa("HTML::Object::Text") $_->isa("HTML::Object::Space") defined $prev $prev->isa("HTML::Object::Space")
Truth table0%0/13
A and B and C or D and E and F
A= $_->isa("HTML::Object::Text")B= defined $prevC= $prev->isa("HTML::Object::Text")D= $_->isa("HTML::Object::Space")E= defined $prevF= $prev->isa("HTML::Object::Space")
ABCDEFresult
111XXX1
0XX1111
10X1111
1101111
0XX0XX0
0XX10X0
0XX1100
10X0XX0
10X10X0
10X1100
1100XX0
11010X0
1101100
1504 ( $_->isa( 'HTML::Object::Space' ) && defined( $prev ) && $prev->isa( 'HTML::Object::Space' ) ) )
1505 {
1506 0 $prev->value->append( $_->value );
1507 0 next;
1508 }
1509 0 $new->push( $_ );
1510 0 $prev = $_;
1511 }
1512 0 return( $new );
1513 }
1514  
1515 # Used by after, append, before
1516 sub _get_from_list_of_elements_or_html
1517 13 ▶{
Subroutine _get_from_list_of_elements_or_html: called CC=16 SCAR=39.0
1518 13 my $self = shift( @_ );
1519 13 my $list = $self->new_array;
1520 13 my $prev;
1521 13 foreach my $this ( @_ )
1522 {
1523 16 ▶ if( $self->_is_a( $this => 'HTML::Object::Element' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($this, 'HTML::Object::Element')) { } 11 5 16
1524 {
1525 11 ▶ if( $self->_is_a( $this => 'HTML::Object::DOM::DocumentFragment' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($this, 'HTML::Object::DOM::DocumentFragment')) { } 0 11 11
elsif ($self->_is_a($this, 'HTML::Object::Text')) { } 0 11 11
1526 {
1527 0 my $clone = $this->children->clone;
1528 0 $list->push( $clone->list );
1529 0 $this->children->reset;
1530 0 undef( $prev );
1531 }
1532 elsif( $self->_is_a( $this => 'HTML::Object::Text' ) )
1533 {
1534 0 ▶ if( defined( $prev ) && $self->_is_a( $prev => 'HTML::Object::Text' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prev and $self->_is_a($prev, 'HTML::Object::Text')) { } 0 0 0
Condition0%0/3
defined $prev and $self->_is_a($prev, "HTML::Object::Text")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $prev and $self->_is_a($prev, "HTML::Object::Text")
defined $prev $self->_is_a($prev, "HTML::Object::Text")
Truth table0%0/3
A and B
A= defined $prevB= $self->_is_a($prev, "HTML::Object::Text")
ABresult
0X0
100
111
1535 {
1536 0 $prev->value->append( $this->value );
1537 }
1538 else
1539 {
1540 0 my $clone = $this->clone;
1541 0 $list->push( $clone );
1542 0 $prev = $clone;
1543 }
1544 }
1545 else
1546 {
1547 11 my $clone = $this->clone;
1548 11 $list->push( $clone );
1549 # $list->push( $clone->close_tag ) if( $clone->close_tag );
1550 11 undef( $prev );
1551 }
1552 }
1553 else
1554 {
1555 5 ▶ if( ref( $this ) && ( !$self->_is_object( $this ) || ( $self->_is_object( $this ) && !overload::Method( $this, '""' ) ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this and !$self->_is_object($this) || $self->_is_object($this) && !overload::Method($this, "\"\"")) 0 5 5
Condition11%1/9
ref $this and !$self->_is_object($this) || $self->_is_object($this) && !overload::Method($this, "\"\"")
!ll&&!rl&&r
500
not $self->_is_object($this) or $self->_is_object($this) and not overload::Method($this, "\"\"")
l!l&&r!l&&!r
000
$self->_is_object($this) and not overload::Method($this, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/4
ref $this and !$self->_is_object($this) || $self->_is_object($this) && !overload::Method($this, "\"\"")
ref $this not $self->_is_object($this) $self->_is_object($this) not overload::Method($this, "\"\"")
Truth table20%1/5
A and not(B) or C and not(D)
A= ref $thisB= not $self->_is_object($this)C= $self->_is_object($this)D= not overload::Method($this, "\"\"")
ABCDresult
0XXX0
100X0
10100
11XX1
10111
1556 {
1557 0 return( $self->error( "I was expecting some HTML data, but got '", overload::StrVal( $this ), "'" ) );
1558 }
1559  
1560 # if( "$this" =~ /$LOOK_LIKE_HTML/ )
1561 # LOOK_LIKE_HTML check for html tag starting at the beginning of the string
1562 # LOOK_LIKE_IT_HAS_HTML checks for tag anywhere
1563 5 ▶ if( "$this" =~ /$LOOK_LIKE_IT_HAS_HTML/ )
Branch: 1 branch
BranchTrueFalseTotal
if ("$this" =~ /$HTML::Object::Element::LOOK_LIKE_IT_HAS_HTML/) { } 1 4 5
1564 {
1565 1 my $p = $self->new_parser( debug => 4 );
1566 1 ▶ my $res = $p->parse_data( "$this" ) ||
Condition50%1/2
$p->parse_data("$this") || (return $self->error('Error while parsing html data provided: ', $p->error))
l!l
10
MC/DC0%0/1
$p->parse_data("$this") || (return $self->error('Error while parsing html data provided: ', $p->error))
$p->parse_data("$this")
Truth table50%1/2
A
A= $p->parse_data("$this")
Aresult
11
00
1567 return( $self->error( "Error while parsing html data provided: ", $p->error ) );
1568 1 ▶ $list->push( $res->children->list ) if( !$res->children->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
unless $res->children->is_empty 1 0 1
1569 }
1570 # Maybe just some text provided, and in that case, the parser would return nothing unfortunately
1571 else
1572 {
1573 4 ▶ if( defined( $prev ) && $self->_is_a( $prev => 'HTML::Object::Text' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prev and $self->_is_a($prev, 'HTML::Object::Text')) { } 0 4 4
Condition33%1/3
defined $prev and $self->_is_a($prev, "HTML::Object::Text")
!ll&&!rl&&r
400
MC/DC0%0/2
defined $prev and $self->_is_a($prev, "HTML::Object::Text")
defined $prev $self->_is_a($prev, "HTML::Object::Text")
Truth table33%1/3
A and B
A= defined $prevB= $self->_is_a($prev, "HTML::Object::Text")
ABresult
0X0
100
111
1574 {
1575 0 $prev->value->append( "$this" );
1576 }
1577 else
1578 {
1579 4 my $e = $self->new_text({ value => "$this" });
1580 4 $list->push( $e );
1581 4 $prev = $e;
1582 }
1583 }
1584 }
1585 }
1586 13 return( $list );
1587 }
1588  
1589 sub _get_md5_hash
1590 1581 ▶{
Subroutine _get_md5_hash: called CC=4 SCAR=14.1
1591 1581 my $self = shift( @_ );
1592 1581 my $data = shift( @_ );
1593 1581 ▶ return( $self->error( "No data was provided to compute a md5 hash." ) ) if( !defined( $data ) || !length( "$data" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data and length "$data" 42 1539 1581
Condition66%2/3
defined $data and length "$data"
!ll&&!rl&&r
0421539
MC/DC50%1/2
defined $data and length "$data"
defined $data length "$data"
Truth table66%2/3
A and B
A= defined $dataB= length "$data"
ABresult
0X0
100
111
1594 # try-catch
1595 1539 local $@;
1596 my $rv = eval
1597 1539 {
1598 1539 return( Digest::MD5::md5_hex( Encode::encode( 'utf8', $data, Encode::FB_CROAK ) ) );
1599 };
1600 1539 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1539 1539
1601 {
1602 0 return( $self->error( "An error occurred while calculating the md5 hash for tag \"", $self->tag, "\": $@" ) );
1603 }
1604 1539 return( $rv );
1605 }
1606  
1607 # For other modules to use
1608 2 ▶sub _is_reset { return( CORE::length( shift->{_reset} ) ); }
Subroutine _is_reset: called CC=1 SCAR=0.0
1609  
1610 # For other modules to use
1611 265 ▶sub _remove_reset { return( CORE::delete( shift->{_reset} ) ); }
Subroutine _remove_reset: called CC=1 SCAR=0.0
1612  
1613 # Method shared with HTML::Object::XQuery
1614 19 ▶sub _set_get_id : lvalue { return( shift->_set_get_callback({
Subroutine _set_get_id: called CC=1 SCAR=1.0
1615 get => sub
1616 11 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
1617 11 my $self = shift( @_ );
1618 11 my $id = $self->new_scalar( $self->attributes->get( 'id' ) );
1619 11 return( $id );
1620 },
1621 set => sub
1622 8 ▶ {
Subroutine __ANON__: called CC=4 SCAR=19.6
1623 8 my $self = shift( @_ );
1624 8 my $id = shift( @_ );
1625 8 ▶ if( !defined( $id ) || !CORE::length( $id ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $id && length $id) { } 0 8 8
Condition33%1/3
defined $id && length $id
!ll&&!rl&&r
008
MC/DC0%0/2
defined $id && length $id
defined $id length $id
Truth table33%1/3
A && B
A= defined $idB= length $id
ABresult
0X0
100
111
1626 {
1627 0 ▶ if( $self->attributes->exists( 'id' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->attributes->exists("id")) 0 0 0
1628 {
1629 0 $self->attributes->delete( 'id' );
1630 0 $self->attributes_sequence->remove( 'id' );
1631 0 $self->reset(1);
1632 0 return(1);
1633 }
1634 0 return(0);
1635 }
1636 else
1637 {
1638 8 $self->attributes->set( id => $id );
1639 8 $self->reset(1);
1640 8 return(1);
1641 }
1642 }
1643 19 }, @_ ) ); }
1644  
1645 sub _same_as
1646 164 ▶{
Subroutine _same_as: called CC=5 SCAR=18.1
1647 164 my $self = shift( @_ );
1648 164 my $this = shift( @_ );
1649 164 ▶ return(0) if( !defined( $this ) || ( defined( $this ) && !$self->_is_a( $this, 'HTML::Object::Element' ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $this or defined $this and not $self->_is_a($this, "HTML::Object::Element") 0 164 164
Condition33%2/6
not defined $this or defined $this and not $self->_is_a($this, "HTML::Object::Element")
l!l&&r!l&&!r
00164
defined $this and not $self->_is_a($this, "HTML::Object::Element")
!ll&&!rl&&r
01640
MC/DC0%0/3
not defined $this or defined $this and not $self->_is_a($this, "HTML::Object::Element")
not defined $this defined $this not $self->_is_a($this, "HTML::Object::Element")
Truth table25%1/4
not(A) or B and not(C)
A= not defined $thisB= defined $thisC= not $self->_is_a($this, "HTML::Object::Element")
ABCresult
1XX1
0111
00X0
0100
1650 164 ▶ return( $self->eid CORE::eq $this->eid ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$self->eid eq $this->eid ? : 99 65 164
1651 }
1652  
1653 # Used to register callbacks for some properties like rel, sizes, controlslist that we trigger and that update the attribute's HTML::Object::TokenList
1654 sub _set_get_internal_attribute_callback
1655 64 ▶{
Subroutine _set_get_internal_attribute_callback: called CC=6 SCAR=19.9
1656 64 my $self = shift( @_ );
1657 64 ▶ $self->{_internal_attribute_callbacks} = {} if( ref( $self->{_internal_attribute_callbacks} ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"_internal_attribute_callbacks"} ne "HASH" 0 64 64
1658 64 my $ref = $self->{_internal_attribute_callbacks};
1659 # get mode
1660 64 ▶ if( scalar( @_ ) == 1 )
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 1) { } 0 64 64
elsif (scalar @_) { } 64 0 64
1661 {
1662 0 my $attr = shift( @_ );
1663 0 return( $ref->{ $attr } );
1664 }
1665 elsif( scalar( @_ ) )
1666 {
1667 64 ▶ return( $self->error( "Odd number of parameters for attribute callback assignment." ) ) if( ( @_ % 2 ) );
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 64 64
1668 64 ▶ for( my $i = 0; $i < scalar( @_ ); $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @_) 64 64 128
1669 {
1670 64 $ref->{ $_[ $i ] } = $_[ $i + 1 ];
1671 }
1672 64 return( $self );
1673 }
1674 0 return;
1675 }
1676  
1677 # A private method for internal use when the tag method has been overriden for example as it is the case in HTML::Object::XQuery
1678 912 ▶sub _tag { return( shift->reset(@_)->_set_get_scalar_as_object( 'tag', @_ ) ); }
Subroutine _tag: called CC=1 SCAR=0.0
1679  
1680 37 1;
1681 # NOTE: POD
1682 __END__
« Object/XPath/Expr.pm ↑ Summary Object/DOM/CharacterData.pm »