lib/HTML/Object/XQuery.pm

filter: Statementstmt 34.5% 798 / 2313 Branchbran 22.8% 331 / 1448 Conditioncond 12.9% 105 / 810 MC/DCmcdc 4.5% 19 / 419 Subroutinesub 43.6% 121 / 277 Podpod 44.7% 38 / 85 totaltotal 26.3% 1412 / 5352 CC 1030 SCAR 68.1
CC
1030
Cov
27%
ajax
9120.0
load
3306.0
__ANON__
756.0
CRAP 907.7
« blib/lib/HTML/Object/XQuery.pm ↑ Summary lib/HTML/Object/DOM/List.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/XQuery.pm
3 ## Version v0.4.0
4 ## Copyright(c) 2024 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/05/01
7 ## Modified 2024/04/27
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::XQuery;
15 BEGIN
16 {
17 7 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 7 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 7 ▶ warnings::register_categories( 'HTML::Object' );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 7 ▶ use parent qw( HTML::Object::DOM );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 7 ▶ use vars qw( @EXPORT $DEBUG $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 7 our @EXPORT = qw( xq );
23 7 our $DEBUG = 0;
24 7 our $VERSION = 'v0.4.0';
25 };
26  
27 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 {
31 7 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 7 *xq = \&HTML::Object::DOM::Element::xq;
33 }
34  
35 # NOTE: DateTimeFormat class
36 # package
37 # DateTimeFormat;
38 # BEGIN
39 # {
40 # use strict;
41 # use warnings;
42 # use parent qw( HTML::Object::DateTime::Format );
43 # };
44 #
45 # use strict;
46 # use warnings;
47  
48 # NOTE: xQuery class
49 package xQuery;
50 BEGIN
51 {
52 7 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 7 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 7 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
55 };
56 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
58  
59 {
60 7 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
61 # NOTE: clearQueue
62 7 *clearQueue = \&HTML::Object::DOM::Element::clearQueue;
63 # NOTE: contains
64 7 *contains = \&HTML::Object::DOM::Element::contains;
65 }
66  
67 sub data
68 {
69 5 ▶ my $self = shift( @_ );
Subroutine data: called CC=5 SCAR=17.0
70 5 ▶ my $elem = shift( @_ ) || return( $self->error( "No element was provided to set/get data on it." ) );
Condition50%1/2
shift @_ || (return $self->error('No element was provided to set/get data on it.'))
l!l
50
MC/DC0%0/1
shift @_ || (return $self->error('No element was provided to set/get data on it.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
71 5 ▶ return( $self->error( "Element value provided is not an HTML::Object::DOM::Element" ) ) if( !$self->_is_a( $elem => 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($elem, "HTML::Object::DOM::Element") 0 5 5
72 5 my $rv = $elem->data( @_ );
73 5 ▶ return( $self->pass_error( $elem->error ) ) if( !defined( $rv ) && $elem->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $rv and $elem->error 0 5 5
Condition66%2/3
not defined $rv and $elem->error
!ll&&!rl&&r
410
MC/DC0%0/2
not defined $rv and $elem->error
not defined $rv $elem->error
Truth table66%2/3
not(A) and B
A= not defined $rvB= $elem->error
ABresult
0X0
100
111
74 5 return( $rv );
75 }
76  
77 {
78 7 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
79 # NOTE: dequeue
80 7 *dequeue = \&HTML::Object::DOM::Element::dequeue;
81 }
82  
83 sub each
84 {
85 1 ▶ my $self = shift( @_ );
Subroutine each: called CC=5 SCAR=20.3
86 1 my( $data, $cb ) = @_;
87 1 my $obj;
88 1 ▶ if( $self->_is_array( $data ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_array($data)) { } 1 0 1
elsif ($self->_is_hash($data)) { } 0 0 0
89 {
90 1 $obj = $self->new_array( $data );
91 }
92 elsif( $self->_is_hash( $data ) )
93 {
94 0 $obj = $self->new_hash( $data );
95 }
96 else
97 {
98 0 ▶ return( $self->error( "Unsupported data type (", overload::StrVal( $data // 'undef' ), ")" ) );
Condition0%0/2
$data // "undef"
l!l
00
MC/DC0%0/1
$data // "undef"
$data
Truth table0%0/2
A
A= $data
Aresult
11
00
99 }
100 1 ▶ return( $self->error( "Callback value provided is not a code reference." ) ) if( !$self->_is_code( $cb ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_code($cb) 0 1 1
101 1 return( $obj->each($cb) );
102 }
103  
104 sub extend
105 {
106 2 ▶ my $self = shift( @_ );
Subroutine extend: called CC=8 SCAR=21.0
107 2 my $deep = 0;
108 2 ▶ if( scalar( @_ ) && !$self->_is_hash( $_[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ and not $self->_is_hash($_[0])) 1 1 2
Condition66%2/3
scalar @_ and not $self->_is_hash($_[0])
!ll&&!rl&&r
011
MC/DC50%1/2
scalar @_ and not $self->_is_hash($_[0])
scalar @_ not $self->_is_hash($_[0])
Truth table66%2/3
A and not(B)
A= scalar @_B= not $self->_is_hash($_[0])
ABresult
0X0
100
111
109 {
110 1 my $bool = shift( @_ );
111 1 ▶ $deep = $bool ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$bool ? : 1 0 1
112 }
113 # Clean up the arguments
114 2 my @args = ();
115 2 ▶ for( my $i = 0; $i < scalar( @_ ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @_) 4 2 6
116 {
117 4 ▶ if( $self->_is_hash( $_[$i] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_hash($_[$i])) 4 0 4
118 {
119 4 push( @args, $_[$i] );
120 }
121 }
122 2 ▶ return( {} ) if( !scalar( @args ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @args 0 2 2
123 2 ▶ return( { map( %$_, @args ) } ) unless( $deep );
Branch: 1 branch
BranchTrueFalseTotal
unless $deep 1 1 2
124 # Credits: Hash::Merge::Simple
125 1 my $merge;
126 $merge = sub
127 {
128 2 ▶ my( $left, @right ) = @_;
Subroutine __ANON__: called CC=6 SCAR=18.1
129 2 ▶ return( $left ) unless( @right );
Branch: 1 branch
BranchTrueFalseTotal
unless @right 0 2 2
130 2 ▶ return( $merge->( $left, $merge->( @right ) ) ) if( @right > 1 );
Branch: 1 branch
BranchTrueFalseTotal
if @right > 1 0 2 2
131 2 my( $right ) = @right;
132 2 my $merged = { %$left };
133 2 foreach my $key ( keys( %$right ) )
134 {
135 3 my( $hr, $hl ) = map{ ref( $_->{ $key } ) eq 'HASH' } $right, $left;
136 # Both hash have the same key pointing to an hash
137 3 ▶ if( $hr and $hl )
Branch: 1 branch
BranchTrueFalseTotal
if ($hr and $hl) { } 1 2 3
Condition66%2/3
$hr and $hl
!ll&&!rl&&r
201
MC/DC50%1/2
$hr and $hl
$hr $hl
Truth table66%2/3
A and B
A= $hrB= $hl
ABresult
0X0
100
111
138 {
139 1 $merged->{ $key } = $merge->( $left->{ $key }, $right->{ $key } );
140 }
141 else
142 {
143 2 $merged->{ $key } = $right->{ $key };
144 }
145 }
146 2 return( $merged );
147 1 };
148 1 return( $merge->( @args ) );
149 }
150  
151 sub grep
152 {
153 4 ▶ my $self = shift( @_ );
Subroutine grep: called CC=4 SCAR=14.0
154 4 my( $ref, $cb, $invert ) = @_;
155 4 ▶ return( $self->error( "Value provided is not an array reference." ) ) if( !$self->_is_array( $ref ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($ref) 0 4 4
156 4 ▶ return( $self->error( "Callback value provided is not a code reference." ) ) if( !$self->_is_code( $cb ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_code($cb) 0 4 4
157 4 ▶ $invert //= 0;
Condition100%2/2
$invert //= 0
l!l
13
MC/DC100%1/1
$invert //= 0
$invert
Truth table100%2/2
A
A= $invert
Aresult
11
00
158 4 $ref = $self->new_array( $ref );
159 4 return( $ref->grep( $cb, $invert ) );
160 }
161  
162 sub inArray
163 {
164 5 ▶ my $self = shift( @_ );
Subroutine inArray: called CC=11 SCAR=25.4
165 5 my( $val, $array, $fromIndex ) = @_;
166 5 ▶ return( $self->error( "Array value provided is not an array." ) ) if( !$self->_is_array( $array ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($array) 0 5 5
167 5 ▶ return( $self->error( "fromIndex value provided is not an integer." ) ) if( defined( $fromIndex ) && !$self->_is_integer( $fromIndex ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $fromIndex and not $self->_is_integer($fromIndex) 0 5 5
Condition66%2/3
defined $fromIndex and not $self->_is_integer($fromIndex)
!ll&&!rl&&r
410
MC/DC0%0/2
defined $fromIndex and not $self->_is_integer($fromIndex)
defined $fromIndex not $self->_is_integer($fromIndex)
Truth table66%2/3
A and not(B)
A= defined $fromIndexB= not $self->_is_integer($fromIndex)
ABresult
0X0
100
111
168 5 ▶ $fromIndex //= 0;
Condition100%2/2
$fromIndex //= 0
l!l
14
MC/DC100%1/1
$fromIndex //= 0
$fromIndex
Truth table100%2/2
A
A= $fromIndex
Aresult
11
00
169 5 ▶ my $isRe = ( ref( $val ) eq 'Regexp' ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
ref $val eq 'Regexp' ? : 0 5 5
170 5 ▶ for( my $i = 0; $i < scalar( @$array ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$array) 16 2 18
171 {
172 16 ▶ next unless( $i >= $fromIndex );
Branch: 1 branch
BranchTrueFalseTotal
unless $i >= $fromIndex 2 14 16
173 14 ▶ if( $isRe )
Branch: 1 branch
BranchTrueFalseTotal
if ($isRe) { } 0 14 14
174 {
175 0 ▶ return( $i ) if( $array->[$i] =~ /$val/ );
Branch: 1 branch
BranchTrueFalseTotal
if $array->[$i] =~ /$val/ 0 0 0
176 }
177 else
178 {
179 14 ▶ return( $i ) if( $array->[$i] eq $val );
Branch: 1 branch
BranchTrueFalseTotal
if $array->[$i] eq $val 3 11 14
180 }
181 }
182 2 return(-1);
183 }
184  
185 1 ▶sub isArray { return( shift->_is_array( @_ ) ); }
Subroutine isArray: called CC=1 SCAR=0.0
186  
187 sub isEmptyObject
188 {
189 2 ▶ my $self = shift( @_ );
Subroutine isEmptyObject: called CC=3 SCAR=11.0
190 2 my $this = shift( @_ );
191 2 ▶ return(0) if( !$self->_is_hash( $this, 'strict' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_hash($this, "strict") 0 2 2
192 2 ▶ return( scalar( keys( %$this ) ) ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %$this ? : 1 1 2
193 }
194  
195 sub isFunction
196 {
197 5 ▶ my $self = shift( @_ );
Subroutine isFunction: called CC=5 SCAR=16.1
198 5 my $this = shift( @_ );
199 5 ▶ return(0) if( $self->_is_empty( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_empty($this) 1 4 5
200 4 ▶ return(1) if( $self->_is_code( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_code($this) 1 3 4
201 3 my $pkg = caller;
202 3 ▶ if( $self->_has_symbol( $pkg => "\&${this}" ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_symbol($pkg, "&$this") and defined &{"${pkg}::$this";}) 1 2 3
Condition66%2/3
$self->_has_symbol($pkg, "&$this") and defined &{"${pkg}::$this";}
!ll&&!rl&&r
201
MC/DC50%1/2
$self->_has_symbol($pkg, "&$this") and defined &{"${pkg}::$this";}
$self->_has_symbol($pkg, "&$this") defined &{"${pkg}::$this";}
Truth table66%2/3
A and B
A= $self->_has_symbol($pkg, "&$this")B= defined &{"${pkg}::$this";}
ABresult
0X0
100
111
203 1 defined( &{"${pkg}\::${this}"} ) )
204 {
205 1 return(1);
206 }
207 2 return(0);
208 }
209  
210 15 ▶sub isNumeric { return( shift->_look_like_number( @_ ) ); }
Subroutine isNumeric: called CC=1 SCAR=0.0
211  
212 2 ▶sub isPlainObject { return( shift->_is_hash( shift( @_ ), 'strict' ) ); }
Subroutine isPlainObject: called CC=1 SCAR=0.0
213  
214 2 ▶sub isWindow { return( shift->_is_a( shift( @_ ) => 'HTML::Object::DOM::Window' ) ); }
Subroutine isWindow: called CC=1 SCAR=0.0
215  
216 sub makeArray
217 {
218 1 ▶ my $self = shift( @_ );
Subroutine makeArray: called CC=3 SCAR=11.1
219 1 my $ref = shift( @_ );
220 1 ▶ if( $self->_is_a( $ref => 'HTML::Object::Collection' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($ref, "HTML::Object::Collection")) 1 0 1
221 {
222 1 $ref = $ref->children;
223 }
224 1 ▶ return( $self->error( "Value provided is not an array reference or an array object." ) ) if( !$self->_is_array( $ref ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($ref) 0 1 1
225 1 my $new = [];
226 1 @$new = @$ref;
227 1 return( $new );
228 }
229  
230 sub map
231 {
232 8 ▶ my $self = shift( @_ );
Subroutine map: called CC=15 SCAR=28.9
233 8 ▶ my $ref = shift( @_ ) || return( $self->error( "No data was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No data was provided.'))
l!l
80
MC/DC0%0/1
shift @_ || (return $self->error('No data was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
234 8 ▶ my $code = shift( @_ ) || return( $self->error( "No code reference was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No code reference was provided.'))
l!l
80
MC/DC0%0/1
shift @_ || (return $self->error('No code reference was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
235 8 ▶ return( $self->error( "I was expecting a code reference, but instead I was provided with this: \"", overload::StrVal( $code ), "\"." ) ) if( ref( $code ) ne 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $code ne "CODE" 0 8 8
236 8 my $type;
237 8 ▶ if( $self->_is_array( $ref ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_array($ref)) { } 6 2 8
elsif ($self->_is_hash($ref, 'strict')) { } 2 0 2
238 {
239 6 $type = 'array';
240 }
241 elsif( $self->_is_hash( $ref => 'strict' ) )
242 {
243 2 $type = 'hash';
244 }
245 8 my $new = $self->new_array;
246 8 local $@;
247 8 ▶ if( defined( $type ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type) { } 8 0 8
248 {
249 my $each = sub
250 {
251 37 ▶ if( $type eq 'hash' )
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'hash') { } 8 29 37
252 {
253 8 return( CORE::each( %$ref ) );
254 }
255 else
256 {
257 29 return( CORE::each( @$ref ) );
258 }
259 8 };
260  
261 # We use a callback, because perl does not accept: each( $type eq 'array' ? @$ref : %$ref )
262 8 ▶ while( my( $key, $value ) = $each->() )
Branch: 1 branch
BranchTrueFalseTotal
if (() = &$each()) 29 8 37
263 {
264 # try-catch
265 my @rv = eval
266 29 {
267 29 $code->( $value, $key );
268 };
269 29 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 29 29
270 {
271 0 ▶ warn( "An error occured while executing callback for key ${key}: $@" ) if( $self->_is_warnings_enabled( 'HTML::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTML::Object") 0 0 0
272 0 next;
273 }
274 # User returned an empty array or undef
275 29 ▶ if( !scalar( @rv ) || ( scalar( @rv ) == 1 && !defined( $rv[0] ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not scalar @rv or scalar @rv == 1 and not defined $rv[0]) 1 28 29
Condition66%4/6
not scalar @rv or scalar @rv == 1 and not defined $rv[0]
l!l&&r!l&&!r
0128
scalar @rv == 1 and not defined $rv[0]
!ll&&!rl&&r
0281
MC/DC33%1/3
not scalar @rv or scalar @rv == 1 and not defined $rv[0]
not scalar @rv scalar @rv == 1 not defined $rv[0]
Truth table50%2/4
not(A) or B and not(C)
A= not scalar @rvB= scalar @rv == 1C= not defined $rv[0]
ABCresult
1XX1
0111
00X0
0100
276 {
277 1 next;
278 }
279 28 ▶ if( scalar( @rv ) == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @rv == 1) { } 28 0 28
280 {
281 # User returned an array reference, such as:
282 # my @rv = $.map( $array, sub{ return( [1, 2, 3] ) } );
283 28 ▶ if( $self->_is_array( $rv[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($rv[0])) { } 7 21 28
284 {
285 7 $new->push( @{$rv[0]} );
286 }
287 else
288 {
289 # warn( "Warning only: value returned from the \$.map callback for key ${key} did not return either undef or an array reference: ", join( ', ', map( overload::StrVal( $_ // 'undef' ), @rv ) ) ) if( $self->_is_warnings_enabled( 'HTML::Object' ) );
290 21 $new->push( $rv[0] );
291 }
292 }
293 # User returned an array of more than 1 item, such as:
294 # my @rv = $.map( $array, sub{ return( 1, 2, 3 ) } );
295 else
296 {
297 0 $new->push( @rv );
298 }
299 }
300 8 return( $new );
301 }
302 else
303 {
304 0 return( $self->error( "The data provided is neither an array reference, an array object or an hash reference." ) );
305 }
306 }
307  
308 sub merge
309 {
310 4 ▶ my $self = shift( @_ );
Subroutine merge: called CC=3 SCAR=11.2
311 4 my( $first, $second ) = @_;
312 4 ▶ return( $self->error( "First value provided is not an array reference." ) ) if( !$self->_is_array( $first ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($first) 0 4 4
313 4 ▶ return( $self->error( "Second value provided is not an array reference." ) ) if( !$self->_is_array( $second ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($second) 0 4 4
314 4 CORE::push( @$first, @$second );
315 4 return( $first );
316 }
317  
318 0 ▶sub noop { return }
Subroutine noop: not called CC=1 SCAR=6.9
319  
320 sub now
321 {
322 1 ▶ my $self = shift( @_ );
Subroutine now: called CC=3 SCAR=11.2
323 1 ▶ $self->_load_class( 'DateTime' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DateTime") or return $self->pass_error 0 1 1
324 1 ▶ $self->_load_class( 'DateTime::Format::Strptime' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DateTime::Format::Strptime") or return $self->pass_error 0 1 1
325 1 my $fmt = DateTime::Format::Strptime->new(
326 pattern => '%s',
327 );
328 1 my $dt = DateTime->now(
329 formatter => $fmt,
330 );
331 1 return( $dt );
332 }
333  
334 sub parseHTML
335 {
336 1 ▶ my( $self, $str ) = @_;
Subroutine parseHTML: called CC=3 SCAR=11.2
337 1 my $res = $self->new_array;
338 1 ▶ return( $res ) if( $self->_is_empty( $str ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_empty($str) 0 1 1
339 1 my $parser = HTML::Object::DOM->new( debug => $self->debug );
340 1 ▶ my $doc = $parser->parse_data( "$str" ) ||
Condition50%1/2
$parser->parse_data("$str") || (return $self->pass_error($parser->error))
l!l
10
MC/DC0%0/1
$parser->parse_data("$str") || (return $self->pass_error($parser->error))
$parser->parse_data("$str")
Truth table50%1/2
A
A= $parser->parse_data("$str")
Aresult
11
00
341 return( $self->pass_error( $parser->error ) );
342 1 $res->push( $doc->children->list );
343 1 return( $res );
344 }
345  
346 sub parseJSON
347 {
348 1 ▶ my( $self, $str ) = @_;
Subroutine parseJSON: called CC=3 SCAR=11.3
349 1 ▶ return( $self->error( "No JSON data was provided to parse" ) ) if( $self->_is_empty( $str ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_empty($str) 0 1 1
350 1 my $j = $self->new_json( allow_tags => 0 );
351 # try-catch
352 1 local $@;
353 my $rv = eval
354 1 {
355 1 return( $j->decode( "$str" ) );
356 };
357 1 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
358 {
359 0 return( $self->error( "An error occurred while parsing ", CORE::length( "$str" ), " bytes of JSON data: $@" ) );
360 }
361 1 return( $rv );
362 }
363  
364 sub parseXML
365 {
366 0 ▶ my( $self, $str ) = @_;
Subroutine parseXML: not called CC=4 SCAR=30.0
367 0 ▶ return( $self->error( "No XML data was provided to parse" ) ) if( $self->_is_empty( $str ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_empty($str) 0 0 0
368 0 ▶ if( !$self->_load_class( 'XML::LibXML' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_load_class("XML::LibXML")) 0 0 0
369 {
370 0 return( $self->pass_error );
371 }
372 # try-catch
373 0 local $@;
374 my $doc = eval
375 0 {
376 0 XML::LibXML->load_xml( string => $str );
377 };
378 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
379 {
380 0 return( $self->error( "Error while parsing XML data with XML::LibXML: $@" ) );
381 }
382 0 return( $doc );
383 }
384  
385 # NOTE: $.proxy() is deprecated
386 # <https://api.jquery.com/jQuery.proxy/>
387  
388 # NOTE: $.queue() is unsupported as it has no meaning under perl
389 # <https://api.jquery.com/jQuery.queue/>
390  
391 sub removeData
392 {
393 1 ▶ my $self = shift( @_ );
Subroutine removeData: called CC=5 SCAR=17.2
394 1 ▶ my $elem = shift( @_ ) || return( $self->error( "No element was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No element was provided.'))
l!l
10
MC/DC0%0/1
shift @_ || (return $self->error('No element was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
395 1 ▶ return( $self->error( "Element object provided is not an HTML::Object::DOM::Element" ) ) if( !$self->_is_a( $elem => 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($elem, "HTML::Object::DOM::Element") 0 1 1
396 1 ▶ $elem->removeData( scalar( @_ ) ? @_ : () );
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ ? : 1 0 1
397 1 ▶ return( $self->pass_error( $elem->error ) ) if( $elem->error );
Branch: 1 branch
BranchTrueFalseTotal
if $elem->error 0 1 1
398 1 return;
399 }
400  
401 # NOTE: support() is not supported
402 # <https://api.jquery.com/jQuery.support/>
403  
404 sub trim
405 {
406 1 ▶ my $self = shift( @_ );
Subroutine trim: called CC=4 SCAR=15.2
407 1 my $this = shift( @_ );
408 1 ▶ return( $this ) if( $self->_is_empty( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_empty($this) 0 1 1
409 1 ▶ if( ref( $this ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this and not $self->_can_overload($this, "\"\"")) 0 1 1
Condition33%1/3
ref $this and not $self->_can_overload($this, "\"\"")
!ll&&!rl&&r
100
MC/DC0%0/2
ref $this and not $self->_can_overload($this, "\"\"")
ref $this not $self->_can_overload($this, "\"\"")
Truth table33%1/3
A and not(B)
A= ref $thisB= not $self->_can_overload($this, "\"\"")
ABresult
0X0
100
111
410 !$self->_can_overload( $this => '""' ) )
411 {
412 0 return( $self->error( "Value provided is not a string nor a stringifyable object." ) );
413 }
414 1 my $str = "$this";
415 1 $str =~ s/^[[:blank:]\h\v]+|[[:blank:]\h\v]+$//gs;
416 1 return( $str );
417 }
418  
419 sub type
420 {
421 13 ▶ my $self = shift( @_ );
Subroutine type: called CC=10 SCAR=23.0
422 13 my $this = shift( @_ );
423 13 ▶ if( !defined( $this ) )
Branch: 9 branches
BranchTrueFalseTotal
if (not defined $this) { } 2 11 13
elsif ($self->_is_hash($this, 'strict')) { } 1 10 11
elsif ($self->_is_array($this)) { } 2 8 10
elsif ($self->_is_a($this, ['DateTime', 'Module::Generic::DateTime'])) { } 1 7 8
elsif ($self->_is_a($this, ['Module::Generic::Boolean', 'JSON::PP::Boolean'])) { } 1 6 7
elsif ($self->_is_a($this, 'Regexp')) { } 1 5 6
elsif ($self->_is_a($this, ['Module::Generic::Exception', 'Error', 'Throwable::Error'])) { } 1 4 5
elsif ($self->_is_number($this)) { } 1 3 4
elsif ($self->_look_like_number($this)) { } 1 2 3
424 {
425 2 return( 'undef' );
426 }
427 elsif( $self->_is_hash( $this => 'strict' ) )
428 {
429 1 return( 'hash' );
430 }
431 elsif( $self->_is_array( $this ) )
432 {
433 2 return( 'array' );
434 }
435 elsif( $self->_is_a( $this => [qw( DateTime Module::Generic::DateTime )] ) )
436 {
437 1 return( 'date' );
438 }
439 elsif( $self->_is_a( $this => [qw( Module::Generic::Boolean JSON::PP::Boolean )] ) )
440 {
441 1 return( 'boolean' );
442 }
443 elsif( $self->_is_a( $this => 'Regexp' ) )
444 {
445 1 return( 'regexp' );
446 }
447 elsif( $self->_is_a( $this => [qw( Module::Generic::Exception Error Throwable::Error )] ) )
448 {
449 1 return( 'error' );
450 }
451 elsif( $self->_is_number( $this ) )
452 {
453 1 return( 'number' );
454 }
455 elsif( $self->_look_like_number( $this ) )
456 {
457 1 return( 'number' );
458 }
459 else
460 {
461 2 return( 'string' );
462 }
463 }
464  
465 sub unique
466 {
467 2 ▶ my $self = shift( @_ );
Subroutine unique: called CC=3 SCAR=11.3
468 2 ▶ my $arr = shift( @_ ) || return( $self->error( "No array was provided to make unique." ) );
Condition50%1/2
shift @_ || (return $self->error('No array was provided to make unique.'))
l!l
20
MC/DC0%0/1
shift @_ || (return $self->error('No array was provided to make unique.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
469 2 ▶ return( $self->error( "Value provided is not an array reference or an array object." ) ) if( !$self->_is_array( $arr ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($arr) 0 2 2
470 2 my $res = $self->new_array( $arr )->unique;
471 2 return( $res );
472 }
473  
474 sub uniqueSort
475 {
476 1 ▶ my $self = shift( @_ );
Subroutine uniqueSort: called CC=4 SCAR=20.6
477 1 ▶ my $new = $self->unique( @_ ) || return( $self->pass_error );
Condition50%1/2
$self->unique(@_) || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$self->unique(@_) || (return $self->pass_error)
$self->unique(@_)
Truth table50%1/2
A
A= $self->unique(@_)
Aresult
11
00
478 1 ▶ return( $new ) if( $new->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $new->is_empty 0 1 1
479 1 my $root = $new->first->getRootNode;
480 # <https://stackoverflow.com/questions/63575333/javascript-replacement-of-sourceindex-in-chromium-browsers>
481 # <https://developer.mozilla.org/en-US/docs/Web/API/Document/all>
482 # <https://johnresig.com/blog/comparing-document-position/#postcomment>
483 # Compare Position - MIT Licensed, John Resig
484 # function comparePosition(a, b)
485 # {
486 # return a.compareDocumentPosition
487 # ? a.compareDocumentPosition(b)
488 # : a.contains
489 # ? ( a != b && a.contains(b) && 16 ) +
490 # ( a != b && b.contains(a) && 8 ) +
491 # ( a.sourceIndex >= 0 && b.sourceIndex >= 0
492 # ? ( a.sourceIndex < b.sourceIndex && 4 ) + ( a.sourceIndex > b.sourceIndex && 2 )
493 # : 1
494 # ) + 0
495 # : 0;
496 # }
497 1 my $all = $root->querySelectorAll('*');
498 1 ▶ for( my $i = 0; $i < scalar( @$all ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$all) 11 1 12
499 {
500 11 my $e = $all->[$i];
501 11 $e->sourceIndex( $i );
502 }
503 $new = $new->sort(sub
504 {
505 7 ▶ my( $a, $b ) = @_;
Subroutine __ANON__: called CC=13 SCAR=49.0
506 return(
507 7 ▶ $a->can( 'compareDocumentPosition' )
Branch: 3 branches
BranchTrueFalseTotal
$a->can('compareDocumentPosition') ? : 7 0 7
$a->can('contains') ? : 0 0 0
($a->sourceIndex // -1) >= 0 && ($b->sourceIndex // -1) >= 0 ? : 0 0 0
Condition0%0/21
$a != $b && $a->contains($b) && 16
!ll
00
$a != $b and $a->contains($b)
!ll&&!rl&&r
000
$a != $b && $b->contains($a) && 8
!ll
00
$a != $b and $b->contains($a)
!ll&&!rl&&r
000
($a->sourceIndex // -1) >= 0 and ($b->sourceIndex // -1) >= 0
!ll&&!rl&&r
000
$a->sourceIndex // -1
l!l
00
$b->sourceIndex // -1
l!l
00
$a->sourceIndex < $b->sourceIndex && 4
!ll
00
$a->sourceIndex > $b->sourceIndex && 2
!ll
00
MC/DC0%0/2
$a != $b && $a->contains($b) && 16
$a != $b $a->contains($b)
MC/DC0%0/2
$a != $b && $b->contains($a) && 8
$a != $b $b->contains($a)
MC/DC0%0/2
($a->sourceIndex // -1) >= 0 and ($b->sourceIndex // -1) >= 0
$a->sourceIndex $b->sourceIndex
MC/DC0%0/1
$a->sourceIndex < $b->sourceIndex && 4
$a->sourceIndex < $b->sourceIndex
MC/DC0%0/1
$a->sourceIndex > $b->sourceIndex && 2
$a->sourceIndex > $b->sourceIndex
Truth table0%0/3
A and B
A= $a != $bB= $a->contains($b)
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $a != $bB= $b->contains($a)
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $a->sourceIndexB= $b->sourceIndex
ABresult
0X0
100
111
Truth table0%0/2
A
A= $a->sourceIndex < $b->sourceIndex
Aresult
00
11
Truth table0%0/2
A
A= $a->sourceIndex > $b->sourceIndex
Aresult
00
11
508 ? $a->compareDocumentPosition( $b )
509 : $a->can( 'contains' )
510 ? ( $a !=$ b && $a->contains($b) && 16 ) +
511 ( $a != $b && $b->contains($a) && 8 ) +
512 ( ( $a->sourceIndex // -1 ) >= 0 && ( $b->sourceIndex // -1 ) >= 0
513 ? ( $a->sourceIndex < $b->sourceIndex && 4 ) + ( $a->sourceIndex > $b->sourceIndex && 2 )
514 : 1
515 ) + 0
516 : 0
517 );
518 1 });
519 1 return( $new );
520 }
521  
522 # NOTE: HTML::Object::DOM::Element class
523 package HTML::Object::DOM::Element;
524 BEGIN
525 {
526 7 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
527 7 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
528 7 ▶ use vars qw( $XP $LOOK_LIKE_HTML $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
529 7 ▶ use CSS::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
530 7 ▶ use HTML::Object::Collection;
Subroutine BEGIN: called CC=1 SCAR=0.0
531 7 ▶ use HTML::Object::DOM::Attribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
532 7 ▶ use HTML::Object::DOM::Boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
533 7 ▶ use HTML::Object::DOM::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
534 7 ▶ use HTML::Object::DOM::Number;
Subroutine BEGIN: called CC=1 SCAR=0.0
535 7 ▶ use HTML::Object::DOM::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
536 # use HTML::Object::DOM::Text;
537 7 ▶ use HTML::Selector::XPath 0.20 qw( selector_to_xpath );
Subroutine BEGIN: called CC=1 SCAR=0.0
538 7 ▶ use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
539 # use Promise::XS ();
540 # use Promise::Me;
541 7 ▶ use HTML::Object::XPath;
Subroutine BEGIN: called CC=1 SCAR=0.0
542 use overload (
543 7 'eq' => \&_same_as,
544 '==' => \&_same_as,
545 fallback => 1,
546 7 ▶ );
Subroutine BEGIN: called CC=1 SCAR=0.0
547 7 ▶ our $XP;
Subroutine BEGIN: called CC=1 SCAR=0.0
548 # As perl jQuery documentation
549 7 our $LOOK_LIKE_HTML = qr/^[[:blank:]\h\v]*\<\w+.*?\>/;
550 };
551  
552 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
553 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
554 7 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
555  
556 # Takes a selector (e.g. '.some-class'); or
557 # a collection (i.e. one or more elements resulting from a find or equivalent query); or
558 # "HTML fragment to add to the set of matched elements."; or
559 # a selector and a context (i.e. an element object); or
560 # a element object
561 # $self->add( $selector );
562 # $self->add( $elements );
563 # $self->add( $html );
564 # $self->add( $selector, $context );
565 sub add
566 {
567 2 ▶ my $self = shift( @_ );
Subroutine add: called CC=17 SCAR=44.3
Pod undocumented
568 2 my( $this, $context ) = @_;
569 # Compliant with what jQuery does, i.e. when no argument is provide this just returns a collection of the collecting object
570 2 my $collection = $self->new_collection( end => $self );
571 # if( $self->isa_element && !$self->isa_collection )
572 2 ▶ if( $self->isa_collection )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->isa_collection) { } 2 0 2
elsif ($self->isa_element) { } 0 0 0
573 {
574 2 $collection->children( $self->children );
575 }
576 elsif( $self->isa_element )
577 {
578 0 $collection->children->push( $self );
579 }
580  
581 2 ▶ if( !defined( $this ) )
Branch: 3 branches
BranchTrueFalseTotal
if (CORE::not defined $this) { } 0 2 2
elsif (CORE::not ref $this or overload::Method($this, '""')) { } 2 0 2
elsif (CORE::not $self->_is_object($this)) { } 0 0 0
582 {
583 0 return( $collection )
584 }
585 # e.g.: $( "p" ).add( "div" )
586 # $( "li" ).add( "<p id='new'>new paragraph</p>" )
587 # elsif( !ref( $this ) || ( ref( $this ) && overload::Overloaded( $this ) && overload::Method( $this, '""' ) ) )
588 ▶ elsif( !ref( $this ) || overload::Method( $this, '""' ) )
Condition33%1/3
CORE::not ref $this or overload::Method($this, "\"\"")
l!l&&r!l&&!r
200
MC/DC0%0/2
CORE::not ref $this or overload::Method($this, "\"\"")
CORE::not ref $this overload::Method($this, "\"\"")
Truth table33%1/3
not(A) or B
A= CORE::not ref $thisB= overload::Method($this, "\"\"")
ABresult
1X1
011
000
589 {
590 # https://api.jquery.com/Types/#htmlString
591 # $( "li" ).add( "<p id='new'>new paragraph</p>" )
592 2 ▶ if( "$this" =~ /$LOOK_LIKE_HTML/ )
Branch: 1 branch
BranchTrueFalseTotal
if ("$this" =~ /$HTML::Object::DOM::Element::LOOK_LIKE_HTML/) { } 0 2 2
593 {
594 0 my $p = $self->new_parser;
595 0 ▶ $this = $p->parse_data( "$this" ) || return( $self->pass_error( $p->error ) );
Condition0%0/2
$p->parse_data("$this") || (return $self->pass_error($p->error))
l!l
00
MC/DC0%0/1
$p->parse_data("$this") || (return $self->pass_error($p->error))
$p->parse_data("$this")
Truth table0%0/2
A
A= $p->parse_data("$this")
Aresult
11
00
596 }
597 # selector
598 # $( "p" ).add( "div" )
599 else
600 {
601 # $self->add( $selector, $context );
602 2 ▶ if( defined( $context ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $context) { } 0 2 2
elsif (defined $HTML::Object::DOM::GLOBAL_DOM) { } 2 0 2
603 {
604 0 ▶ return( $self->error( "A context has been provided, but it is not an HTML::Object::DOM::Element." ) ) if( !$self->_is_object( $context ) || !$context->isa( 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($context) and $context->isa("HTML::Object::DOM::Element") 0 0 0
Condition0%0/3
$self->_is_object($context) and $context->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($context) and $context->isa("HTML::Object::DOM::Element")
$self->_is_object($context) $context->isa("HTML::Object::DOM::Element")
Truth table0%0/3
A and B
A= $self->_is_object($context)B= $context->isa("HTML::Object::DOM::Element")
ABresult
0X0
100
111
605 0 ▶ $this = $context->find( "$this" ) || return( $self->pass_error( $context->error ) );
Condition0%0/2
$context->find("$this") || (return $self->pass_error($context->error))
l!l
00
MC/DC0%0/1
$context->find("$this") || (return $self->pass_error($context->error))
$context->find("$this")
Truth table0%0/2
A
A= $context->find("$this")
Aresult
11
00
606 }
607 # $self->add( $selector );
608 elsif( defined( $HTML::Object::DOM::GLOBAL_DOM ) )
609 {
610 2 my $selector = "$this";
611 2 ▶ $this = $HTML::Object::DOM::GLOBAL_DOM->find( "$selector" ) || return( $self->pass_error( $HTML::Object::DOM::GLOBAL_DOM->error ) );
Condition50%1/2
$HTML::Object::DOM::GLOBAL_DOM->find("$selector") || (return $self->pass_error($HTML::Object::DOM::GLOBAL_DOM->error))
l!l
20
MC/DC0%0/1
$HTML::Object::DOM::GLOBAL_DOM->find("$selector") || (return $self->pass_error($HTML::Object::DOM::GLOBAL_DOM->error))
$HTML::Object::DOM::GLOBAL_DOM->find("$selector")
Truth table50%1/2
A
A= $HTML::Object::DOM::GLOBAL_DOM->find("$selector")
Aresult
11
00
612 }
613 else
614 {
615 0 return( $self->error( "You need to provide some context to the selector by supplying an HTML::Object::DOM::Element object." ) );
616 }
617 }
618 }
619 # Some array or hash ref provided maybe ?
620 elsif( !$self->_is_object( $this ) )
621 {
622 0 return( $self->error( "I was expecting an HTML::Object::DOM::Element, an HTML::Object::Collection, an html string or a selector., but instead I got '$this'." ) );
623 }
624  
625 # We now have either an element object or a collection of them
626 # We return a new collection either way
627 2 ▶ if( $self->isa_collection( $this ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->isa_collection($this)) { } 2 0 2
elsif ($this->isa('HTML::Object::DOM::Element')) { } 0 0 0
628 {
629 2 $collection->children->merge( $this->children->unique );
630 }
631 elsif( $this->isa( 'HTML::Object::DOM::Element' ) )
632 {
633 0 $collection->children->push( $this );
634 }
635 else
636 {
637 0 return( $self->error( "An object of class \"", ref( $this ), "\" was provided, but I do not know what to do with it. I was expecting an HTML::Object::DOM::Element, or an HTML::Object::Collection." ) );
638 }
639 2 return( $collection );
640 }
641  
642 # To make it look like really like jQuery
643 sub addClass
644 {
645 1 ▶ my( $self, $class ) = @_;
Subroutine addClass: called CC=8 SCAR=25.0
Pod undocumented
646 1 ▶ return( $self->error( "I received a reference to add as a class, but was expecting a string or a code reference." ) ) if( ref( $class ) && ref( $class ) ne 'CODE' && !( overload::Overloaded( $class ) && overload::Method( $class, '""' ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $class and ref $class ne "CODE" and CORE::not overload::Overloaded($class) && overload::Method($class, "\"\"") 0 1 1
Condition22%2/9
ref $class and ref $class ne "CODE" and CORE::not overload::Overloaded($class) && overload::Method($class, "\"\"")
!ll&&!rl&&r
100
ref $class and ref $class ne "CODE"
!ll&&!rl&&r
100
overload::Overloaded($class) && overload::Method($class, '""')
!ll&&!rl&&r
000
MC/DC0%0/4
ref $class and ref $class ne "CODE" and CORE::not overload::Overloaded($class) && overload::Method($class, "\"\"")
ref $class ref $class ne "CODE" overload::Overloaded($class) overload::Method($class, '""')
Truth table20%1/5
A and B and not(C && D)
A= ref $classB= ref $class ne "CODE"C= overload::Overloaded($class)D= overload::Method($class, '""')
ABCDresult
0XXX0
10XX0
11110
110X1
11101
647 1 ▶ $class = "${class}" unless( ref( $class ) CORE::eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $class eq "CODE" 1 0 1
648 1 my $set_attr;
649 $set_attr = sub
650 {
651 1 ▶ my( $i, $e ) = @_;
Subroutine __ANON__: called CC=8 SCAR=22.6
652 1 ▶ my $v = $e->attr( 'class' ) // '';
Condition50%1/2
$e->attr("class") // ""
l!l
10
MC/DC0%0/1
$e->attr("class") // ""
$e->attr("class")
Truth table50%1/2
A
A= $e->attr("class")
Aresult
11
00
653 1 local $_ = $e;
654 1 ▶ my $classes = ref( $class ) CORE::eq 'CODE'
Branch: 1 branch
BranchTrueFalseTotal
ref $class eq 'CODE' ? : 0 1 1
655 ? $class->({ element => $e, pos => $i, value => $v })
656 : $class;
657 1 ▶ my $cl_ref = $self->new_array(
Branch: 2 branches
BranchTrueFalseTotal
$self->_is_array($classes) ? : 0 1 1
CORE::length "$classes" ? : 1 0 1
658 $self->_is_array( $classes )
659 ? $classes
660 : CORE::length( "$classes" )
661 ? [split( /[[:blank:]\h]+/, "${classes}" )]
662 : []
663 );
664 1 my $curr;
665 1 ▶ if( CORE::length( "${v}" ) )
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::length "$v") { } 1 0 1
666 {
667 1 ▶ $curr = $self->_is_a( $v, 'Module::Generic::Array' ) ? $v : $self->new_array( [split( /[[:blank:]\h]+/, $v )] );
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_a($v, 'Module::Generic::Array') ? : 0 1 1
668 1 my $new = $self->new_array;
669 $cl_ref->foreach(sub
670 {
671 # <http://www.w3.org/TR/CSS21/grammar.html#scanner>
672 # <https://stackoverflow.com/questions/448981/which-characters-are-valid-in-css-class-names-selectors#449000>
673 1 ▶ $new->push( $_ ) if( !$curr->exists( $_ ) );
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
if CORE::not $curr->exists($_) 1 0 1
674 1 });
675 1 ▶ $curr->push( $new->list ) if( $new->length );
Branch: 1 branch
BranchTrueFalseTotal
if $new->length 1 0 1
676 }
677 else
678 {
679 0 $curr = $cl_ref;
680 }
681 1 $e->attr( class => $curr->join( ' ' )->scalar );
682 1 $e->reset(1);
683 1 };
684  
685 1 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 1 0 1
686 {
687 1 $self->children->for( $set_attr );
688 }
689 else
690 {
691 0 ▶ my $v = $self->attr( 'class' ) // '';
Condition0%0/2
$self->attr("class") // ""
l!l
00
MC/DC0%0/1
$self->attr("class") // ""
$self->attr("class")
Truth table0%0/2
A
A= $self->attr("class")
Aresult
11
00
692 # Here 0 is a dummy number to satisfy the code ref required by for()
693 0 $set_attr->( 0, $self );
694 }
695 }
696  
697 # <https://api.jquery.com/after/>
698 2 ▶sub after { return( shift->_before_after( @_, { action => 'after' } ) ); }
Subroutine after: called CC=1 SCAR=0.0
Pod documented
699  
700 sub ajax
701 {
702 0 ▶ my $self = shift( @_ );
Subroutine ajax: not called CC=95 SCAR=91.2
Pod undocumented
703 0 ▶ my $url = shift( @_ ) ||
Condition0%0/2
shift @_ || (return $self->error('No URL was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No URL was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
704 return( $self->error( "No URL was provided." ) );
705 0 my $opts = $self->_get_args_as_hash( @_ );
706 0 ▶ $opts->{async} //= 1;
Condition0%0/2
$opts->{"async"} //= 1
l!l
00
MC/DC0%0/1
$opts->{"async"} //= 1
$opts->{"async"}
Truth table0%0/2
A
A= $opts->{"async"}
Aresult
11
00
707 0 $opts->{cache} = 0;
708 0 ▶ $opts->{processData} //= 1;
Condition0%0/2
$opts->{"processData"} //= 1
l!l
00
MC/DC0%0/1
$opts->{"processData"} //= 1
$opts->{"processData"}
Truth table0%0/2
A
A= $opts->{"processData"}
Aresult
11
00
709 0 ▶ $opts->{debug} //= 0;
Condition0%0/2
$opts->{"debug"} //= 0
l!l
00
MC/DC0%0/1
$opts->{"debug"} //= 0
$opts->{"debug"}
Truth table0%0/2
A
A= $opts->{"debug"}
Aresult
11
00
710 0 ▶ $self->_load_class( 'HTTP::Promise', { version => 'v0.5.0' } ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise", {"version", "v0.5.0"}) or return $self->pass_error 0 0 0
711 return( $self->pass_error );
712 0 ▶ $self->_load_class( 'HTTP::Promise::Request' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Request") or return $self->pass_error 0 0 0
713 return( $self->pass_error );
714 0 ▶ $self->_load_class( 'URI', { version => '5.21' } ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("URI", {"version", "5.21"}) or return $self->pass_error 0 0 0
715 return( $self->pass_error );
716 0 ▶ if( !$self->_is_empty( $opts->{url} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_empty($opts->{"url"})) 0 0 0
717 {
718 0 $url = $opts->{url};
719 }
720 0 my $uri = URI->new( "$url" );
721 # Contextual URL that requires a base URL.
722 # We check for documentURI of the root element, if any
723 0 my( $doc_root, $doc_uri );
724 0 ▶ if( ( substr( $url, 0, 1 ) eq '/' ||
Branch: 1 branch
BranchTrueFalseTotal
if (substr($url, 0, 1) eq "/" || substr($url, 0, 2) eq "./" || substr($url, 0, 3) eq "../" and $doc_root = $self->getRootNode and $doc_root->isa("HTML::Object::DOM::Document") and $doc_uri = $doc_root->documentURI) 0 0 0
Condition0%0/15
substr($url, 0, 1) eq "/" || substr($url, 0, 2) eq "./" || substr($url, 0, 3) eq "../" and $doc_root = $self->getRootNode and $doc_root->isa("HTML::Object::DOM::Document") and $doc_uri = $doc_root->documentURI
!ll&&!rl&&r
000
substr($url, 0, 1) eq "/" || substr($url, 0, 2) eq "./" || substr($url, 0, 3) eq "../" and $doc_root = $self->getRootNode and $doc_root->isa("HTML::Object::DOM::Document")
!ll&&!rl&&r
000
substr($url, 0, 1) eq "/" || substr($url, 0, 2) eq "./" || substr($url, 0, 3) eq "../" and $doc_root = $self->getRootNode
!ll&&!rl&&r
000
substr($url, 0, 1) eq "/" or substr($url, 0, 2) eq "./" or substr($url, 0, 3) eq "../"
l!l&&r!l&&!r
000
substr($url, 0, 1) eq "/" or substr($url, 0, 2) eq "./"
l!l&&r!l&&!r
000
MC/DC0%0/6
substr($url, 0, 1) eq "/" || substr($url, 0, 2) eq "./" || substr($url, 0, 3) eq "../" and $doc_root = $self->getRootNode and $doc_root->isa("HTML::Object::DOM::Document") and $doc_uri = $doc_root->documentURI
substr($url, 0, 1) eq "/" substr($url, 0, 2) eq "./" substr($url, 0, 3) eq "../" $doc_root = $self->getRootNode $doc_root->isa("HTML::Object::DOM::Document") $doc_uri = $doc_root->documentURI
Truth table0%0/13
A or B or C and D and E and F
A= substr($url, 0, 1) eq "/"B= substr($url, 0, 2) eq "./"C= substr($url, 0, 3) eq "../"D= $doc_root = $self->getRootNodeE= $doc_root->isa("HTML::Object::DOM::Document")F= $doc_uri = $doc_root->documentURI
ABCDEFresult
000XXX0
1XX0XX0
01X0XX0
0010XX0
1XX10X0
01X10X0
00110X0
1XX1100
01X1100
0011100
1XX1111
01X1111
0011111
725 substr( $url, 0, 2 ) eq './' ||
726 substr( $url, 0, 3 ) eq '../' ) &&
727 ( $doc_root = $self->getRootNode ) &&
728 $doc_root->isa( 'HTML::Object::DOM::Document' ) &&
729 ( $doc_uri = $doc_root->documentURI ) )
730 {
731 0 $uri = $doc_uri->clone;
732 0 $uri->path( $url );
733 }
734 # !contents
735 # !context
736 # converters
737 # !crossDomain
738 # NOTE dataType
739 0 my $dataType;
740 0 ▶ $dataType = $opts->{dataType} if( !$self->_is_empty( $opts->{dataType} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_empty($opts->{"dataType"}) 0 0 0
741 # NOTE error
742 0 my $error;
743 0 ▶ if( $self->_is_code( $opts->{error} ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_code($opts->{'error'})) { } 0 0 0
elsif ($self->_is_array($opts->{'error'})) { } 0 0 0
744 {
745 0 $error = [$opts->{error}];
746 }
747 elsif( $self->_is_array( $opts->{error} ) )
748 {
749 0 ▶ for( my $i = 0; $i < scalar( @{$opts->{error}} ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$opts->{"error"};}) 0 0 0
750 {
751 0 my $this = $opts->{error}->[$i];
752 0 ▶ if( !$self->_is_code( $opts->{error}->[$i] ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_code($opts->{"error"}[$i])) 0 0 0
753 {
754 0 return( $self->error( "Value provided at offset $i with the 'error' argument to ajax method, is not a code reference." ) );
755 }
756 }
757 0 $error = $opts->{error};
758 }
759 # NOTE headers
760 0 ▶ my $headers = ( ( exists( $opts->{headers} ) && ref( $opts->{headers} // '' ) eq 'HASH' ) ? $opts->{headers} : {} );
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'headers'} && ref($opts->{'headers'} // '') eq 'HASH' ? : 0 0 0
Condition0%0/5
exists $opts->{"headers"} and ref($opts->{"headers"} // "") eq "HASH"
!ll&&!rl&&r
000
$opts->{"headers"} // ""
l!l
00
MC/DC0%0/2
exists $opts->{"headers"} and ref($opts->{"headers"} // "") eq "HASH"
exists $opts->{"headers"} $opts->{"headers"}
Truth table0%0/3
A and B
A= exists $opts->{"headers"}B= $opts->{"headers"}
ABresult
0X0
100
111
761 0 ▶ unless( exists( $headers->{X_Requested_With} ) || exists( $headers->{ 'X-Requested-With' } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $headers->{"X_Requested_With"} or exists $headers->{"X-Requested-With"}) 0 0 0
Condition0%0/3
exists $headers->{"X_Requested_With"} or exists $headers->{"X-Requested-With"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $headers->{"X_Requested_With"} or exists $headers->{"X-Requested-With"}
exists $headers->{"X_Requested_With"} exists $headers->{"X-Requested-With"}
Truth table0%0/3
A or B
A= exists $headers->{"X_Requested_With"}B= exists $headers->{"X-Requested-With"}
ABresult
1X1
011
000
762 {
763 0 $headers->{X_Requested_With} = 'XMLHttpRequest';
764 }
765 # !global
766 # !isLocal
767 # !jsonp
768 # !jsonpCallback
769 my $params =
770 {
771 use_promise => ( $opts->{async} ? 1 : 0 ),
772 # NOTE timeout
773 ( $self->_is_integer( $opts->{timeout} ) ? ( timeout => $opts->{timeout} ) : () ),
774 0 ▶ ( ( $self->_is_integer( $opts->{debug} ) && $opts->{debug} ) ? ( debug => $opts->{debug} ) : () ),
Branch: 3 branches
BranchTrueFalseTotal
$opts->{'async'} ? : 0 0 0
$self->_is_integer($opts->{'timeout'}) ? : 0 0 0
$self->_is_integer($opts->{'debug'}) && $opts->{'debug'} ? : 0 0 0
Condition0%0/3
$self->_is_integer($opts->{"debug"}) and $opts->{"debug"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_integer($opts->{"debug"}) and $opts->{"debug"}
$self->_is_integer($opts->{"debug"}) $opts->{"debug"}
Truth table0%0/3
A and B
A= $self->_is_integer($opts->{"debug"})B= $opts->{"debug"}
ABresult
0X0
100
111
775 };
776 # NOTE accepts
777 0 ▶ if( !$self->_is_empty( $opts->{accepts} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not $self->_is_empty($opts->{'accepts'})) { } 0 0 0
elsif (CORE::not $self->_is_empty($opts->{'accept'})) { } 0 0 0
778 {
779 0 $headers->{accept} = $opts->{accepts};
780 }
781 elsif( !$self->_is_empty( $opts->{accept} ) )
782 {
783 0 $headers->{accept} = $opts->{accept};
784 }
785 # NOTE contentType
786 0 ▶ if( !$self->_is_empty( $opts->{contentType} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_empty($opts->{"contentType"})) 0 0 0
787 {
788 0 $headers->{Content_Type} = $opts->{contentType};
789 }
790 # NOTE ifModified
791 0 ▶ if( exists( $opts->{ifModified} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"ifModified"} and ref $opts->{"ifModified"} eq "HASH") 0 0 0
Condition0%0/3
exists $opts->{"ifModified"} and ref $opts->{"ifModified"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"ifModified"} and ref $opts->{"ifModified"} eq "HASH"
exists $opts->{"ifModified"} ref $opts->{"ifModified"} eq "HASH"
Truth table0%0/3
A and B
A= exists $opts->{"ifModified"}B= ref $opts->{"ifModified"} eq "HASH"
ABresult
0X0
100
111
792 ref( $opts->{ifModified} ) eq 'HASH' )
793 {
794 0 my $ifmod = $opts->{ifModified};
795 0 ▶ if( exists( $ifmod->{since} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ifmod->{"since"} and defined $ifmod->{"since"} and CORE::length $ifmod->{"since"}) 0 0 0
Condition0%0/6
exists $ifmod->{"since"} and defined $ifmod->{"since"} and CORE::length $ifmod->{"since"}
!ll&&!rl&&r
000
exists $ifmod->{"since"} and defined $ifmod->{"since"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $ifmod->{"since"} and defined $ifmod->{"since"} and CORE::length $ifmod->{"since"}
exists $ifmod->{"since"} defined $ifmod->{"since"} CORE::length $ifmod->{"since"}
Truth table0%0/4
A and B and C
A= exists $ifmod->{"since"}B= defined $ifmod->{"since"}C= CORE::length $ifmod->{"since"}
ABCresult
0XX0
10X0
1100
1111
796 defined( $ifmod->{since} ) &&
797 CORE::length( $ifmod->{since} ) )
798 {
799 0 my $dt;
800 0 ▶ if( $ifmod->{since} =~ /^\d{10}$/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($ifmod->{'since'} =~ /^\d{10}$/) { } 0 0 0
elsif ($self->_is_a($ifmod->{'since'}, ['DateTime', 'Module::Generic::DateTime'])) { } 0 0 0
801 {
802 # try-catch
803 0 local $@;
804 $dt = eval
805 0 {
806 0 DateTime->from_epoch( epoch => $ifmod->{since} );
807 };
808 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
809 {
810 0 return( $self->error( "Error with the timestamp provided for the option ifModified: $@" ) );
811 }
812 }
813 elsif( $self->_is_a( $ifmod->{since} => [qw( DateTime Module::Generic::DateTime )] ) )
814 {
815 0 $dt = $ifmod->{since};
816 }
817 else
818 {
819 0 ▶ return( $self->error( "Unsupported value provided to option ifModified->since: '", ( $ifmod->{since} // 'undef' ), "'" ) );
Condition0%0/2
$ifmod->{"since"} // "undef"
l!l
00
MC/DC0%0/1
$ifmod->{"since"} // "undef"
$ifmod->{"since"}
Truth table0%0/2
A
A= $ifmod->{"since"}
Aresult
11
00
820 }
821  
822 0 ▶ $self->_load_class( 'DateTime::Format::Strptime' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DateTime::Format::Strptime") or return $self->pass_error 0 0 0
823 return( $self->pass_error );
824 0 $dt->set_time_zone( 'GMT' );
825 0 my $fmt = DateTime::Format::Strptime->new(
826 pattern => '%a, %d %b %Y %H:%M:%S GMT',
827 locale => 'en_GB',
828 time_zone => 'GMT',
829 );
830 0 $dt->set_formatter( $fmt );
831 0 $headers->{If_Modified_Since} = $dt;
832 }
833 0 ▶ if( exists( $ifmod->{etag} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ifmod->{"etag"} and defined $ifmod->{"etag"} and CORE::length $ifmod->{"etag"}) 0 0 0
Condition0%0/6
exists $ifmod->{"etag"} and defined $ifmod->{"etag"} and CORE::length $ifmod->{"etag"}
!ll&&!rl&&r
000
exists $ifmod->{"etag"} and defined $ifmod->{"etag"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $ifmod->{"etag"} and defined $ifmod->{"etag"} and CORE::length $ifmod->{"etag"}
exists $ifmod->{"etag"} defined $ifmod->{"etag"} CORE::length $ifmod->{"etag"}
Truth table0%0/4
A and B and C
A= exists $ifmod->{"etag"}B= defined $ifmod->{"etag"}C= CORE::length $ifmod->{"etag"}
ABCresult
0XX0
10X0
1100
1111
834 defined( $ifmod->{etag} ) &&
835 CORE::length( $ifmod->{etag} ) )
836 {
837 0 ▶ if( $ifmod->{etag} =~ /^[\w\-]+$/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($ifmod->{'etag'} =~ /^[\w\-]+$/) { } 0 0 0
elsif ($ifmod->{'etag'} =~ m[W/"^[\w\-]+"$]) { } 0 0 0
838 {
839 0 $headers->{If_None_Match} = '"' . $ifmod->{etag} . '"';
840 }
841 # Useless to use the weak prefix since If-None-Match only uses the weak algorithm
842 elsif( $ifmod->{etag} =~ m,W/"^[\w\-]+"$, )
843 {
844 0 $headers->{If_None_Match} = $ifmod->{etag};
845 }
846 else
847 {
848 0 return( $self->error( "The etag provided for the option ifModified->etag contains illegal characters." ) );
849 }
850 }
851 }
852 # !isLocal
853 # !jsonp
854 # NOTE method, type
855 0 my $method = 'get';
856 0 ▶ $opts->{method} = $opts->{type} if( !$self->_is_empty( $opts->{method} ) && !$self->_is_empty( $opts->{type} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_empty($opts->{"method"}) or $self->_is_empty($opts->{"type"}) 0 0 0
Condition0%0/3
$self->_is_empty($opts->{"method"}) or $self->_is_empty($opts->{"type"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_is_empty($opts->{"method"}) or $self->_is_empty($opts->{"type"})
$self->_is_empty($opts->{"method"}) $self->_is_empty($opts->{"type"})
Truth table0%0/3
A or B
A= $self->_is_empty($opts->{"method"})B= $self->_is_empty($opts->{"type"})
ABresult
1X1
011
000
857 0 ▶ if( exists( $opts->{method} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"method"} and defined $opts->{"method"} and CORE::length($opts->{"method"} // "")) 0 0 0
Condition0%0/8
exists $opts->{"method"} and defined $opts->{"method"} and CORE::length($opts->{"method"} // "")
!ll&&!rl&&r
000
exists $opts->{"method"} and defined $opts->{"method"}
!ll&&!rl&&r
000
$opts->{"method"} // ""
l!l
00
MC/DC0%0/3
exists $opts->{"method"} and defined $opts->{"method"} and CORE::length($opts->{"method"} // "")
exists $opts->{"method"} defined $opts->{"method"} $opts->{"method"}
Truth table0%0/4
A and B and C
A= exists $opts->{"method"}B= defined $opts->{"method"}C= $opts->{"method"}
ABCresult
0XX0
10X0
1100
1111
858 defined( $opts->{method} ) &&
859 CORE::length( $opts->{method} // '' ) )
860 {
861 0 ▶ if( $opts->{method} =~ /^(get|head|options|patch|post|put)$/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'method'} =~ /^(get|head|options|patch|post|put)$/i) { } 0 0 0
862 {
863 0 $method = lc( $1 );
864 }
865 else
866 {
867 0 return( $self->error( "Unsupported HTTP method '$opts->{method}'" ) );
868 }
869 }
870 # NOTE data, processData
871 0 my $data;
872 0 ▶ if( $opts->{data} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'data'}) { } 0 0 0
873 {
874 0 ▶ if( $opts->{processData} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'processData'}) { } 0 0 0
875 {
876 0 $headers->{Content} = $data;
877 }
878 else
879 {
880 0 $headers->{Content} = "$data";
881 }
882 }
883 else
884 {
885 }
886  
887 # NOTE mimeType
888 0 ▶ if( !$self->_is_empty( $opts->{mimeType} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_empty($opts->{"mimeType"})) 0 0 0
889 {
890 0 $headers->{Content_Type} = $opts->{mimeType};
891 }
892 # !scriptAttrs
893 # !scriptCharset
894 # NOTE statusCode
895 0 my $statusCode;
896 0 ▶ if( exists( $opts->{statusCode} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"statusCode"} and defined $opts->{"statusCode"} and ref($opts->{"statusCode"} // "") eq "HASH") 0 0 0
Condition0%0/8
exists $opts->{"statusCode"} and defined $opts->{"statusCode"} and ref($opts->{"statusCode"} // "") eq "HASH"
!ll&&!rl&&r
000
exists $opts->{"statusCode"} and defined $opts->{"statusCode"}
!ll&&!rl&&r
000
$opts->{"statusCode"} // ""
l!l
00
MC/DC0%0/3
exists $opts->{"statusCode"} and defined $opts->{"statusCode"} and ref($opts->{"statusCode"} // "") eq "HASH"
exists $opts->{"statusCode"} defined $opts->{"statusCode"} $opts->{"statusCode"}
Truth table0%0/4
A and B and C
A= exists $opts->{"statusCode"}B= defined $opts->{"statusCode"}C= $opts->{"statusCode"}
ABCresult
0XX0
10X0
1100
1111
897 defined( $opts->{statusCode} ) &&
898 ref( $opts->{statusCode} // '' ) eq 'HASH' )
899 {
900 0 foreach my $c ( sort( keys( %{$opts->{statusCode}} ) ) )
901 {
902 0 ▶ if( !defined( $c ) || !CORE::length( "$c" // '' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not defined $c && CORE::length("$c" // '')) { } 0 0 0
elsif (CORE::not "$c" =~ /^\d{3}$/) { } 0 0 0
Condition0%0/5
defined $c && CORE::length("$c" // '')
!ll&&!rl&&r
000
"$c" // ""
l!l
00
MC/DC0%0/2
defined $c && CORE::length("$c" // '')
defined $c "$c"
Truth table0%0/3
A && B
A= defined $cB= "$c"
ABresult
0X0
100
111
903 {
904 0 return( $self->error( "The code value provided in the option statusCode is empty!" ) );
905 }
906 elsif( "$c" !~ /^\d{3}$/ )
907 {
908 0 return( $self->error( "The code value provided (${c}) is invalid. It should be a 3 digits code, such as 200" ) );
909 }
910  
911 0 my $code_ref = $opts->{statusCode}->{ $c };
912 0 ▶ if( !$self->_is_code( $code_ref ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_code($code_ref)) 0 0 0
913 {
914 0 return( $self->error( "The value provided for status code '${c}' is not a code reference." ) );
915 }
916 }
917 0 $statusCode = $opts->{statusCode};
918 }
919 # NOTE success
920 0 my $success;
921 0 ▶ if( exists( $opts->{success} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"success"}) 0 0 0
922 {
923 0 ▶ if( $self->_is_code( $opts->{success} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_code($opts->{'success'})) { } 0 0 0
924 {
925 0 $success = $opts->{success};
926 }
927 else
928 {
929 0 return( $self->error( "The success callback provided is not a code reference." ) );
930 }
931 }
932 # !traditional
933  
934 0 ▶ my $http = HTTP::Promise->new( %$params ) ||
Condition0%0/2
'HTTP::Promise'->new(%$params) || (return $self->pass_error('HTTP::Promise'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise'->new(%$params) || (return $self->pass_error('HTTP::Promise'->error))
'HTTP::Promise'->new(%$params)
Truth table0%0/2
A
A= 'HTTP::Promise'->new(%$params)
Aresult
11
00
935 return( $self->pass_error( HTTP::Promise->error ) );
936 0 ▶ my $req = $http->prepare( $method => $uri, %$headers ) ||
Condition0%0/2
$http->prepare($method, $uri, %$headers) || (return $self->pass_error($http->error))
l!l
00
MC/DC0%0/1
$http->prepare($method, $uri, %$headers) || (return $self->pass_error($http->error))
$http->prepare($method, $uri, %$headers)
Truth table0%0/2
A
A= $http->prepare($method, $uri, %$headers)
Aresult
11
00
937 return( $self->pass_error( $http->error ) );
938 0 ▶ if( exists( $opts->{xhr} ) && defined( $opts->{xhr} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"xhr"} and defined $opts->{"xhr"}) 0 0 0
Condition0%0/3
exists $opts->{"xhr"} and defined $opts->{"xhr"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"xhr"} and defined $opts->{"xhr"}
exists $opts->{"xhr"} defined $opts->{"xhr"}
Truth table0%0/3
A and B
A= exists $opts->{"xhr"}B= defined $opts->{"xhr"}
ABresult
0X0
100
111
939 {
940 0 ▶ if( $self->_is_code( $opts->{xhr} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_code($opts->{'xhr'})) { } 0 0 0
941 {
942 0 my $code_ref = $opts->{xhr};
943 # try-catch
944 0 local $@;
945 my $this = eval
946 0 {
947 0 $code_ref->( $req );
948 };
949 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
950 {
951 0 ▶ return( $self->error( "An error occurred while calling the callback code reference for xhr: $@" ) ) if( $self->_is_warnings_enabled( 'HTML::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTML::Object") 0 0 0
952 }
953 0 ▶ if( $self->_is_a( $this => 'HTTP::Promise::Request' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($this, 'HTTP::Promise::Request')) { } 0 0 0
954 {
955 0 $req = $this;
956 }
957 else
958 {
959 0 ▶ return( $self->error( "The value returned by the callback (", overload::StrVal( $this // '' ), ") is not an HTTP::Promise::Request object." ) );
Condition0%0/2
$this // ""
l!l
00
MC/DC0%0/1
$this // ""
$this
Truth table0%0/2
A
A= $this
Aresult
11
00
960 }
961 }
962 else
963 {
964 0 return( $self->error( "The value provided for the xhr callback is not a code reference." ) );
965 }
966 }
967  
968 # NOTE password & username
969 0 ▶ if( !$self->_is_empty( $opts->{password} ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_empty($opts->{"password"}) and $self->_is_empty($opts->{"username"})) 0 0 0
Condition0%0/3
$self->_is_empty($opts->{"password"}) and $self->_is_empty($opts->{"username"})
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_empty($opts->{"password"}) and $self->_is_empty($opts->{"username"})
$self->_is_empty($opts->{"password"}) $self->_is_empty($opts->{"username"})
Truth table0%0/3
A and B
A= $self->_is_empty($opts->{"password"})B= $self->_is_empty($opts->{"username"})
ABresult
0X0
100
111
970 !$self->_is_empty( $opts->{username} ) )
971 {
972 0 ▶ $req->headers->authorization_basic( ( $opts->{username} // '' ), ( $opts->{password} // '' ) );
Condition0%0/4
$opts->{"username"} // ""
l!l
00
$opts->{"password"} // ""
l!l
00
MC/DC0%0/1
$opts->{"username"} // ""
$opts->{"username"}
MC/DC0%0/1
$opts->{"password"} // ""
$opts->{"password"}
Truth table0%0/2
A
A= $opts->{"username"}
Aresult
11
00
Truth table0%0/2
A
A= $opts->{"password"}
Aresult
11
00
973 }
974 # NOTE beforeSend
975 0 ▶ my $beforeSend = ( $self->_is_code( $opts->{beforeSend} ) ? $opts->{beforeSend} : sub{ $_[0] } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_code($opts->{'beforeSend'}) ? : 0 0 0
976 0 my $complete;
977 0 ▶ if( $self->_is_code( $opts->{complete} ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_code($opts->{'complete'})) { } 0 0 0
elsif ($self->_is_array($opts->{'complete'})) { } 0 0 0
978 {
979 0 $complete = [$opts->{complete}];
980 }
981 elsif( $self->_is_array( $opts->{complete} ) )
982 {
983 0 ▶ for( my $i = 0; $i < scalar( @{$opts->{complete}} ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$opts->{"complete"};}) 0 0 0
984 {
985 0 my $this = $opts->{complete}->[$i];
986 0 ▶ if( !$self->_is_code( $opts->{complete}->[$i] ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_code($opts->{"complete"}[$i])) 0 0 0
987 {
988 0 return( $self->error( "Value provided at offset $i with the 'complete' argument to ajax method, is not a code reference." ) );
989 }
990 }
991 0 $complete = $opts->{complete};
992 }
993  
994 # NOTE dataFilter
995 0 ▶ my $dataFilter = ( $self->_is_code( $opts->{dataFilter} ) ? $opts->{dataFilter} : sub{ $_[0] } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_code($opts->{'dataFilter'}) ? : 0 0 0
996 my $code2status = sub
997 {
998 0 ▶ my $resp = shift( @_ );
Subroutine __ANON__: not called CC=7 SCAR=40.3
999 0 my $code = $resp->code;
1000 0 ▶ if( $code == 200 )
Branch: 5 branches
BranchTrueFalseTotal
if ($code == 200) { } 0 0 0
elsif ($code == 204) { } 0 0 0
elsif ($code == 304) { } 0 0 0
elsif ($code == 408) { } 0 0 0
elsif ($code >= 400 and $code <= 599) { } 0 0 0
1001 {
1002 0 return( 'success' );
1003 }
1004 elsif( $code == 204 )
1005 {
1006 0 return( 'nocontent' );
1007 }
1008 elsif( $code == 304 )
1009 {
1010 0 return( 'notmodified' );
1011 }
1012 elsif( $code == 408 )
1013 {
1014 0 return( 'timeout' );
1015 }
1016 ▶ elsif( $code >= 400 && $code <= 599 )
Condition0%0/3
$code >= 400 and $code <= 599
!ll&&!rl&&r
000
MC/DC0%0/2
$code >= 400 and $code <= 599
$code >= 400 $code <= 599
Truth table0%0/3
A and B
A= $code >= 400B= $code <= 599
ABresult
0X0
100
111
1017 {
1018 0 return( 'error' );
1019 }
1020 else
1021 {
1022 0 return( 'success' );
1023 }
1024 0 };
1025  
1026 my $process = sub
1027 {
1028 0 ▶ my $resp = shift( @_ );
Subroutine __ANON__: not called CC=27 SCAR=66.3
1029 0 my( $resolve, $reject ) = @_;
1030 0 my $status = $code2status->( $resp );
1031 0 my $code = $resp->code;
1032 # TODO: converters
1033 0 my $content = $resp->decoded_content;
1034 0 $content = $dataFilter->( $content );
1035 0 my $decoded;
1036 0 ▶ unless( defined( $dataType ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dataType) 0 0 0
1037 {
1038 0 my $type = $resp->headers->type;
1039 0 ▶ if( defined( $type ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type) 0 0 0
1040 {
1041 0 ▶ if( $type =~ m,^application/json,i )
Branch: 4 branches
BranchTrueFalseTotal
if ($type =~ m[^application/json]i) { } 0 0 0
elsif ($type =~ m[^text/html]i) { } 0 0 0
elsif ($type =~ m[^text/xml]i) { } 0 0 0
elsif ($type =~ m[^text/plain]i) { } 0 0 0
1042 {
1043 0 $dataType = 'json';
1044 }
1045 elsif( $type =~ m,^text/html,i )
1046 {
1047 0 $dataType = 'html';
1048 }
1049 elsif( $type =~ m,^text/xml,i )
1050 {
1051 0 $dataType = 'xml';
1052 }
1053 elsif( $type =~ m,^text/plain,i )
1054 {
1055 0 $dataType = 'text';
1056 }
1057 else
1058 {
1059 0 $dataType = 'application/octet-stream';
1060 }
1061 }
1062 }
1063  
1064 0 ▶ if( defined( $dataType ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dataType) { } 0 0 0
1065 {
1066 0 ▶ if( ( $dataType eq 'json' ||
Branch: 1 branch
BranchTrueFalseTotal
if ($dataType eq "json" || $dataType eq "jsonp" and defined $content) 0 0 0
Condition0%0/6
$dataType eq "json" || $dataType eq "jsonp" and defined $content
!ll&&!rl&&r
000
$dataType eq "json" or $dataType eq "jsonp"
l!l&&r!l&&!r
000
MC/DC0%0/3
$dataType eq "json" || $dataType eq "jsonp" and defined $content
$dataType eq "json" $dataType eq "jsonp" defined $content
Truth table0%0/5
A or B and C
A= $dataType eq "json"B= $dataType eq "jsonp"C= defined $content
ABCresult
00X0
1X00
0100
1X11
0111
1067 $dataType eq 'jsonp' ) &&
1068 defined( $content ) )
1069 {
1070 0 my $j = $self->new_json->relaxed->utf8;
1071 # try-catch
1072 0 local $@;
1073 $decoded = eval
1074 0 {
1075 0 $j->decode( "$content" );
1076 };
1077 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
1078 {
1079 0 $self->error( "Error decoding ", CORE::length( $content ), " bytes of JSON data: $@" );
1080 0 ▶ if( defined( $reject ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $reject) { } 0 0 0
1081 {
1082 0 return({ error => $self->error });
1083 }
1084 else
1085 {
1086 0 return( $self->pass_error );
1087 }
1088 }
1089 else
1090 {
1091 # $resolve->( $decoded );
1092 0 $content = $decoded;
1093 }
1094 }
1095 }
1096 else
1097 {
1098 # Hmm, dataType is still undefined
1099 }
1100  
1101 0 ▶ if( defined( $statusCode ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $statusCode) 0 0 0
1102 {
1103 0 my $code_ref = $statusCode->{ $code };
1104 # try-catch
1105 0 local $@;
1106 eval
1107 0 {
1108 0 $code_ref->( $content, $status, $resp, $http );
1109 };
1110 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1111 {
1112 0 ▶ warn( "Error calling statusCode callback for code '${code}': $@" ) if( $self->_is_warnings_enabled( 'HTML::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTML::Object") 0 0 0
1113 }
1114 }
1115  
1116 0 ▶ if( defined( $complete ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $complete) 0 0 0
1117 {
1118 0 foreach my $coderef ( @$complete )
1119 {
1120 0 $coderef->( $resp, $status, $http );
1121 }
1122 }
1123  
1124 0 ▶ if( defined( $success ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $success) 0 0 0
1125 {
1126 # try-catch
1127 0 local $@;
1128 eval
1129 0 {
1130 0 $success->( $content, $status, $resp, $http );
1131 };
1132 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1133 {
1134 0 ▶ warn( "Error calling success callback: $@" ) if( $self->_is_warnings_enabled( 'HTML::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTML::Object") 0 0 0
1135 }
1136 }
1137 0 ▶ if( defined( $error ) && ( $code >= 400 && $code < 600 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error and ($code >= 400 and $code < 600)) 0 0 0
Condition0%0/6
defined $error and ($code >= 400 and $code < 600)
!ll&&!rl&&r
000
$code >= 400 and $code < 600
!ll&&!rl&&r
000
MC/DC0%0/3
defined $error and ($code >= 400 and $code < 600)
defined $error $code >= 400 $code < 600
Truth table0%0/4
A and B and C
A= defined $errorB= $code >= 400C= $code < 600
ABCresult
0XX0
10X0
1100
1111
1138 {
1139 0 my $status = $resp->status;
1140 0 ▶ for( my $i = 0; $i < scalar( @$error ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$error) 0 0 0
1141 {
1142 0 my $code_ref = $error->[$i];
1143 # try-catch
1144 0 local $@;
1145 eval
1146 0 {
1147 # No exception object, because this is just a regular HTTP error
1148 0 $code_ref->( $req, $status );
1149 };
1150 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1151 {
1152 0 ▶ warn( "An error occurred while calling the error callback at offset $i: $@" ) if( $self->_is_warnings_enabled( 'HTML::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTML::Object") 0 0 0
1153 }
1154 }
1155 }
1156 return({
1157 0 content => $content,
1158 status => $status,
1159 resp => $resp,
1160 http => $http,
1161 });
1162 0 };
1163  
1164 0 ▶ if( $params->{use_promise} )
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'use_promise'}) { } 0 0 0
1165 {
1166 0 my $p;
1167 $p = Promise::Me->new(sub
1168 {
1169 0 ▶ my( $resolve_main, $reject_main ) = @$_;
Subroutine __ANON__: not called CC=7 SCAR=40.3
1170 # NOTE: Process beforeSend for asynchronous process
1171 0 my $this = $beforeSend->( $req );
1172 0 ▶ if( !defined( $this ) || !CORE::length( $this // '' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not defined $this && CORE::length($this // '')) { } 0 0 0
elsif (CORE::not $self->_is_a($this, 'HTTP::Promise::Request')) { } 0 0 0
Condition0%0/5
defined $this && CORE::length($this // '')
!ll&&!rl&&r
000
$this // ""
l!l
00
MC/DC0%0/2
defined $this && CORE::length($this // '')
defined $this $this
Truth table0%0/3
A && B
A= defined $thisB= $this
ABresult
0X0
100
111
1173 {
1174 0 return( $resolve_main->( '', 'abort', undef, $http ) );
1175 }
1176 elsif( !$self->_is_a( $this => 'HTTP::Promise::Request' ) )
1177 {
1178 0 $self->error( "Value returned by the beforeSend callback is not an HTTP::Promise::Request object." );
1179 0 my $err = $self->error;
1180 0 return( $reject_main->( $err ) );
1181 }
1182 0 $req = $this;
1183 my $prom = $http->request( $req,
1184 ( defined( $opts->{promise_debug} ) ? ( promise_debug => $opts->{promise_debug} ) : () ),
1185 )->then(sub
1186 {
1187 0 ▶ my( $resolve, $reject ) = @$_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
1188 0 my $resp = shift( @_ );
1189 0 ▶ if( !$resp )
Branch: 1 branch
BranchTrueFalseTotal
unless ($resp) 0 0 0
1190 {
1191 0 return( $reject_main->( $http->error ) );
1192 }
1193 0 my $res = $process->( $resp, $resolve_main, $reject_main );
1194 0 ▶ if( $res->{error} )
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"error"}) 0 0 0
1195 {
1196 0 return( $reject_main->( $res->{error} ) );
1197 }
1198 0 return( $resolve_main->( @$res{qw( content status resp http )} ) );
1199 })->catch(sub
1200 {
1201 0 ▶ my $err = shift( @_ );
Subroutine __ANON__: not called CC=5 SCAR=34.0
1202 0 ▶ if( defined( $error ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) 0 0 0
1203 {
1204 0 my $status = 'error';
1205 0 ▶ for( my $i = 0; $i < scalar( @$error ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$error) 0 0 0
1206 {
1207 0 my $code_ref = $error->[$i];
1208 # try-catch
1209 0 local $@;
1210 eval
1211 0 {
1212 0 $code_ref->( $req, $status, $err );
1213 };
1214 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1215 {
1216 0 ▶ warn( "An error occurred while calling the error callback at offset $i: $@" ) if( $self->_is_warnings_enabled( 'HTML::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTML::Object") 0 0 0
1217 }
1218 }
1219 }
1220 0 return( $reject_main->( $err ) );
1221 0 ▶ });
Branch: 1 branch
BranchTrueFalseTotal
defined $opts->{'promise_debug'} ? : 0 0 0
1222 0 ▶ return( $reject_main->( $http->error ) ) if( !$prom );
Branch: 1 branch
BranchTrueFalseTotal
unless $prom 0 0 0
1223 # return(1);
1224 0 return( $prom );
1225 },
1226 {
1227 0 ▶ ( defined( $opts->{promise_debug} ) ? ( debug => $opts->{promise_debug} ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
defined $opts->{'promise_debug'} ? : 0 0 0
1228 });
1229 0 return( $p );
1230 }
1231 # No promise
1232 else
1233 {
1234 # NOTE: Process beforeSend for synchronous process
1235 0 my $this = $beforeSend->( $req );
1236 0 ▶ if( !defined( $this ) || !CORE::length( $this // '' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not defined $this && CORE::length($this // '')) { } 0 0 0
elsif (CORE::not $self->_is_a($this, 'HTTP::Promise::Request')) { } 0 0 0
Condition0%0/5
defined $this && CORE::length($this // '')
!ll&&!rl&&r
000
$this // ""
l!l
00
MC/DC0%0/2
defined $this && CORE::length($this // '')
defined $this $this
Truth table0%0/3
A && B
A= defined $thisB= $this
ABresult
0X0
100
111
1237 {
1238 0 return( '', 'abort', undef, $http );
1239 }
1240 elsif( !$self->_is_a( $this => 'HTTP::Promise::Request' ) )
1241 {
1242 0 return( $self->error( "Value returned by the beforeSend callback is not an HTTP::Promise::Request object." ) );
1243 }
1244 0 $req = $this;
1245 0 my $resp = $http->request( $req );
1246 0 my $res = $process->( $resp );
1247 0 ▶ return( $self->pass_error ) if( $res->{error} );
Branch: 1 branch
BranchTrueFalseTotal
if $res->{"error"} 0 0 0
1248 0 return( @$res{qw( content status resp http )} );
1249 }
1250 }
1251  
1252 # Takes html string (start with <tag...), text object (HTML::Object::DOM::Text), array or element object
1253 # or alternatively a code reference that returns the above
1254 # <https://api.jquery.com/append/>
1255 0 ▶sub append { return( shift->_append_prepend( @_, { action => 'append' } ) ); }
Subroutine append: not called CC=1 SCAR=6.9
Pod documented
1256  
1257 1 ▶sub appendTo { return( shift->_append_prepend_to( @_, { action => 'append' } ) ); }
Subroutine appendTo: called CC=1 SCAR=0.0
Pod undocumented
1258  
1259 # $e->attr( attribute );
1260 # $collection->attribute( attribute );
1261 # $e->attr( attribute1 => value1, attribute2 => value2 );
1262 # $collection->attr( attribute1 => value1, attribute2 => value2 );
1263 # $e->attr( attribute1 => $sub_routine1, attribute2 => $string );
1264 # $collection->attr( attribute1 => $sub_routine1, attribute2 => $string );
1265 sub attr
1266 {
1267 2 ▶ my $self = shift( @_ );
Subroutine attr: called CC=6 SCAR=20.3
Pod documented
1268 2 my @classes = @_;
1269 2 ▶ return if( !scalar( @classes ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @classes 0 2 2
1270 2 ▶ if( scalar( @classes ) > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @classes > 1) { } 1 1 2
1271 {
1272 1 my $ref = {};
1273 1 %$ref = @classes;
1274 1 my $set_attributes;
1275 $set_attributes = sub
1276 {
1277 1 ▶ my $e = shift( @_ );
Subroutine __ANON__: called CC=7 SCAR=22.3
1278 1 ▶ while( my( $a, $v ) = each( %$ref ) )
Branch: 1 branch
BranchTrueFalseTotal
if (() = CORE::each %$ref) 1 1 2
1279 {
1280 1 local $_ = $e;
1281 1 ▶ my $val = ref( $v ) CORE::eq 'CODE'
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'CODE' ? : 0 1 1
1282 ? $v->({ element => $e, attribute => $a, current => $e->attributes->get( $a ) })
1283 : $v;
1284 1 ▶ return( $self->error( "I was expecting a string value for the attribute \"${a}\", but instead got \"", overload::StrVal( $val ), "\"." ) ) if( ref( $val ) && !( overload::Overloaded( $val ) && overload::Method( $val, '""' ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $val and CORE::not overload::Overloaded($val) && overload::Method($val, "\"\"") 0 1 1
Condition16%1/6
ref $val and CORE::not overload::Overloaded($val) && overload::Method($val, "\"\"")
!ll&&!rl&&r
100
overload::Overloaded($val) && overload::Method($val, '""')
!ll&&!rl&&r
000
MC/DC0%0/3
ref $val and CORE::not overload::Overloaded($val) && overload::Method($val, "\"\"")
ref $val overload::Overloaded($val) overload::Method($val, '""')
Truth table25%1/4
A and not(B && C)
A= ref $valB= overload::Overloaded($val)C= overload::Method($val, '""')
ABCresult
0XX0
1110
10X1
1101
1285 1 ▶ if( defined( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 1 0 1
1286 {
1287 1 $val = "$val";
1288 1 $val =~ s/^[[:blank:]\h]+|[[:blank:]\h]+$//g;
1289 1 $e->attributes->set( $a => $val );
1290 }
1291 else
1292 {
1293 0 $e->attributes->delete( $a );
1294 }
1295 }
1296 1 return(1);
1297 1 };
1298  
1299 1 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 1 1
1300 {
1301 $self->children->foreach(sub
1302 {
1303 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
1304 0 $e->reset(1);
1305 # $e->attributes->merge( $ref );
1306 0 ▶ $set_attributes->( $e ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
&$set_attributes($e) or return $self->pass_error 0 0 0
1307 0 });
1308 }
1309 else
1310 {
1311 1 $self->reset(1);
1312 1 ▶ $set_attributes->( $self ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
&$set_attributes($self) or return $self->pass_error 0 1 1
1313 }
1314 1 return( $self );
1315 }
1316 # Get mode
1317 else
1318 {
1319 # return( $self->children->map(sub{ $_->attributes->get( $classes[0] ) }) );
1320 # Get the value of an attribute for the first element in the set of matched elements.
1321 1 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 1 1
1322 {
1323 0 return( $self->children->first->attributes->get( $classes[0] ) );
1324 }
1325 else
1326 {
1327 1 return( $self->attributes->get( $classes[0] ) );
1328 }
1329 }
1330 }
1331  
1332 1 ▶sub before { return( shift->_before_after( @_, { action => 'before' } ) ); }
Subroutine before: called CC=1 SCAR=0.0
Pod documented
1333  
1334 0 ▶sub clearQueue { return( $_[0] ) }
Subroutine clearQueue: not called CC=1 SCAR=6.9
Pod undocumented
1335  
1336 # Takes a selector; or
1337 # a selector and an HTML::Object::DOM::Element as a context; or
1338 # a HTML::Object::DOM::Element object
1339 # "Given a jQuery object that represents a set of DOM elements, the .closest() method searches through these elements and their ancestors in the DOM tree and constructs a new jQuery object from the matching elements."
1340 sub closest
1341 {
1342 0 ▶ my $self = shift( @_ );
Subroutine closest: not called CC=12 SCAR=50.5
Pod documented
1343 0 my $this = shift( @_ );
1344 0 my $context = shift( @_ );
1345 0 my $collection = $self->new_collection;
1346 0 ▶ return $collection if( !defined( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this 0 0 0
1347 0 ▶ if( defined( $context ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (defined $context and !$self->_is_object($context) || $self->_is_object($context) && !$context->isa('HTML::Object::DOM::Element')) { } 0 0 0
elsif (ref $this and $self->_is_object($this) and !$this->isa('HTML::Object::DOM::Element') || overload::Overloaded($this) && !overload::Method($this, '""')) { } 0 0 0
Condition0%0/9
defined $context and !$self->_is_object($context) || $self->_is_object($context) && !$context->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
000
CORE::not $self->_is_object($context) or $self->_is_object($context) and CORE::not $context->isa("HTML::Object::DOM::Element")
l!l&&r!l&&!r
000
$self->_is_object($context) and CORE::not $context->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
000
MC/DC0%0/4
defined $context and !$self->_is_object($context) || $self->_is_object($context) && !$context->isa("HTML::Object::DOM::Element")
defined $context CORE::not $self->_is_object($context) $self->_is_object($context) CORE::not $context->isa("HTML::Object::DOM::Element")
Truth table0%0/5
A and not(B) or C and not(D)
A= defined $contextB= CORE::not $self->_is_object($context)C= $self->_is_object($context)D= CORE::not $context->isa("HTML::Object::DOM::Element")
ABCDresult
0XXX0
100X0
10100
11XX1
10111
1348 ( !$self->_is_object( $context ) ||
1349 ( $self->_is_object( $context ) &&
1350 !$context->isa( 'HTML::Object::DOM::Element' )
1351 )
1352 ) )
1353 {
1354 0 return( $self->error( "Context provided (", overload::StrVal( $context ), ") is not an HTML::Object::DOM::Element." ) );
1355 }
1356 ▶ elsif( ref( $this ) &&
Condition0%0/12
ref $this and $self->_is_object($this) and !$this->isa("HTML::Object::DOM::Element") || overload::Overloaded($this) && !overload::Method($this, "\"\"")
!ll&&!rl&&r
000
ref $this and $self->_is_object($this)
!ll&&!rl&&r
000
CORE::not $this->isa("HTML::Object::DOM::Element") or overload::Overloaded($this) and CORE::not overload::Method($this, "\"\"")
l!l&&r!l&&!r
000
overload::Overloaded($this) and CORE::not overload::Method($this, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/5
ref $this and $self->_is_object($this) and !$this->isa("HTML::Object::DOM::Element") || overload::Overloaded($this) && !overload::Method($this, "\"\"")
ref $this $self->_is_object($this) CORE::not $this->isa("HTML::Object::DOM::Element") overload::Overloaded($this) CORE::not overload::Method($this, "\"\"")
Truth table0%0/6
A and B and not(C) or D and not(E)
A= ref $thisB= $self->_is_object($this)C= CORE::not $this->isa("HTML::Object::DOM::Element")D= overload::Overloaded($this)E= CORE::not overload::Method($this, "\"\"")
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
1357 $self->_is_object( $this ) &&
1358 ( !$this->isa( 'HTML::Object::DOM::Element' ) ||
1359 ( overload::Overloaded( $this ) && !overload::Method( $this, '""' ) )
1360 ) )
1361 {
1362 0 return( $self->error( "I was expecting a selector or an HTML::Object::DOM::Element, but instead received '$this'" ) );
1363 }
1364 else
1365 {
1366 0 return( $self->error( "I was expecting a selector or an HTML::Object::DOM::Element, but instead received '$this'" ) );
1367 }
1368  
1369 0 my $xpath;
1370 0 ▶ if( !ref( $this ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $this) 0 0 0
1371 {
1372 0 $xpath = $self->_xpath_value( $this );
1373 }
1374 0 my $process;
1375 $process = sub
1376 {
1377 0 ▶ my $elem = shift( @_ );
Subroutine __ANON__: not called CC=7 SCAR=40.3
1378 # We reach the limit of our upward search
1379 0 ▶ return if( defined( $context ) && $elem->eid CORE::eq $context->eid );
Branch: 1 branch
BranchTrueFalseTotal
if defined $context and $elem->eid eq $context->eid 0 0 0
Condition0%0/3
defined $context and $elem->eid eq $context->eid
!ll&&!rl&&r
000
MC/DC0%0/2
defined $context and $elem->eid eq $context->eid
defined $context $elem->eid eq $context->eid
Truth table0%0/3
A and B
A= defined $contextB= $elem->eid eq $context->eid
ABresult
0X0
100
111
1380 0 my $parent = $elem->parent;
1381 0 ▶ if( defined( $xpath ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xpath) { } 0 0 0
1382 {
1383 0 ▶ if( $elem->matches( $xpath ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->matches($xpath)) 0 0 0
1384 {
1385 0 $collection->push( $elem );
1386 }
1387 }
1388 else
1389 {
1390 0 ▶ if( $elem->eid CORE::eq $this->eid )
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->eid eq $this->eid) 0 0 0
1391 {
1392 0 $collection->push( $elem );
1393 }
1394 }
1395 0 ▶ return if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
1396 0 return( $process->( $parent ) );
1397 0 };
1398 0 $process->( $self );
1399 0 return( $collection );
1400 }
1401  
1402 sub contains
1403 {
1404 3 ▶ my $self = shift( @_ );
Subroutine contains: called CC=12 SCAR=27.2
Pod documented
1405 3 my( $container, $contained );
1406 3 ▶ if( scalar( @_ ) > 1 )
Branch: 3 branches
BranchTrueFalseTotal
if (scalar @_ > 1) { } 2 1 3
elsif (scalar @_) { } 1 0 1
elsif (CORE::not ref $self and scalar @_ < 2) { } 0 0 0
1407 {
1408 2 ▶ return( $self->error( "Wrong number of argument: \$el->contains( \$container, \$contained )" ) ) if( scalar( @_ ) > 2 );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 2 0 2 2
1409 2 ( $container, $contained ) = @_;
1410 }
1411 elsif( scalar( @_ ) )
1412 {
1413 1 $container = $self;
1414 1 $contained = shift( @_ );
1415 }
1416 ▶ elsif( !ref( $self ) && scalar( @_ ) < 2 )
Condition0%0/3
CORE::not ref $self and scalar @_ < 2
!ll&&!rl&&r
000
MC/DC0%0/2
CORE::not ref $self and scalar @_ < 2
CORE::not ref $self scalar @_ < 2
Truth table0%0/3
not(A) and B
A= CORE::not ref $selfB= scalar @_ < 2
ABresult
0X0
100
111
1417 {
1418 0 return( $self->error( "You need to provide 2 arguments when using contains() as a class function: xQuery->contains( \$container, \$contained )" ) );
1419 }
1420 else
1421 {
1422 0 return( $self->error( "No contained object provided to check." ) );
1423 }
1424 # We need an object to access certain methods
1425 3 ▶ my $this = ref( $self ) ? $self : HTML::Object::DOM->new;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 1 2 3
1426 3 ▶ return( $self->error( "Container value provided is undefined." ) ) if( !defined( $container ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $container 0 3 3
1427 3 ▶ return( $self->error( "Contained value provided is undefined." ) ) if( !defined( $contained ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $contained 0 3 3
1428 3 ▶ return( $this->false ) if( $this->_is_a( $contained => [qw( HTML::Object::DOM::Text HTML::Object::DOM::Comment )] ) );
Branch: 1 branch
BranchTrueFalseTotal
if $this->_is_a($contained, ["HTML::Object::DOM::Text", "HTML::Object::DOM::Comment"]) 0 3 3
1429 3 ▶ return( $self->error( "Container object provided is not an HTML::Object::DOM::Element" ) ) if( !$this->_is_a( $container => 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $this->_is_a($container, "HTML::Object::DOM::Element") 0 3 3
1430 3 ▶ return( $self->error( "Contained object provided is not an HTML::Object::DOM::Element" ) ) if( !$this->_is_a( $contained => 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $this->_is_a($contained, "HTML::Object::DOM::Element") 0 3 3
1431 3 my $crawl;
1432 3 my $seen = {};
1433 $crawl = sub
1434 {
1435 3 ▶ my $kids = shift( @_ );
Subroutine __ANON__: called CC=7 SCAR=19.9
1436 3 my $grand_kids = $this->new_array;
1437 3 ▶ for( my $i = 0; $i < scalar( @$kids ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$kids) 6 2 8
1438 {
1439 6 my $e = $kids->[$i];
1440 # Avoid recursion
1441 6 ▶ next if( ++$seen->{ $e->eid } > 1 );
Branch: 1 branch
BranchTrueFalseTotal
if ++$$seen{$e->eid} > 1 0 6 6
1442 6 ▶ next unless( $this->_is_a( $e => 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $this->_is_a($e, "HTML::Object::DOM::Element") 4 2 6
1443 2 ▶ return( $this->true ) if( $e == $contained );
Branch: 1 branch
BranchTrueFalseTotal
if $e == $contained 1 1 2
1444 1 ▶ $grand_kids->push( $e->children->list ) if( !$e->children->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
unless $e->children->is_empty 1 0 1
1445 }
1446 2 ▶ return( $this->false ) if( $grand_kids->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $grand_kids->is_empty 2 0 2
1447 0 return( $crawl->( $grand_kids ) );
1448 3 };
1449 3 return( $crawl->( $container->children ) );
1450 }
1451  
1452 sub contents
1453 {
1454 1 ▶ my $self = shift( @_ );
Subroutine contents: called CC=2 SCAR=7.1
Pod undocumented
1455 1 my $collection = $self->new_collection;
1456 1 my $children = $collection->children;
1457 1 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 1 0 1
1458 {
1459 $self->children->foreach(sub
1460 {
1461 1 ▶ $children->push( $_->children->list );
Subroutine __ANON__: called CC=1 SCAR=0.0
1462 1 });
1463 }
1464 else
1465 {
1466 0 $children->push( $self->children->list );
1467 }
1468 1 return( $collection );
1469 }
1470  
1471 # Takes a property name; or
1472 # an array reference of one or more css properties; or
1473 # a property name and a value; or
1474 # a property name and a function; or
1475 # an hash reference of property name-value pairs
1476 # <https://api.jquery.com/css/>
1477 # $e->css( $property_name );
1478 # $e->css( [$property_name1, $property_name2, $property_name3] );
1479 # $e->css( $property_name, $value );
1480 # $e->css( $property_name, $code_reference );
1481 # $e->css({ $property_name1 => $value1, $property_name2 => $value2 });
1482 # <https://api.jquery.com/css/>
1483 sub css
1484 {
1485 4 ▶ my $self = shift( @_ );
Subroutine css: called CC=7 SCAR=30.2
Pod undocumented
1486 # "An element should be connected to the DOM when calling .css()"
1487 4 ▶ return( $self->error( "Method css() must be called on an HTML::Object::DOM::Element." ) ) if( ( !$self->isa_element && !$self->isa_collection ) || $self->tag->substr( 0, 1 ) CORE::eq '_' );
Branch: 1 branch
BranchTrueFalseTotal
if CORE::not $self->isa_element || $self->isa_collection or $self->tag->substr(0, 1) eq "_" 0 4 4
Condition33%2/6
CORE::not $self->isa_element || $self->isa_collection or $self->tag->substr(0, 1) eq "_"
l!l&&r!l&&!r
004
$self->isa_element || $self->isa_collection
l!l&&r!l&&!r
400
MC/DC0%0/3
CORE::not $self->isa_element || $self->isa_collection or $self->tag->substr(0, 1) eq "_"
$self->isa_element $self->isa_collection $self->tag->substr(0, 1) eq "_"
Truth table20%1/5
not(A || B) or C
A= $self->isa_elementB= $self->isa_collectionC= $self->tag->substr(0, 1) eq "_"
ABCresult
00X1
1X11
0111
1X00
0100
1488 4 my( $name, $more ) = @_;
1489 4 ▶ return( $self->error( "No css property was provided." ) ) if( !defined( $name ) || !CORE::length( $name ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and CORE::length $name 0 4 4
Condition33%1/3
defined $name and CORE::length $name
!ll&&!rl&&r
004
MC/DC0%0/2
defined $name and CORE::length $name
defined $name CORE::length $name
Truth table33%1/3
A and B
A= defined $nameB= CORE::length $name
ABresult
0X0
100
111
1490  
1491 4 my $process;
1492 $process = sub
1493 {
1494 26 ▶ my $elem = shift( @_ );
Subroutine __ANON__: called CC=34 SCAR=60.6
1495 26 my $style = $elem->attributes->get( 'style' );
1496 # return if( !defined( $style ) );
1497 26 my $css = CSS::Object->new( format => 'CSS::Object::Format::Inline', debug => $self->debug );
1498 26 my $cached;
1499 26 ▶ $cached = $elem->css_cache_check( $style ) if( defined( $style ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $style 12 14 26
1500 26 ▶ if( $cached )
Branch: 2 branches
BranchTrueFalseTotal
if ($cached) { } 12 14 26
elsif (defined $style) { } 0 14 14
1501 {
1502 12 $css = $cached;
1503 }
1504 elsif( defined( $style ) )
1505 {
1506 # 'inline' here is just a fake selector to serve as a container rule for the inline properties,
1507 # because CSS::Object requires properties to be within a rule
1508 0 ▶ $css->read_string( 'inline {' . $style . ' }' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$css->read_string('inline {' . $style . ' }') or return $self->error("Unable to parse existing style for tag name \"", $elem->prop("tagName"), "\":", $css->error) 0 0 0
1509 return( $self->error( "Unable to parse existing style for tag name \"", $elem->prop( 'tagName' ), "\":", $css->error ) );
1510 }
1511 else
1512 {
1513 }
1514 26 my $main = $css->rules->first;
1515 # my $rule = defined( $main ) ? $css->builder->select( $main ) : $css->builder->select( 'inline' );
1516 26 my $rule;
1517  
1518 # Get the requested property values
1519 # $e->css( $property_name );
1520 # $e->css( [$property_name1, $property_name2, $property_name3] );
1521 # $e->css({ $property_name1 => $value1, $property_name2 => $value2 });
1522 26 ▶ if( $self->_is_array( $name ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($name) or $self->_is_hash($name) or !ref($name) || overload::Method($name, '""') and CORE::not defined $more) { } 0 26 26
Condition33%4/12
$self->_is_array($name) or $self->_is_hash($name) or !ref($name) || overload::Method($name, "\"\"") and CORE::not defined $more
l!l&&r!l&&!r
0026
$self->_is_array($name) or $self->_is_hash($name)
l!l&&r!l&&!r
0026
!ref($name) || overload::Method($name, "\"\"") and CORE::not defined $more
!ll&&!rl&&r
0260
CORE::not ref $name or overload::Method($name, "\"\"")
l!l&&r!l&&!r
2600
MC/DC0%0/5
$self->_is_array($name) or $self->_is_hash($name) or !ref($name) || overload::Method($name, "\"\"") and CORE::not defined $more
$self->_is_array($name) $self->_is_hash($name) CORE::not ref $name overload::Method($name, "\"\"") CORE::not defined $more
Truth table14%1/7
A or B or not(C) or D and not(E)
A= $self->_is_array($name)B= $self->_is_hash($name)C= CORE::not ref $nameD= overload::Method($name, "\"\"")E= CORE::not defined $more
ABCDEresult
1XXXX1
01XXX1
001X11
000111
0000X0
001X00
000100
1523 $self->_is_hash( $name ) ||
1524 ( ( !ref( $name ) || overload::Method( $name, '""' ) ) && !defined( $more ) ) )
1525 {
1526 # If this is just 1 css property, we encapsulate it into an array to standardise our processing
1527 # $e->css( $property_name );
1528 0 ▶ $name = [ "$name" ] if( !defined( $more ) && ( !ref( $name ) || overload::Method( $name, '""' ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if CORE::not defined $more and !ref($name) || overload::Method($name, "\"\"") 0 0 0
Condition0%0/6
CORE::not defined $more and !ref($name) || overload::Method($name, "\"\"")
!ll&&!rl&&r
000
CORE::not ref $name or overload::Method($name, "\"\"")
l!l&&r!l&&!r
000
MC/DC0%0/3
CORE::not defined $more and !ref($name) || overload::Method($name, "\"\"")
CORE::not defined $more CORE::not ref $name overload::Method($name, "\"\"")
Truth table0%0/4
not(A) and not(B) or C
A= CORE::not defined $moreB= CORE::not ref $nameC= overload::Method($name, "\"\"")
ABCresult
0XX0
1000
11X1
1011
1529 # $e->css( [$property_name1, $property_name2, $property_name3] );
1530 # "assing an array of style properties to .css() will result in an object of property-value pairs."
1531 # <https://api.jquery.com/css/#css-propertyName>
1532 0 ▶ if( $self->_is_array( $name ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_array($name)) { } 0 0 0
elsif ($self->_is_hash($name)) { } 0 0 0
1533 {
1534 0 my $res = $self->new_hash;
1535 $self->new_array( $name )->foreach(sub
1536 {
1537 0 ▶ my $prop = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
1538 0 $prop =~ tr/_/-/;
1539 0 my $obj = $main->get_property_by_name( $prop );
1540 # next
1541 0 ▶ return(1) if( !defined( $obj ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj 0 0 0
1542 0 $res->{ $prop } = $obj->value->as_string;
1543 0 return(1);
1544 0 });
1545 0 return( $res );
1546 }
1547 # $e->css({ $property_name1 => $value1, $property_name2 => $value2 });
1548 elsif( $self->_is_hash( $name ) )
1549 {
1550 0 ▶ $rule = defined( $main ) ? $css->builder->select( $main ) : $css->builder->select( 'inline' );
Branch: 1 branch
BranchTrueFalseTotal
defined $main ? : 0 0 0
1551 $self->new_hash( $name )->each(sub
1552 {
1553 0 ▶ my( $prop, $value ) = @_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
1554 0 my $obj = $main->get_property_by_name( $prop );
1555 # if the value is undef, remove the property from the set of css properties
1556 # "Setting the value of a style property to an empty string - e.g. $( "#mydiv" ).css( "color", "" ) - removes that property from an element if it has already been directly applied,"
1557 # <https://api.jquery.com/css/#css-propertyName-value>
1558 0 ▶ if( !defined( $value ) || !CORE::length( $value ) )
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not defined $value && CORE::length $value) { } 0 0 0
elsif (defined $obj) { } 0 0 0
Condition0%0/3
defined $value && CORE::length $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value && CORE::length $value
defined $value CORE::length $value
Truth table0%0/3
A && B
A= defined $valueB= CORE::length $value
ABresult
0X0
100
111
1559 {
1560 0 ▶ $main->element->remove( $obj ) if( $obj );
Branch: 1 branch
BranchTrueFalseTotal
if $obj 0 0 0
1561 }
1562 elsif( defined( $obj ) )
1563 {
1564 0 $obj->value( "$value" );
1565 }
1566 else
1567 {
1568 0 $main->$prop( "$value" );
1569 }
1570 0 });
1571 0 ▶ if( $rule->elements->length > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($rule->elements->length > 0) { } 0 0 0
1572 {
1573 0 my $style = $rule->as_string;
1574 0 ▶ $elem->css_cache_store( $style, $css ) || return( $self->pass_error( $elem->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$elem->css_cache_store($style, $css) or return $self->pass_error($elem->error) 0 0 0
1575 0 $elem->attributes->set( style => $style );
1576 }
1577 else
1578 {
1579 }
1580 0 return( $self );
1581 }
1582 else
1583 {
1584 0 return( $self->error( "I was expecting a css property, or an array reference of css property, but instead I received '$name'." ) );
1585 }
1586 }
1587 else
1588 {
1589 # Set css property values
1590 # $e->css( $property_name, $value );
1591 # $e->css( $property_name, $code_reference );
1592 26 ▶ if( defined( $more ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $more) 26 0 26
1593 {
1594 26 ▶ return( $self->error( "More than 2 arguments were provided. I was expecting a property and its value or a function." ) ) if( scalar( @_ ) > 2 );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 2 0 26 26
1595 26 ▶ $rule = defined( $main ) ? $css->builder->select( $main ) : $css->builder->select( 'inline' );
Branch: 1 branch
BranchTrueFalseTotal
defined $main ? : 12 14 26
1596 # $e->css( $property_name, $code_reference );
1597 26 ▶ if( ref( $more ) CORE::eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $more eq 'CODE') { } 0 26 26
1598 {
1599 0 ▶ my $pos = $elem->parent ? $elem->parent->children->pos( $elem ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$elem->parent ? : 0 0 0
1600 0 $name =~ tr/_/-/;
1601 0 my $obj = $main->get_property_by_name( $name );
1602 0 my $val;
1603 0 ▶ if( defined( $obj ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj) 0 0 0
1604 {
1605 0 $val = $obj->value->as_string;
1606 }
1607 0 local $_ = $elem;
1608 0 my $ret = $more->( $pos, $val );
1609 # "If nothing is returned in the setter function (ie. function( index, style ){} ), or if undefined is returned, the current value is not changed. This is useful for selectively setting values only when certain criteria are met."
1610 # <https://api.jquery.com/css/#css-propertyName-function>
1611 0 ▶ return( $elem ) if( !defined( $ret ) || !CORE::length( $ret ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ret and CORE::length $ret 0 0 0
Condition0%0/3
defined $ret and CORE::length $ret
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ret and CORE::length $ret
defined $ret CORE::length $ret
Truth table0%0/3
A and B
A= defined $retB= CORE::length $ret
ABresult
0X0
100
111
1612 0 ▶ if( defined( $obj ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj) { } 0 0 0
1613 {
1614 0 $obj->value( "$val" );
1615 }
1616 else
1617 {
1618 0 $rule->$name( "$val" );
1619 }
1620 }
1621 # $e->css( $property_name, $value );
1622 else
1623 {
1624 26 ▶ return( $self->error( "I was expecting a value as a string, but instead got '$more'." ) ) if( ref( $more ) && !( overload::Overloaded( $more ) && overload::Method( $more, '""' ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $more and CORE::not overload::Overloaded($more) && overload::Method($more, "\"\"") 0 26 26
Condition16%1/6
ref $more and CORE::not overload::Overloaded($more) && overload::Method($more, "\"\"")
!ll&&!rl&&r
2600
overload::Overloaded($more) && overload::Method($more, '""')
!ll&&!rl&&r
000
MC/DC0%0/3
ref $more and CORE::not overload::Overloaded($more) && overload::Method($more, "\"\"")
ref $more overload::Overloaded($more) overload::Method($more, '""')
Truth table25%1/4
A and not(B && C)
A= ref $moreB= overload::Overloaded($more)C= overload::Method($more, '""')
ABCresult
0XX0
1110
10X1
1101
1625 26 $name =~ tr/_/-/;
1626 26 my $obj = $rule->get_property_by_name( $name );
1627 26 ▶ if( defined( $obj ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj) { } 0 26 26
1628 {
1629 0 $obj->value( "$more" );
1630 }
1631 else
1632 {
1633 26 $rule->$name( "$more" );
1634 }
1635 }
1636 }
1637  
1638 26 ▶ if( defined( $rule ) && $rule->elements->length > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rule and $rule->elements->length > 0) { } 26 0 26
Condition33%1/3
defined $rule and $rule->elements->length > 0
!ll&&!rl&&r
0026
MC/DC0%0/2
defined $rule and $rule->elements->length > 0
defined $rule $rule->elements->length > 0
Truth table33%1/3
A and B
A= defined $ruleB= $rule->elements->length > 0
ABresult
0X0
100
111
1639 {
1640 26 my $style = $rule->as_string;
1641 26 ▶ $elem->css_cache_store( $style, $css ) || return( $self->pass_error( $elem->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$elem->css_cache_store($style, $css) or return $self->pass_error($elem->error) 0 26 26
1642 26 $elem->attributes->set( style => $style );
1643 }
1644 else
1645 {
1646 }
1647 26 return( $elem );
1648 }
1649 4 };
1650  
1651 4 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 4 0 4
1652 {
1653 $self->children->foreach(sub
1654 {
1655 26 ▶ $_->reset(1);
Subroutine __ANON__: called CC=1 SCAR=0.0
1656 26 $process->( $_ );
1657 4 });
1658 4 return( $self );
1659 }
1660 else
1661 {
1662 0 $self->reset(1);
1663 0 return( $process->( $self ) );
1664 }
1665 }
1666  
1667 sub css_cache_check
1668 {
1669 12 ▶ my $self = shift( @_ );
Subroutine css_cache_check: called CC=5 SCAR=17.5
Pod undocumented
1670 # my $data = shift( @_ );
1671 # return if( !defined( $data ) );
1672 12 ▶ return( $self->error( "css_cache_check() must be called on an HTML element, not a collection." ) ) if( $self->isa_collection );
Branch: 1 branch
BranchTrueFalseTotal
if $self->isa_collection 0 12 12
1673 12 my $internal = $self->internal;
1674 12 ▶ $internal->{css_cache} //= {};
Condition50%1/2
$internal->{"css_cache"} //= {}
l!l
012
MC/DC0%0/1
$internal->{"css_cache"} //= {}
$internal->{"css_cache"}
Truth table50%1/2
A
A= $internal->{"css_cache"}
Aresult
11
00
1675 12 ▶ if( exists( $internal->{css_cache} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $internal->{"css_cache"}) 12 0 12
1676 {
1677 my $css = $internal->{css_cache}->{object} ||
1678 12 ▶ return( $self->error( "CSS object could not be found in cache!" ) );
Condition50%1/2
$internal->{'css_cache'}{'object'} || (return $self->error('CSS object could not be found in cache!'))
l!l
120
MC/DC0%0/1
$internal->{'css_cache'}{'object'} || (return $self->error('CSS object could not be found in cache!'))
$internal->{'css_cache'}{'object'}
Truth table50%1/2
A
A= $internal->{'css_cache'}{'object'}
Aresult
11
00
1679 # return( $css->clone );
1680 # my $clone = $css->clone;
1681 # return( $clone );
1682 12 return( $css );
1683 }
1684 0 return( '' );
1685 }
1686  
1687 sub css_cache_store
1688 {
1689 26 ▶ my $self = shift( @_ );
Subroutine css_cache_store: called CC=4 SCAR=14.1
Pod undocumented
1690 26 my $data = shift( @_ );
1691 26 ▶ return if( !defined( $data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 26 26
1692 26 ▶ return( $self->error( "css_cache_store() must be called on an HTML element, not a collection." ) ) if( $self->isa_collection );
Branch: 1 branch
BranchTrueFalseTotal
if $self->isa_collection 0 26 26
1693 26 my $css = shift( @_ );
1694 26 ▶ return( $self->error( "No css object provided to store in the element cache." ) ) if( !$self->_is_object( $css ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($css) 0 26 26
1695 26 my $trace = $self->_get_stack_trace;
1696 26 my $internal = $self->internal;
1697 $internal->{css_cache} =
1698 {
1699 26 timestamp => time(),
1700 # object => $css->clone,
1701 object => $css,
1702 };
1703 26 return( $self );
1704 }
1705  
1706 # sub data { return( shift->attr( join( '-', 'data', shift( @_ ) ) => shift( @_ ) ) ) }
1707 # nothing which returns everything as a hash; or
1708 # a key-value pair; or
1709 # a hash reference
1710 sub data
1711 {
1712 17 ▶ my $self = shift( @_ );
Subroutine data: called CC=17 SCAR=32.9
Pod documented
1713 17 my( $this, $val ) = @_;
1714 17 my $elem;
1715 17 ▶ if( $self->isa_collection )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->isa_collection) { } 17 0 17
elsif (CORE::not $self->_is_a($self, 'HTML::Object::DOM::Element')) { } 0 0 0
1716 {
1717 17 $elem = $self->children->first;
1718 }
1719 # elsif( $self->tag->substr( 0, 1 ) eq '_' )
1720 elsif( !$self->_is_a( $self => 'HTML::Object::DOM::Element' ) )
1721 {
1722 0 return( $self->error( "You can only call the data method on HTML elements." ) );
1723 }
1724 else
1725 {
1726 0 $elem = $self;
1727 }
1728  
1729 17 ▶ if( $self->_is_hash( $this ) )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_is_hash($this)) { } 1 16 17
elsif (defined $this and scalar @_ > 1) { } 5 11 16
elsif (defined $this and scalar @_ == 1) { } 10 1 11
1730 {
1731 1 my $changed = 0;
1732 $this = $self->new_hash( $this )->each(sub
1733 {
1734 1 ▶ my( $k, $v ) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.4
1735 # Remove leading and trailing spaces if this is not a reference
1736 1 ▶ $v =~ s/^[[:blank:]\h]+|[[:blank:]\h]+$//g if( !ref( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v 0 1 1
1737 # $attr->set( 'data-' . $k, $v );
1738 1 ▶ if( $elem->setAttribute( 'data-' . $k, $v ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->setAttribute('data-' . $k, $v)) 1 0 1
1739 {
1740 1 $changed++;
1741 }
1742 1 });
1743 1 ▶ $elem->reset(1) if( $changed );
Branch: 1 branch
BranchTrueFalseTotal
if $changed 1 0 1
1744 1 return( $elem );
1745 }
1746 ▶ elsif( defined( $this ) && scalar( @_ ) > 1 )
Condition100%3/3
defined $this and scalar @_ > 1
!ll&&!rl&&r
1105
MC/DC100%2/2
defined $this and scalar @_ > 1
defined $this scalar @_ > 1
Truth table100%3/3
A and B
A= defined $thisB= scalar @_ > 1
ABresult
0X0
100
111
1747 {
1748 # From jQuery documentation: "undefined is not recognized as a data value. Calls such as .data( "name", undefined ) will return the jQuery object that it was called on, allowing for chaining."
1749 5 ▶ return( $self ) if( !defined( $val ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 5 5
1750 5 ▶ return( $self->error( "I was provided data name '$this', but I was expcting a regular string." ) ) if( ref( $this ) && ( !overload::Overloaded( $this ) || ( overload::Overloaded( $this ) && !overload::Method( $this, '""' ) ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $this and !overload::Overloaded($this) || overload::Overloaded($this) && !overload::Method($this, "\"\"") 0 5 5
Condition11%1/9
ref $this and !overload::Overloaded($this) || overload::Overloaded($this) && !overload::Method($this, "\"\"")
!ll&&!rl&&r
500
CORE::not overload::Overloaded($this) or overload::Overloaded($this) and CORE::not overload::Method($this, "\"\"")
l!l&&r!l&&!r
000
overload::Overloaded($this) and CORE::not overload::Method($this, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/4
ref $this and !overload::Overloaded($this) || overload::Overloaded($this) && !overload::Method($this, "\"\"")
ref $this CORE::not overload::Overloaded($this) overload::Overloaded($this) CORE::not overload::Method($this, "\"\"")
Truth table20%1/5
A and not(B) or C and not(D)
A= ref $thisB= CORE::not overload::Overloaded($this)C= overload::Overloaded($this)D= CORE::not overload::Method($this, "\"\"")
ABCDresult
0XXX0
100X0
10100
11XX1
10111
1751 # $attr->set( 'data-' . $this => $val );
1752 5 ▶ if( $elem->setAttribute( 'data-' . $this => $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->setAttribute('data-' . $this, $val)) 5 0 5
1753 {
1754 5 $elem->reset(1);
1755 }
1756 5 return( $elem );
1757 }
1758 ▶ elsif( defined( $this ) && scalar( @_ ) == 1 )
Condition66%2/3
defined $this and scalar @_ == 1
!ll&&!rl&&r
1010
MC/DC50%1/2
defined $this and scalar @_ == 1
defined $this scalar @_ == 1
Truth table66%2/3
A and B
A= defined $thisB= scalar @_ == 1
ABresult
0X0
100
111
1759 {
1760 # return( $attr->get( $this ) );
1761 10 return( $elem->getAttribute( 'data-' . $this ) );
1762 }
1763 else
1764 {
1765 1 ▶ $self->_load_class( 'Module::Generic::Dynamic' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Dynamic") or return $self->pass_error 0 1 1
1766 1 my $ref = {};
1767 1 my $attr = $elem->attributes;
1768 $attr->each(sub
1769 {
1770 3 ▶ my( $k, $v ) = @_;
Subroutine __ANON__: called CC=3 SCAR=12.5
1771 3 ▶ if( substr( $k, 0, 5 ) CORE::eq 'data-' && CORE::length( $k ) > 5 )
Branch: 1 branch
BranchTrueFalseTotal
if (substr($k, 0, 5) eq "data-" and CORE::length $k > 5) 3 0 3
Condition33%1/3
substr($k, 0, 5) eq "data-" and CORE::length $k > 5
!ll&&!rl&&r
003
MC/DC0%0/2
substr($k, 0, 5) eq "data-" and CORE::length $k > 5
substr($k, 0, 5) eq "data-" CORE::length $k > 5
Truth table33%1/3
A and B
A= substr($k, 0, 5) eq "data-"B= CORE::length $k > 5
ABresult
0X0
100
111
1772 {
1773 3 $ref->{ substr( $k, 5 ) } = $v;
1774 }
1775 1 });
1776 1 ▶ my $obj = Module::Generic::Dynamic->new( $ref ) ||
Condition50%1/2
'Module::Generic::Dynamic'->new($ref) || (return $self->pass_error('Module::Generic::Dynamic'->error))
l!l
10
MC/DC0%0/1
'Module::Generic::Dynamic'->new($ref) || (return $self->pass_error('Module::Generic::Dynamic'->error))
'Module::Generic::Dynamic'->new($ref)
Truth table50%1/2
A
A= 'Module::Generic::Dynamic'->new($ref)
Aresult
11
00
1777 return( $self->pass_error( Module::Generic::Dynamic->error ) );
1778 1 return( $obj );
1779 }
1780 }
1781  
1782 sub debug
1783 {
1784 460 ▶ my $self = shift( @_ );
Subroutine debug: called CC=3 SCAR=11.0
Pod documented
1785 460 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 94 366 460
1786 {
1787 94 my $val = $self->SUPER::debug( @_ );
1788 94 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) 26 68 94
1789 {
1790 $self->children->foreach(sub
1791 {
1792 64 ▶ $_->debug( $val );
Subroutine __ANON__: called CC=1 SCAR=0.0
1793 26 });
1794 }
1795 94 return( $val );
1796 }
1797 366 return( $self->SUPER::debug );
1798 }
1799  
1800 0 ▶sub dequeue { return( $_[0] ) }
Subroutine dequeue: not called CC=1 SCAR=6.9
Pod undocumented
1801  
1802 # TODO: Instead of adding this method, maybe we should change the one in HTML::Object::DOM::Element to have it return $self instead of $parent, because otherwise there is no difference
1803 sub detach
1804 {
1805 8 ▶ my $self = shift( @_ );
Subroutine detach: called CC=4 SCAR=17.9
Pod documented
1806 # If this is a collection, walk through its children
1807 8 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 8 8
1808 {
1809 $self->children->foreach(sub
1810 {
1811 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
1812 0 my $parent = $e->parent;
1813 0 ▶ return(1) if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
1814 0 my $pos = $parent->children->pos( $e );
1815 0 $parent->children->splice( $pos, 1 );
1816 0 $e->parent( undef() );
1817 0 $parent->reset(1);
1818 0 });
1819 }
1820 # otherwise, process this one element individually
1821 else
1822 {
1823 8 my $parent = $self->parent;
1824 8 ▶ return( $self ) if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 8 8
1825 8 my $pos = $parent->children->pos( $self );
1826 8 ▶ if( defined( $pos ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) 8 0 8
1827 {
1828 8 $parent->children->splice( $pos, 1 );
1829 8 $self->parent( undef() );
1830 8 $parent->reset(1);
1831 }
1832 }
1833 8 return( $self );
1834 }
1835  
1836 # Takes a code reference which receives the element position and element object as parameter
1837 # It returns the current object it was called with
1838 sub each
1839 {
1840 0 ▶ my( $self, $code ) = @_;
Subroutine each: not called CC=2 SCAR=17.9
Pod undocumented
1841 0 ▶ return( $self->error( "I was expecting a code reference to pass it the element position and element object, but instead I got \"", overload::StrVal( $code ), "\"." ) ) if( ref( $code ) ne 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $code ne "CODE" 0 0 0
1842 # Make a copy of the array so that call to code ref that may remove a child element does not alter our looping operation through all the children
1843 $self->children->clone->for(sub
1844 {
1845 0 ▶ my( $i, $e ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1846 0 $code->( $i, $e );
1847 0 });
1848 0 return( $self );
1849 }
1850  
1851 sub empty
1852 {
1853 0 ▶ my $self = shift( @_ );
Subroutine empty: not called CC=1 SCAR=6.9
Pod undocumented
1854 # Element object of Collection object, it does not matter
1855 0 $self->children->reset;
1856 0 $self->reset(1);
1857 0 return( $self );
1858 }
1859  
1860 sub end { return( shift->_set_get_object({
1861 0 ▶ field => 'end',
Subroutine end: not called CC=1 SCAR=6.9
Pod documented
1862 weaken => 1,
1863 }, 'HTML::Object::DOM::Element', @_ ) ); }
1864  
1865 0 ▶sub eq { return( shift->children->index( shift( @_ ) ) ); }
Subroutine eq: not called CC=1 SCAR=6.9
Pod undocumented
1866  
1867 # Returns a new collection of elements whose position is an even number
1868 sub even
1869 {
1870 0 ▶ my $self = shift( @_ );
Subroutine even: not called CC=2 SCAR=17.9
Pod undocumented
1871 0 ▶ return( $self ) unless( $self->isa_collection );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isa_collection 0 0 0
1872 0 my $even = $self->children->even;
1873 0 my $collection = $self->new_collection;
1874 0 $collection->children( $even );
1875 0 return( $collection );
1876 }
1877  
1878 sub exists
1879 {
1880 0 ▶ my( $self, $path ) = @_;
Subroutine exists: not called CC=1 SCAR=6.9
Pod undocumented
1881 0 return( $self->xp->exists( $path, $self ) );
1882 }
1883  
1884 # Takes a selector; or
1885 # function with arguments are element position (starting from 0) and the element itself, expecting a true value in return; or
1886 # an array of element objects; or
1887 # an element object;
1888 sub filter
1889 {
1890 2 ▶ my $self = shift( @_ );
Subroutine filter: called CC=23 SCAR=51.5
Pod documented
1891 2 my $this = shift( @_ );
1892 2 my $collection = $self->new_collection( end => $self );
1893 2 ▶ return( $collection ) if( !defined( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this 0 2 2
1894 2 ▶ if( !ref( $this ) ||
Branch: 3 branches
BranchTrueFalseTotal
if (CORE::not ref $this or ref $this and overload::Overloaded($this) and overload::Method($this, '""')) { } 1 1 2
elsif (ref $this eq 'CODE') { } 1 0 1
elsif ($self->_is_array($this) or $self->_is_object($this)) { } 0 0 0
Condition44%4/9
CORE::not ref $this or ref $this and overload::Overloaded($this) and overload::Method($this, "\"\"")
l!l&&r!l&&!r
101
ref $this and overload::Overloaded($this) and overload::Method($this, "\"\"")
!ll&&!rl&&r
100
ref $this and overload::Overloaded($this)
!ll&&!rl&&r
010
MC/DC25%1/4
CORE::not ref $this or ref $this and overload::Overloaded($this) and overload::Method($this, "\"\"")
CORE::not ref $this ref $this overload::Overloaded($this) overload::Method($this, "\"\"")
Truth table40%2/5
not(A) or B and C and D
A= CORE::not ref $thisB= ref $thisC= overload::Overloaded($this)D= overload::Method($this, "\"\"")
ABCDresult
1XXX1
01111
00XX0
010X0
01100
1895 ( ref( $this ) &&
1896 overload::Overloaded( $this ) &&
1897 overload::Method( $this, '""' )
1898 ) )
1899 {
1900 1 ▶ my $xpath = $self->_xpath_value( "$this" ) || return;
Condition50%1/2
$self->_xpath_value("$this") || (return)
l!l
10
MC/DC0%0/1
$self->_xpath_value("$this") || (return)
$self->_xpath_value("$this")
Truth table50%1/2
A
A= $self->_xpath_value("$this")
Aresult
11
00
1901 1 ▶ if( $self->isa_collection )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->isa_collection) { } 1 0 1
elsif ($self->tag->substr(0, 1) ne '_' and $self->matches($xpath)) { } 0 0 0
1902 {
1903 $self->children->foreach(sub
1904 {
1905 # $_->debug( $self->debug );
1906 7 ▶ if( $_->tag->substr( 0, 1 ) ne '_' &&
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
if ($_->tag->substr(0, 1) ne '_' and $_->matches($xpath)) { } 4 3 7
Condition66%2/3
$_->tag->substr(0, 1) ne "_" and $_->matches($xpath)
!ll&&!rl&&r
304
MC/DC0%0/2
$_->tag->substr(0, 1) ne "_" and $_->matches($xpath)
$_->tag->substr(0, 1) ne "_" $_->matches($xpath)
Truth table33%1/3
A and B
A= $_->tag->substr(0, 1) ne "_"B= $_->matches($xpath)
ABresult
0X0
100
111
1907 $_->matches( $xpath ) )
1908 {
1909 4 $collection->children->push( $_ );
1910 }
1911 else
1912 {
1913 # No match
1914 }
1915 1 });
1916 }
1917 ▶ elsif( $self->tag->substr( 0, 1 ) ne '_' && $self->matches( $xpath ) )
Condition0%0/3
$self->tag->substr(0, 1) ne "_" and $self->matches($xpath)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->tag->substr(0, 1) ne "_" and $self->matches($xpath)
$self->tag->substr(0, 1) ne "_" $self->matches($xpath)
Truth table0%0/3
A and B
A= $self->tag->substr(0, 1) ne "_"B= $self->matches($xpath)
ABresult
0X0
100
111
1918 {
1919 0 $collection->children->push( $self );
1920 }
1921 }
1922 elsif( ref( $this ) eq 'CODE' )
1923 {
1924 1 ▶ if( $self->isa_collection )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->isa_collection) { } 1 0 1
elsif ($self->isa('HTML::Object::DOM::Element')) { } 0 0 0
1925 {
1926 $self->children->for(sub
1927 {
1928 7 ▶ my( $i, $e ) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
1929 7 local $_ = $e;
1930 7 ▶ if( $this->( $i, $e ) )
Branch: 1 branch
BranchTrueFalseTotal
if (&$this($i, $e)) 3 4 7
1931 {
1932 3 $collection->children->push( $e );
1933 }
1934 1 });
1935 }
1936 elsif( $self->isa( 'HTML::Object::DOM::Element' ) )
1937 {
1938 0 ▶ return( $collection ) if( $self->tag->substr( 0, 1 ) eq '_' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->tag->substr(0, 1) eq "_" 0 0 0
1939 0 local $_ = $self;
1940 0 ▶ $collection->children->push( $self ) if( $this->( 0, $self ) );
Branch: 1 branch
BranchTrueFalseTotal
if &$this(0, $self) 0 0 0
1941 }
1942 }
1943 ▶ elsif( $self->_is_array( $this ) || $self->_is_object( $this ) )
Condition0%0/3
$self->_is_array($this) or $self->_is_object($this)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_is_array($this) or $self->_is_object($this)
$self->_is_array($this) $self->_is_object($this)
Truth table0%0/3
A or B
A= $self->_is_array($this)B= $self->_is_object($this)
ABresult
1X1
011
000
1944 {
1945 0 ▶ if( $self->_is_object( $this ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_object($this) and !$this->isa("HTML::Object::DOM::Element") || $this->isa("HTML::Object::Element") && $this->tag->substr(0, 1) eq "_" && !$this->isa("HTML::Object::Collection")) 0 0 0
Condition0%0/12
$self->_is_object($this) and !$this->isa("HTML::Object::DOM::Element") || $this->isa("HTML::Object::Element") && $this->tag->substr(0, 1) eq "_" && !$this->isa("HTML::Object::Collection")
!ll&&!rl&&r
000
CORE::not $this->isa("HTML::Object::DOM::Element") or $this->isa("HTML::Object::Element") and $this->tag->substr(0, 1) eq "_" and CORE::not $this->isa("HTML::Object::Collection")
l!l&&r!l&&!r
000
$this->isa("HTML::Object::Element") and $this->tag->substr(0, 1) eq "_" and CORE::not $this->isa("HTML::Object::Collection")
!ll&&!rl&&r
000
$this->isa("HTML::Object::Element") and $this->tag->substr(0, 1) eq "_"
!ll&&!rl&&r
000
MC/DC0%0/5
$self->_is_object($this) and !$this->isa("HTML::Object::DOM::Element") || $this->isa("HTML::Object::Element") && $this->tag->substr(0, 1) eq "_" && !$this->isa("HTML::Object::Collection")
$self->_is_object($this) CORE::not $this->isa("HTML::Object::DOM::Element") $this->isa("HTML::Object::Element") $this->tag->substr(0, 1) eq "_" CORE::not $this->isa("HTML::Object::Collection")
Truth table0%0/6
A and not(B) or C and D and not(E)
A= $self->_is_object($this)B= CORE::not $this->isa("HTML::Object::DOM::Element")C= $this->isa("HTML::Object::Element")D= $this->tag->substr(0, 1) eq "_"E= CORE::not $this->isa("HTML::Object::Collection")
ABCDEresult
0XXXX0
100XX0
1010X0
101100
11XXX1
101111
1946 ( !$this->isa( 'HTML::Object::DOM::Element' ) ||
1947 (
1948 # Probably need to change this to HTML::Object::DOM::Node
1949 $this->isa( 'HTML::Object::Element' ) &&
1950 $this->tag->substr( 0, 1 ) eq '_' &&
1951 !$this->isa( 'HTML::Object::Collection' )
1952 )
1953 ) )
1954 {
1955 0 return( $self->error( "Object of class \"", ref( $this ), "\", but you can only provide an HTML::Object::DOM::Element or an HTML::Object::Collection object." ) );
1956 }
1957 0 ▶ my $a = $self->new_array( $self->_is_array( $this ) ? $this : [ $this ] );
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($this) ? : 0 0 0
1958 $a->foreach(sub
1959 {
1960 0 ▶ my $xpath = $_->getNodePath();
Subroutine __ANON__: not called CC=3 SCAR=24.8
1961 0 ▶ if( $self->isa_collection )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
elsif ($self->matches($xpath)) { } 0 0 0
1962 {
1963 $self->children->foreach(sub
1964 {
1965 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
1966 0 ▶ if( $e->matches( $xpath ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->matches($xpath)) 0 0 0
1967 {
1968 0 $collection->children->push( $e );
1969 }
1970 0 });
1971 }
1972 elsif( $self->matches( $xpath ) )
1973 {
1974 0 $collection->children->push( $self );
1975 }
1976 0 });
1977 }
1978 else
1979 {
1980 0 return( $self->error( "I was expecting a selector, a code reference, an array of elements or an element to use in filter(), but instead I got '$this', and I do not know what to do with it." ) );
1981 }
1982 2 return( $collection );
1983 }
1984  
1985 # Takes a selector; or
1986 # Element object
1987 sub find
1988 {
1989 24 ▶ my( $self, $this ) = @_;
Subroutine find: called CC=15 SCAR=43.2
Pod documented
1990 24 my $collection = $self->new_collection;
1991 24 ▶ return( $collection ) if( !defined( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this 0 24 24
1992  
1993 24 ▶ if( ref( $this ) && $self->_is_object( $this ) && $this->isa( 'HTML::Object::DOM::Element' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this and $self->_is_object($this) and $this->isa('HTML::Object::DOM::Element')) { } 0 24 24
Condition33%2/6
ref $this and $self->_is_object($this) and $this->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
2400
ref $this and $self->_is_object($this)
!ll&&!rl&&r
2400
MC/DC0%0/3
ref $this and $self->_is_object($this) and $this->isa("HTML::Object::DOM::Element")
ref $this $self->_is_object($this) $this->isa("HTML::Object::DOM::Element")
Truth table25%1/4
A and B and C
A= ref $thisB= $self->_is_object($this)C= $this->isa("HTML::Object::DOM::Element")
ABCresult
0XX0
10X0
1100
1111
1994 {
1995 0 ▶ my $a = $self->new_array( $self->isa_collection( $this ) ? $this->children : [ $this ] );
Branch: 1 branch
BranchTrueFalseTotal
$self->isa_collection($this) ? : 0 0 0
1996 0 my $lookup;
1997 $lookup = sub
1998 {
1999 0 ▶ my $kids = shift( @_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
2000 $kids->foreach(sub
2001 {
2002 0 ▶ my $child = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
2003 $a->foreach(sub
2004 {
2005 0 ▶ my $candidate = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
2006 0 ▶ if( $child->eid eq $candidate->eid )
Branch: 1 branch
BranchTrueFalseTotal
if ($child->eid eq $candidate->eid) 0 0 0
2007 {
2008 0 $collection->children->push( $child );
2009 # We've added this child. Move to next child.
2010 0 return(1);
2011 }
2012 0 });
2013 0 ▶ if( $child->children->length > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($child->children->length > 0) 0 0 0
2014 {
2015 0 $lookup->( $child->children );
2016 }
2017 0 });
2018 0 };
2019 # Wether this is a collection or just an element object, we check our children
2020 0 $lookup->( $self->children );
2021 }
2022 # I am expecting an xpath value
2023 else
2024 {
2025 24 ▶ if( ref( $this ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this and !overload::Overloaded($this) || overload::Overloaded($this) && !overload::Method($this, "\\\"\\\"")) 0 24 24
Condition11%1/9
ref $this and !overload::Overloaded($this) || overload::Overloaded($this) && !overload::Method($this, "\\\"\\\"")
!ll&&!rl&&r
2400
CORE::not overload::Overloaded($this) or overload::Overloaded($this) and CORE::not overload::Method($this, "\\\"\\\"")
l!l&&r!l&&!r
000
overload::Overloaded($this) and CORE::not overload::Method($this, "\\\"\\\"")
!ll&&!rl&&r
000
MC/DC0%0/4
ref $this and !overload::Overloaded($this) || overload::Overloaded($this) && !overload::Method($this, "\\\"\\\"")
ref $this CORE::not overload::Overloaded($this) overload::Overloaded($this) CORE::not overload::Method($this, "\\\"\\\"")
Truth table20%1/5
A and not(B) or C and not(D)
A= ref $thisB= CORE::not overload::Overloaded($this)C= overload::Overloaded($this)D= CORE::not overload::Method($this, "\\\"\\\"")
ABCDresult
0XXX0
100X0
10100
11XX1
10111
2026 (
2027 !overload::Overloaded( $this ) ||
2028 ( overload::Overloaded( $this ) && !overload::Method( $this, '\"\"' ) )
2029 ) )
2030 {
2031 0 return( $self->error( "I was expecting an xpath string, but instead I got '$this'." ) );
2032 }
2033  
2034 # Fast paths pour les sélecteurs simples - évite le pipeline XPath complet
2035 24 my $str = "$this";
2036  
2037 # Fast path: #id
2038 24 ▶ if( $str =~ /\A#([\w][\w-]*)\z/ )
Branch: 3 branches
BranchTrueFalseTotal
if ($str =~ /\A#([\w][\w-]*)\z/) { } 0 24 24
elsif ($str =~ /\A\.([\w][\w-]*)\z/) { } 10 14 24
elsif ($str =~ /\A([a-zA-Z][a-zA-Z0-9]*)\z/) { } 14 0 14
2039 {
2040 0 my $id = $1;
2041 my $found = $self->_fast_find_by(sub
2042 {
2043 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
2044 0 my $v = $e->attributes->get( 'id' );
2045 0 ▶ return( defined( $v ) && $v eq $id );
Condition0%0/3
defined $v && $v eq $id
!ll&&!rl&&r
000
MC/DC0%0/2
defined $v && $v eq $id
defined $v $v eq $id
Truth table0%0/3
A && B
A= defined $vB= $v eq $id
ABresult
0X0
100
111
2046 0 });
2047 0 $collection->children->push( $found->list );
2048 0 return( $collection );
2049 }
2050 # Fast path: .class (une seule classe, pas de combinaison)
2051 elsif( $str =~ /\A\.([\w][\w-]*)\z/ )
2052 {
2053 10 my $class = $1;
2054 my $found = $self->_fast_find_by(sub
2055 {
2056 85 ▶ my $e = shift( @_ );
Subroutine __ANON__: called CC=2 SCAR=6.9
2057 85 my $v = $e->attributes->get( 'class' );
2058 85 ▶ return( defined( $v ) && $v =~ /(?:\A|[[:blank:]\h]+)\Q${class}\E(?:[[:blank:]\h]+|\Z)/ );
Condition100%3/3
defined $v && $v =~ /(?:\A|[[:blank:]\h]+)\Q$class\E(?:[[:blank:]\h]+|\Z)/
!ll&&!rl&&r
551218
MC/DC100%2/2
defined $v && $v =~ /(?:\A|[[:blank:]\h]+)\Q$class\E(?:[[:blank:]\h]+|\Z)/
defined $v $v =~ /(?:\A|[[:blank:]\h]+)\Q$class\E(?:[[:blank:]\h]+|\Z)/
Truth table100%3/3
A && B
A= defined $vB= $v =~ /(?:\A|[[:blank:]\h]+)\Q$class\E(?:[[:blank:]\h]+|\Z)/
ABresult
0X0
100
111
2059 10 });
2060 10 $collection->children->push( $found->list );
2061 10 return( $collection );
2062 }
2063 # Fast path: tag simple (lettres uniquement, pas de combinaison)
2064 elsif( $str =~ /\A([a-zA-Z][a-zA-Z0-9]*)\z/ )
2065 {
2066 14 my $tag = lc( $1 );
2067 my $found = $self->_fast_find_by(sub
2068 {
2069 131 ▶ my $e = shift( @_ );
Subroutine __ANON__: called CC=1 SCAR=0.0
2070 131 return( lc( "$e->{tag}" ) eq $tag );
2071 14 });
2072 14 $collection->children->push( $found->list );
2073 14 return( $collection );
2074 }
2075  
2076 # Fallback : pipeline XPath complet
2077 0 ▶ my $xpath = $self->_xpath_value( $str ) || return( $self->pass_error );
Condition0%0/2
$self->_xpath_value($str) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_xpath_value($str) || (return $self->pass_error)
$self->_xpath_value($str)
Truth table0%0/2
A
A= $self->_xpath_value($str)
Aresult
11
00
2078 # $self->children->foreach(sub
2079 # {
2080 # my $child = shift( @_ );
2081 # # Propagate debug value
2082 # $child->debug( $self->debug );
2083 # try
2084 # {
2085 # my @nodes = $child->findnodes( $xpath );
2086 # $collection->children->push( @nodes );
2087 # }
2088 # catch( $e )
2089 # {
2090 # warn( "Error while calling findnodes on element id \"", $_->id, "\" and tag \"", $_->tag, "\": $e\n" );
2091 # }
2092 # });
2093 # try-catch
2094 0 local $@;
2095 eval
2096 0 {
2097 0 my @nodes = $self->findnodes( $xpath );
2098 0 $collection->children->push( @nodes );
2099 };
2100 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2101 {
2102 0 warn( "Error while calling findnodes on element id \"", $self->id, "\" and tag \"", $self->tag, "\": $@\n" );
2103 }
2104 }
2105 0 return( $collection );
2106 }
2107  
2108 sub find_xpath
2109 {
2110 0 ▶ my( $self, $path ) = @_;
Subroutine find_xpath: not called CC=1 SCAR=6.9
Pod documented
2111 0 return( $self->xp->find( $path, $self ) );
2112 }
2113  
2114 sub findnodes
2115 {
2116 1 ▶ my( $self, $path ) = @_;
Subroutine findnodes: called CC=1 SCAR=0.0
Pod documented
2117 # xp()->debug( $self->debug );
2118 1 return( $self->xp->findnodes( $path, $self ) );
2119 }
2120  
2121 sub findnodes_as_string
2122 {
2123 0 ▶ my( $self, $path ) = @_;
Subroutine findnodes_as_string: not called CC=1 SCAR=6.9
Pod documented
2124 0 return( $self->xp->findnodes_as_string( $path, $self ) );
2125 }
2126  
2127 sub findnodes_as_strings
2128 {
2129 0 ▶ my( $self, $path ) = @_;
Subroutine findnodes_as_strings: not called CC=1 SCAR=6.9
Pod documented
2130 0 return( $self->xp->findnodes_as_strings( $path, $self ) );
2131 }
2132  
2133 sub findvalue
2134 {
2135 0 ▶ my( $self, $path ) = @_;
Subroutine findvalue: not called CC=1 SCAR=6.9
Pod documented
2136 0 return( $self->xp->findvalue( $path, $self ) );
2137 }
2138  
2139 sub findvalues
2140 {
2141 0 ▶ my( $self, $path ) = @_;
Subroutine findvalues: not called CC=1 SCAR=6.9
Pod documented
2142 0 return( $self->xp->findvalues( $path, $self ) );
2143 }
2144  
2145 sub first
2146 {
2147 0 ▶ my $self = shift( @_ );
Subroutine first: not called CC=2 SCAR=17.9
Pod documented
2148 0 my $collection = $self->new_collection;
2149 0 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
2150 {
2151 0 return( $self->children->first );
2152 }
2153 else
2154 {
2155 0 return( $self );
2156 }
2157 }
2158  
2159 # <https://api.jquery.com/get/>
2160 sub get
2161 {
2162 4 ▶ my $self = shift( @_ );
Subroutine get: called CC=5 SCAR=22.1
Pod documented
2163 4 my $idx = shift( @_ );
2164 4 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 4 0 4
2165 {
2166 4 ▶ if( defined( $idx ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $idx) { } 0 4 4
2167 {
2168 0 ▶ return( $self->error( "Index value provided is not an integer." ) ) if( !$self->_is_integer( $idx ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_integer($idx) 0 0 0
2169 0 return( $self->children->[ $idx ] );
2170 }
2171 else
2172 {
2173 4 my $arr = $self->new_array;
2174 4 $arr->push( $self->children->list );
2175 4 return( $arr );
2176 }
2177 }
2178 else
2179 {
2180 0 ▶ if( defined( $idx ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $idx) { } 0 0 0
2181 {
2182 0 return( $self );
2183 }
2184 else
2185 {
2186 0 return( $self->new_array( $self ) );
2187 }
2188 }
2189 }
2190  
2191 sub getDataJson
2192 {
2193 0 ▶ my $self = shift( @_ );
Subroutine getDataJson: not called CC=11 SCAR=48.8
Pod undocumented
2194 0 ▶ my $dataName = shift( @_ ) ||
Condition0%0/2
shift @_ || (return $self->error('No data name was provided to get its JSON object'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No data name was provided to get its JSON object'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
2195 return( $self->error( "No data name was provided to get its JSON object" ) );
2196 0 my $el;
2197 0 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
2198 {
2199 0 $el = $self->children->first;
2200 0 ▶ return({}) if( !$el );
Branch: 1 branch
BranchTrueFalseTotal
unless $el 0 0 0
2201 }
2202 else
2203 {
2204 0 $el = $self;
2205 }
2206 0 my $json;
2207 0 my $shortName = $dataName;
2208 0 ▶ if( substr( $dataName, 0, 5 ) eq 'data-' )
Branch: 1 branch
BranchTrueFalseTotal
if (substr($dataName, 0, 5) eq "data-") 0 0 0
2209 {
2210 0 $shortName = substr( $dataName, 5, length( $dataName ) );
2211 }
2212 0 my $data = $self->data( $shortName );
2213 0 ▶ return({}) if( !defined( $data ) || !length( $data // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data and CORE::length($data // "") 0 0 0
Condition0%0/5
defined $data and CORE::length($data // "")
!ll&&!rl&&r
000
$data // ""
l!l
00
MC/DC0%0/2
defined $data and CORE::length($data // "")
defined $data $data
Truth table0%0/3
A and B
A= defined $dataB= $data
ABresult
0X0
100
111
2214 0 ▶ if( ref( $data ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data eq 'HASH') { } 0 0 0
2215 {
2216 0 $json = $data;
2217 }
2218 else
2219 {
2220 # Taken from URI::Escape
2221 my $decodeURIComponent = sub
2222 {
2223 0 ▶ my $str = shift( @_ );
Subroutine __ANON__: not called CC=5 SCAR=34.0
2224 0 ▶ if( @_ && wantarray )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and wantarray) 0 0 0
Condition0%0/3
@_ and wantarray
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and wantarray
@_ wantarray
Truth table0%0/3
A and B
A= @_B= wantarray
ABresult
0X0
100
111
2225 {
2226 # not executed for the common case of a single argument
2227 # need to copy
2228 0 my @str = ( $str, @_ );
2229 0 for( @str )
2230 {
2231 0 s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
2232 }
2233 0 return( @str );
2234 }
2235 0 ▶ $str =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg if( defined( $str ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $str 0 0 0
2236 0 return( $str );
2237 0 };
2238 # try-catch
2239 0 local $@;
2240 eval
2241 0 {
2242 0 my $j = $self->new_json;
2243 0 ▶ if( index( $data, '{' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::index($data, '{') != -1) { } 0 0 0
2244 {
2245 0 $json = $j->decode( $data );
2246 }
2247 else
2248 {
2249 0 $json = $j->decode( $decodeURIComponent->( $data ) );
2250 }
2251 };
2252 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2253 {
2254 0 return( $self->error( "An error occurred while trying to decode the json data: $@" ) );
2255 }
2256 # Replace parsed json string by its object representation
2257 0 $self->data( $shortName => $json );
2258 }
2259 0 return( $json );
2260 }
2261  
2262 sub getJSON
2263 {
2264 0 ▶ my $self = shift( @_ );
Subroutine getJSON: not called CC=12 SCAR=50.5
Pod undocumented
2265 0 ▶ my $url = shift( @_ ) || return( $self->error( "No URL was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No URL was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No URL was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
2266 0 my @args = @_;
2267 0 my( $data, $success );
2268 0 ▶ for( my $i = 0; $i < scalar( @args ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @args) 0 0 0
2269 {
2270 0 ▶ if( !defined( $data ) && ref( $args[$i] // '' ) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not defined $data and ref($args[$i] // '') eq 'HASH') { } 0 0 0
elsif (CORE::not defined $success and ref($args[$i] // '') eq 'CODE') { } 0 0 0
Condition0%0/5
CORE::not defined $data and ref($args[$i] // "") eq "HASH"
!ll&&!rl&&r
000
$args[$i] // ""
l!l
00
MC/DC0%0/2
CORE::not defined $data and ref($args[$i] // "") eq "HASH"
CORE::not defined $data $args[$i]
Truth table0%0/3
not(A) and B
A= CORE::not defined $dataB= $args[$i]
ABresult
0X0
100
111
2271 {
2272 0 $data = $args[$i];
2273 }
2274 ▶ elsif( !defined( $success ) && ref( $args[$i] // '' ) eq 'CODE' )
Condition0%0/5
CORE::not defined $success and ref($args[$i] // "") eq "CODE"
!ll&&!rl&&r
000
$args[$i] // ""
l!l
00
MC/DC0%0/2
CORE::not defined $success and ref($args[$i] // "") eq "CODE"
CORE::not defined $success $args[$i]
Truth table0%0/3
not(A) and B
A= CORE::not defined $successB= $args[$i]
ABresult
0X0
100
111
2275 {
2276 0 $success = $args[$i];
2277 }
2278 }
2279  
2280 0 ▶ $self->_load_class( 'Promise::Me' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Promise::Me") or return $self->pass_error 0 0 0
2281 0 ▶ if( lc( substr( "$url", 0, 7 ) ) eq 'file://' )
Branch: 1 branch
BranchTrueFalseTotal
if (lc substr("$url", 0, 7) eq 'file://') { } 0 0 0
2282 {
2283 0 ▶ $self->_load_class( 'HTTP::Promise::Response' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Response") or return $self->pass_error 0 0 0
2284 return( Promise::Me->new(sub
2285 {
2286 0 ▶ my( $resolve, $reject ) = @$_;
Subroutine __ANON__: not called CC=6 SCAR=37.4
2287 0 ▶ my $f = $self->new_file( $url ) || return( $reject->( $self->error ) );
Condition0%0/2
$self->new_file($url) || (return &$reject($self->error))
l!l
00
MC/DC0%0/1
$self->new_file($url) || (return &$reject($self->error))
$self->new_file($url)
Truth table0%0/2
A
A= $self->new_file($url)
Aresult
11
00
2288 0 ▶ if( $f->exists )
Branch: 1 branch
BranchTrueFalseTotal
if ($f->exists) { } 0 0 0
2289 {
2290 0 ▶ my $ref = $f->load_json || return( $reject->( $f->error ) );
Condition0%0/2
$f->load_json || (return &$reject($f->error))
l!l
00
MC/DC0%0/1
$f->load_json || (return &$reject($f->error))
$f->load_json
Truth table0%0/2
A
A= $f->load_json
Aresult
11
00
2291 0 my $resp2 = HTTP::Promise::Response->new( 200 => 'OK' );
2292 0 ▶ if( defined( $success ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $success) 0 0 0
2293 {
2294 0 my $ua = HTTP::Promise->new;
2295 0 $success->( $ref, 'success', $resp2, $ua );
2296 }
2297 0 return( $resolve->( $ref, 'success', $resp2 ) );
2298 }
2299 else
2300 {
2301 0 my $resp2 = HTTP::Promise::Response->new( 404 => 'Not found' );
2302 0 my $err = "File $url is not found.";
2303 0 ▶ if( defined( $success ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $success) 0 0 0
2304 {
2305 0 my $ua = HTTP::Promise->new;
2306 0 $success->( $err, 'error', $resp2, $ua );
2307 }
2308 $self->error({
2309 0 code => 404,
2310 message => $err,
2311 });
2312 0 my $ex = $self->error;
2313 0 return( $reject->( $ex ) );
2314 }
2315 0 }) );
2316 }
2317 else
2318 {
2319 return( Promise::Me->new(sub
2320 {
2321 0 ▶ my( $resolve, $reject ) = @$_;
Subroutine __ANON__: not called CC=11 SCAR=48.8
2322 0 my( $uri, $doc_root, $doc_uri );
2323 0 ▶ if( lc( substr( $url, 0, 7 ) ) eq 'http://' ||
Branch: 2 branches
BranchTrueFalseTotal
if (lc substr($url, 0, 7) eq 'http://' or lc substr($url, 0, 7) eq 'http://') { } 0 0 0
elsif (substr($url, 0, 1) eq '/' || substr($url, 0, 2) eq './' || substr($url, 0, 3) eq '../' and $doc_root = $self->getRootNode and $doc_root->isa('HTML::Object::DOM::Document') and $doc_uri = $doc_root->documentURI) { } 0 0 0
Condition0%0/3
lc substr($url, 0, 7) eq "http://" or lc substr($url, 0, 7) eq "http://"
l!l&&r!l&&!r
000
MC/DC0%0/2
lc substr($url, 0, 7) eq "http://" or lc substr($url, 0, 7) eq "http://"
lc substr($url, 0, 7) eq "http://" lc substr($url, 0, 7) eq "http://"
Truth table0%0/3
A or B
A= lc substr($url, 0, 7) eq "http://"B= lc substr($url, 0, 7) eq "http://"
ABresult
1X1
011
000
2324 lc( substr( $url, 0, 7 ) ) eq 'http://' )
2325 {
2326 0 $uri = $url;
2327 }
2328 # Contextual URL that requires a base URL.
2329 # We check for documentURI of the root element, if any
2330 ▶ elsif( ( substr( $url, 0, 1 ) eq '/' ||
Condition0%0/15
substr($url, 0, 1) eq "/" || substr($url, 0, 2) eq "./" || substr($url, 0, 3) eq "../" and $doc_root = $self->getRootNode and $doc_root->isa("HTML::Object::DOM::Document") and $doc_uri = $doc_root->documentURI
!ll&&!rl&&r
000
substr($url, 0, 1) eq "/" || substr($url, 0, 2) eq "./" || substr($url, 0, 3) eq "../" and $doc_root = $self->getRootNode and $doc_root->isa("HTML::Object::DOM::Document")
!ll&&!rl&&r
000
substr($url, 0, 1) eq "/" || substr($url, 0, 2) eq "./" || substr($url, 0, 3) eq "../" and $doc_root = $self->getRootNode
!ll&&!rl&&r
000
substr($url, 0, 1) eq "/" or substr($url, 0, 2) eq "./" or substr($url, 0, 3) eq "../"
l!l&&r!l&&!r
000
substr($url, 0, 1) eq "/" or substr($url, 0, 2) eq "./"
l!l&&r!l&&!r
000
MC/DC0%0/6
substr($url, 0, 1) eq "/" || substr($url, 0, 2) eq "./" || substr($url, 0, 3) eq "../" and $doc_root = $self->getRootNode and $doc_root->isa("HTML::Object::DOM::Document") and $doc_uri = $doc_root->documentURI
substr($url, 0, 1) eq "/" substr($url, 0, 2) eq "./" substr($url, 0, 3) eq "../" $doc_root = $self->getRootNode $doc_root->isa("HTML::Object::DOM::Document") $doc_uri = $doc_root->documentURI
Truth table0%0/13
A or B or C and D and E and F
A= substr($url, 0, 1) eq "/"B= substr($url, 0, 2) eq "./"C= substr($url, 0, 3) eq "../"D= $doc_root = $self->getRootNodeE= $doc_root->isa("HTML::Object::DOM::Document")F= $doc_uri = $doc_root->documentURI
ABCDEFresult
000XXX0
1XX0XX0
01X0XX0
0010XX0
1XX10X0
01X10X0
00110X0
1XX1100
01X1100
0011100
1XX1111
01X1111
0011111
2331 substr( $url, 0, 2 ) eq './' ||
2332 substr( $url, 0, 3 ) eq '../' ) &&
2333 ( $doc_root = $self->getRootNode ) &&
2334 $doc_root->isa( 'HTML::Object::DOM::Document' ) &&
2335 ( $doc_uri = $doc_root->documentURI ) )
2336 {
2337 0 $uri = $doc_uri->clone;
2338 0 $uri->path( $url );
2339 }
2340 else
2341 {
2342 0 $self->error( "Unsupported URL '${url}'" );
2343 0 return( $reject->( $self->error ) );
2344 }
2345 $self->ajax( $uri,
2346 dataType => 'json',
2347 ( defined( $data ) ? ( data => $data ) : () ),
2348 ( defined( $success ) ? ( success => $success ) : () ),
2349 )->catch(sub
2350 {
2351 0 ▶ return( $reject->( @_ ) );
Subroutine __ANON__: not called CC=1 SCAR=6.9
2352 0 ▶ });
Branch: 2 branches
BranchTrueFalseTotal
defined $data ? : 0 0 0
defined $success ? : 0 0 0
2353 0 }) );
2354 }
2355 }
2356  
2357 sub has
2358 {
2359 0 ▶ my $self = shift( @_ );
Subroutine has: not called CC=10 SCAR=47.0
Pod documented
2360 0 my $this = shift( @_ );
2361 0 my $collection = $self->new_collection;
2362 0 ▶ return( $collection ) if( !defined( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this 0 0 0
2363 0 ▶ if( ref( $this ) && $self->_is_object( $this ) && $self->isa( 'HTML::Object::DOM::Element' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this and $self->_is_object($this) and $self->isa('HTML::Object::DOM::Element')) { } 0 0 0
Condition0%0/6
ref $this and $self->_is_object($this) and $self->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
000
ref $this and $self->_is_object($this)
!ll&&!rl&&r
000
MC/DC0%0/3
ref $this and $self->_is_object($this) and $self->isa("HTML::Object::DOM::Element")
ref $this $self->_is_object($this) $self->isa("HTML::Object::DOM::Element")
Truth table0%0/4
A and B and C
A= ref $thisB= $self->_is_object($this)C= $self->isa("HTML::Object::DOM::Element")
ABCresult
0XX0
10X0
1100
1111
2364 {
2365 0 my $lookup;
2366 $lookup = sub
2367 {
2368 0 ▶ my $kids = shift( @_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
2369 0 my $found;
2370 $kids->foreach(sub
2371 {
2372 0 ▶ my $child = shift( @_ );
Subroutine __ANON__: not called CC=3 SCAR=24.8
2373 $this->children->foreach(sub
2374 {
2375 0 ▶ my $candidate = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
2376 # Found a match, no need to look down further
2377 0 ▶ if( $child->eid eq $candidate->eid )
Branch: 1 branch
BranchTrueFalseTotal
if ($child->eid eq $candidate->eid) 0 0 0
2378 {
2379 0 $found = $child;
2380 0 return( $kids->return( undef() ) );
2381 }
2382 0 });
2383 0 ▶ if( $child->children->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($child->children->length) 0 0 0
2384 {
2385 0 my $rc = $lookup->( $child->children );
2386 0 ▶ if( $rc )
Branch: 1 branch
BranchTrueFalseTotal
if ($rc) 0 0 0
2387 {
2388 0 $found = $rc;
2389 0 return( $kids->return( undef() ) );
2390 }
2391 }
2392 0 });
2393 0 return( $found );
2394 0 };
2395 $self->children->foreach(sub
2396 {
2397 0 ▶ $collection->children->push( $_ ) if( $lookup->( $_->children ) );
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if &$lookup($_->children) 0 0 0
2398 0 });
2399 }
2400 # An xpath then?
2401 else
2402 {
2403 0 ▶ if( ref( $this ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this and !overload::Overloaded($this) || overload::Overloaded($this) && !overload::Method($this, "\"\"")) 0 0 0
Condition0%0/9
ref $this and !overload::Overloaded($this) || overload::Overloaded($this) && !overload::Method($this, "\"\"")
!ll&&!rl&&r
000
CORE::not overload::Overloaded($this) or overload::Overloaded($this) and CORE::not overload::Method($this, "\"\"")
l!l&&r!l&&!r
000
overload::Overloaded($this) and CORE::not overload::Method($this, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/4
ref $this and !overload::Overloaded($this) || overload::Overloaded($this) && !overload::Method($this, "\"\"")
ref $this CORE::not overload::Overloaded($this) overload::Overloaded($this) CORE::not overload::Method($this, "\"\"")
Truth table0%0/5
A and not(B) or C and not(D)
A= ref $thisB= CORE::not overload::Overloaded($this)C= overload::Overloaded($this)D= CORE::not overload::Method($this, "\"\"")
ABCDresult
0XXX0
100X0
10100
11XX1
10111
2404 (
2405 !overload::Overloaded( $this ) ||
2406 ( overload::Overloaded( $this ) && !overload::Method( $this, '""' ) )
2407 ) )
2408 {
2409 0 return( $self->error( "I was expecting an xpath value, but got '$this' instead." ) );
2410 }
2411 0 ▶ my $xpath = $self->_xpath_value( "$this" ) || return;
Condition0%0/2
$self->_xpath_value("$this") || (return)
l!l
00
MC/DC0%0/1
$self->_xpath_value("$this") || (return)
$self->_xpath_value("$this")
Truth table0%0/2
A
A= $self->_xpath_value("$this")
Aresult
11
00
2412  
2413 0 my $lookup;
2414 $lookup = sub
2415 {
2416 0 ▶ my $kids = shift( @_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
2417 0 my $found;
2418 $kids->foreach(sub
2419 {
2420 0 ▶ my $child = shift( @_ );
Subroutine __ANON__: not called CC=4 SCAR=30.0
2421 0 ▶ if( $child->matches( $xpath ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($child->matches($xpath)) 0 0 0
2422 {
2423 0 $found = $child;
2424 # No need to look further, we found a match
2425 0 return(1);
2426 }
2427 0 ▶ if( $child->children->length > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($child->children->length > 0) 0 0 0
2428 {
2429 0 my $rc = $lookup->( $child->children );
2430 0 ▶ if( $rc )
Branch: 1 branch
BranchTrueFalseTotal
if ($rc) 0 0 0
2431 {
2432 0 $found = $rc;
2433 0 return(1);
2434 }
2435 }
2436 0 });
2437 0 return( $found );
2438 0 };
2439  
2440 $self->children->foreach(sub
2441 {
2442 0 ▶ $collection->children->push( $_ ) if( $lookup->( $_->children ) );
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if &$lookup($_->children) 0 0 0
2443 0 });
2444 }
2445 0 return( $collection );
2446 }
2447  
2448 sub hasClass
2449 {
2450 2 ▶ my $self = shift( @_ );
Subroutine hasClass: called CC=5 SCAR=19.8
Pod undocumented
2451 2 my $class = shift( @_ );
2452 2 ▶ return(0) if( !CORE::length( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
unless CORE::length $class 0 2 2
2453 2 my $found = 0;
2454 2 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 2 0 2
2455 {
2456 $self->children->foreach(sub
2457 {
2458 2 ▶ my $e = shift( @_ );
Subroutine __ANON__: called CC=3 SCAR=11.6
2459 2 my $classes = $e->attributes->get( 'class' );
2460 # No class attribute, skip to next element
2461 2 ▶ return(1) if( !defined( $classes ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $classes 0 2 2
2462 # Found a match, no need to go further since we only need to return true or false
2463 2 ▶ if( $classes =~ /(?:\A|[[:blank:]\h]+)${class}(?:[[:blank:]\h]+|\Z)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($classes =~ /(?:\A|[[:blank:]\h]+)$class(?:[[:blank:]\h]+|\Z)/) 2 0 2
2464 {
2465 2 $found++;
2466 2 return(0);
2467 }
2468 0 return(1);
2469 2 });
2470 }
2471 else
2472 {
2473 0 my $classes = $self->attributes->get( 'class' );
2474 0 ▶ return(0) if( !defined( $classes ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $classes 0 0 0
2475 0 ▶ return(1) if( $classes =~ /(?:\A|[[:blank:]\h]+)${class}(?:[[:blank:]\h]+|\Z)/ );
Branch: 1 branch
BranchTrueFalseTotal
if $classes =~ /(?:\A|[[:blank:]\h]+)$class(?:[[:blank:]\h]+|\Z)/ 0 0 0
2476 0 return(0);
2477 }
2478 }
2479  
2480 # Since this is a perl context, this only set the inline css to "display: none" like jQuery actually does
2481 # Any parameter provided will be ignored
2482 # See the show() method for its alter ego
2483 sub hide
2484 {
2485 0 ▶ my $self = shift( @_ );
Subroutine hide: not called CC=5 SCAR=34.0
Pod undocumented
2486 0 my( $this, $code ) = @_;
2487 0 ▶ $code = $this if( ref( $this ) eq 'CODE' && !defined( $code ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $this eq "CODE" and CORE::not defined $code 0 0 0
Condition0%0/3
ref $this eq "CODE" and CORE::not defined $code
!ll&&!rl&&r
000
MC/DC0%0/2
ref $this eq "CODE" and CORE::not defined $code
ref $this eq "CODE" CORE::not defined $code
Truth table0%0/3
A and not(B)
A= ref $this eq "CODE"B= CORE::not defined $code
ABresult
0X0
100
111
2488 0 my $process;
2489 $process = sub
2490 {
2491 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=4 SCAR=30.0
2492 0 my $internal = $e->internal;
2493 0 my $rule = $self->_css_object();
2494 0 ▶ if( defined( $rule ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rule) { } 0 0 0
2495 {
2496 0 my $display = $rule->get_property_by_name( 'display' );
2497 0 my $val = $display->value;
2498 # $val may be undefined if it was not set in the first place, and that's ok
2499 # when we'll restore it with show(), we'll see the original value was empty and
2500 # we'll just remove the "display: none"
2501 # Here we check what the current value is, because, if it is already set to none, we just ignore it
2502 0 ▶ if( $val ne 'none' )
Branch: 1 branch
BranchTrueFalseTotal
if ($val ne "none") 0 0 0
2503 {
2504 0 $internal->{css_display_value} = $val;
2505 }
2506 0 $display->value( 'none' );
2507 }
2508 else
2509 {
2510 0 $rule = $self->_css_builder;
2511 0 $rule->display( 'none' );
2512 }
2513 0 ▶ if( $rule->elements->length > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($rule->elements->length > 0) 0 0 0
2514 {
2515 0 $e->_css_object( $rule );
2516 }
2517 0 };
2518  
2519 0 ▶ if( $self->isa_collection )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
elsif ($self->tag->substr(0, 1) eq '_') { } 0 0 0
2520 {
2521 $self->children->foreach(sub
2522 {
2523 0 ▶ $process->( $_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
2524 0 });
2525 }
2526 elsif( $self->tag->substr( 0, 1 ) eq '_' )
2527 {
2528 0 return( $self->error( "You can only use the hide() or show() method on html object elements. The element you are calling hide() with is an object of class \"", ref( $self ), "\"." ) );
2529 }
2530 else
2531 {
2532 0 $process->( $self );
2533 }
2534 }
2535  
2536 # This takes either no arguments and it returns the inner html; or
2537 # it takes an html string to replace its content; or
2538 # it takes a code reference that is called with the index position in the set of element and
2539 # the current html data. It returns the new html data
2540 # See also text() method
2541 sub html
2542 {
2543 5 ▶ my $self = shift( @_ );
Subroutine html: called CC=12 SCAR=47.3
Pod undocumented
2544 5 my $this = shift( @_ );
2545 5 ▶ if( defined( $this ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this) { } 0 5 5
2546 {
2547 0 ▶ if( !ref( $this ) ||
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not ref $this or ref $this and overload::Overloaded($this) and overload::Method($this, '""')) { } 0 0 0
elsif (ref $this ne 'CODE') { } 0 0 0
Condition0%0/9
CORE::not ref $this or ref $this and overload::Overloaded($this) and overload::Method($this, "\"\"")
l!l&&r!l&&!r
000
ref $this and overload::Overloaded($this) and overload::Method($this, "\"\"")
!ll&&!rl&&r
000
ref $this and overload::Overloaded($this)
!ll&&!rl&&r
000
MC/DC0%0/4
CORE::not ref $this or ref $this and overload::Overloaded($this) and overload::Method($this, "\"\"")
CORE::not ref $this ref $this overload::Overloaded($this) overload::Method($this, "\"\"")
Truth table0%0/5
not(A) or B and C and D
A= CORE::not ref $thisB= ref $thisC= overload::Overloaded($this)D= overload::Method($this, "\"\"")
ABCDresult
1XXX1
01111
00XX0
010X0
01100
2548 ( ref( $this ) && overload::Overloaded( $this ) && overload::Method( $this, '""' ) ) )
2549 {
2550 0 my $p = $self->new_parser;
2551 0 ▶ my $res = $p->parse_data( "$this" ) ||
Condition0%0/2
$p->parse_data("$this") || (return $self->error('Error while parsing html data provided: ', $p->error))
l!l
00
MC/DC0%0/1
$p->parse_data("$this") || (return $self->error('Error while parsing html data provided: ', $p->error))
$p->parse_data("$this")
Truth table0%0/2
A
A= $p->parse_data("$this")
Aresult
11
00
2552 return( $self->error( "Error while parsing html data provided: ", $p->error ) );
2553 0 $this = $res;
2554 }
2555 elsif( ref( $this ) ne 'CODE' )
2556 {
2557 0 return( $self->error( "I was expecting some html data or a code reference in replacement of html for this element \"", $self->tag, "\", but instead got '$this'." ) );
2558 }
2559  
2560 0 ▶ my $is_code = ref( $this ) eq 'CODE' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
ref $this eq 'CODE' ? : 0 0 0
2561 my $process = sub
2562 {
2563 0 ▶ my( $e, $i ) = @_;
Subroutine __ANON__: not called CC=13 SCAR=52.0
2564 0 ▶ if( $is_code )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_code) { } 0 0 0
2565 {
2566 0 my $current_html = $e->as_string;
2567 0 my $html = $this->( $i, $current_html );
2568 0 ▶ if( !defined( $html ) || !CORE::length( $html ) )
Branch: 3 branches
BranchTrueFalseTotal
if (CORE::not defined $html && CORE::length $html) { } 0 0 0
elsif (ref $html and $self->_is_object($html) and $html->isa('HTML::Object::DOM::Element')) { } 0 0 0
elsif (ref $html and CORE::not overload::Overloaded($html) && overload::Method($html, '""')) { } 0 0 0
Condition0%0/3
defined $html && CORE::length $html
!ll&&!rl&&r
000
MC/DC0%0/2
defined $html && CORE::length $html
defined $html CORE::length $html
Truth table0%0/3
A && B
A= defined $htmlB= CORE::length $html
ABresult
0X0
100
111
2569 {
2570 0 $e->empty();
2571 # Next please
2572 0 return(1);
2573 }
2574 # We were provided with an HTML::Object::DOM::Element in response, we use its children as the new content
2575 ▶ elsif( ref( $html ) && $self->_is_object( $html ) && $html->isa( 'HTML::Object::DOM::Element' ) )
Condition0%0/6
ref $html and $self->_is_object($html) and $html->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
000
ref $html and $self->_is_object($html)
!ll&&!rl&&r
000
MC/DC0%0/3
ref $html and $self->_is_object($html) and $html->isa("HTML::Object::DOM::Element")
ref $html $self->_is_object($html) $html->isa("HTML::Object::DOM::Element")
Truth table0%0/4
A and B and C
A= ref $htmlB= $self->_is_object($html)C= $html->isa("HTML::Object::DOM::Element")
ABCresult
0XX0
10X0
1100
1111
2576 {
2577 0 ▶ if( $html->tag->substr( 0, 1 ) eq '_' && !$html->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($html->tag->substr(0, 1) eq "_" and CORE::not $html->isa_collection) 0 0 0
Condition0%0/3
$html->tag->substr(0, 1) eq "_" and CORE::not $html->isa_collection
!ll&&!rl&&r
000
MC/DC0%0/2
$html->tag->substr(0, 1) eq "_" and CORE::not $html->isa_collection
$html->tag->substr(0, 1) eq "_" CORE::not $html->isa_collection
Truth table0%0/3
A and not(B)
A= $html->tag->substr(0, 1) eq "_"B= CORE::not $html->isa_collection
ABresult
0X0
100
111
2578 {
2579 0 warn( "You cannot use this object of class ", ref( $html ), " to set its children as the new html. You can only use html element objects.\n" );
2580 0 return(1);
2581 }
2582 0 $e->children( $html->children );
2583 $html->children->foreach(sub
2584 {
2585 0 ▶ $_->parent( $e );
Subroutine __ANON__: not called CC=1 SCAR=6.9
2586 0 });
2587 0 $e->reset(1);
2588 0 return(1);
2589 }
2590 ▶ elsif( ref( $html ) &&
Condition0%0/6
ref $html and CORE::not overload::Overloaded($html) && overload::Method($html, "\"\"")
!ll&&!rl&&r
000
overload::Overloaded($html) && overload::Method($html, '""')
!ll&&!rl&&r
000
MC/DC0%0/3
ref $html and CORE::not overload::Overloaded($html) && overload::Method($html, "\"\"")
ref $html overload::Overloaded($html) overload::Method($html, '""')
Truth table0%0/4
A and not(B && C)
A= ref $htmlB= overload::Overloaded($html)C= overload::Method($html, '""')
ABCresult
0XX0
1110
10X1
1101
2591 !( overload::Overloaded( $html ) && overload::Method( $html, '""' ) ) )
2592 {
2593 0 warn( "I was provided a reference '$html' as a result from calling this code reference to get the replacement html for tag \"", $e->tag, "\", but I do not know what to do with it.\n" );
2594 0 return(1);
2595 }
2596 0 my $p = $self->new_parser;
2597 my $doc = $p->parse_data( "$html" ) || do
2598 0 ▶ {
Condition0%0/3
$p->parse_data("$html") || do {
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->parse_data("$html") || do { warn 'Error while trying to parse html data returned by code reference supplied: ', $p->error, "\n"; return 1 }
$p->parse_data("$html") do { warn 'Error while trying to parse html data returned by code reference supplied: ', $p->error, "\n"; return 1 }
Truth table0%0/3
A || B
A= $p->parse_data("$html")B= do { warn 'Error while trying to parse html data returned by code reference supplied: ', $p->error, "\n"; return 1 }
ABresult
1X1
011
000
2599 0 warn( "Error while trying to parse html data returned by code reference supplied: ", $p->error, "\n" );
2600 # Switch to next element
2601 0 return(1);
2602 };
2603 # Replace the children element by the new ones found in parsing.
2604 0 $e->children( $doc->children );
2605 $doc->children->foreach(sub
2606 {
2607 0 ▶ $_->parent( $e );
Subroutine __ANON__: not called CC=1 SCAR=6.9
2608 0 });
2609 0 $e->reset(1);
2610 }
2611 # It's an HTML::Object::DOM::Document object
2612 else
2613 {
2614 0 my $a = $self->new_array;
2615 $this->children->foreach(sub
2616 {
2617 0 ▶ $a->push( $_->clone );
Subroutine __ANON__: not called CC=1 SCAR=6.9
2618 0 });
2619 0 $e->children( $a );
2620 0 $e->reset(1);
2621 }
2622 0 };
2623  
2624 0 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
2625 {
2626 $self->children->for(sub
2627 {
2628 0 ▶ my( $i, $e ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
2629 0 $process->( $e, $i );
2630 # Return true at the end to satisfy Module::Generic::Array->for
2631 0 return(1);
2632 0 });
2633 }
2634 else
2635 {
2636 0 $process->( $self, 0 );
2637 }
2638 }
2639 else
2640 {
2641 # "Get the HTML contents of the first element in the set of matched elements."
2642 5 ▶ my $elem = $self->isa_collection ? $self->children->first : $self;
Branch: 1 branch
BranchTrueFalseTotal
$self->isa_collection ? : 3 2 5
2643 5 ▶ return( '' ) unless( $self );
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 5 5
2644 # Create a new document, because we want to use the document object as_string function which produce a string of its children, and no need to reproduce it here
2645 5 my $doc = $elem->new_document;
2646 5 $doc->children( $elem->children );
2647 5 return( $doc->as_string );
2648 }
2649 }
2650  
2651 sub id
2652 {
2653 1 ▶ my $self = shift( @_ );
Subroutine id: called CC=6 SCAR=21.9
Pod documented
2654 1 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 1 1
2655 {
2656 0 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
2657 {
2658 0 return( $self->error( "Cannot set an id on a collection" ) );
2659 }
2660 else
2661 {
2662 # Method in HTML::Object::DOM::Element
2663 0 return( $self->_set_get_id( @_ ) );
2664 }
2665 }
2666 else
2667 {
2668 1 my $e = $self;
2669 1 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) 1 0 1
2670 {
2671 1 my $first = $self->children->first;
2672 1 ▶ return if( !$first || !$self->isa_element( $first ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $first and $self->isa_element($first) 0 1 1
Condition33%1/3
$first and $self->isa_element($first)
!ll&&!rl&&r
001
MC/DC0%0/2
$first and $self->isa_element($first)
$first $self->isa_element($first)
Truth table33%1/3
A and B
A= $firstB= $self->isa_element($first)
ABresult
0X0
100
111
2673 1 $e = $first;
2674 }
2675 1 my $id = $e->attributes->get( 'id' );
2676 1 return( $e->new_scalar( $id ) );
2677 }
2678 }
2679  
2680 # Takes either nothing; or
2681 # a selector; or
2682 # an element object
2683 sub index
2684 {
2685 0 ▶ my $self = shift( @_ );
Subroutine index: not called CC=22 SCAR=62.3
Pod undocumented
2686 0 my $this = shift( @_ );
2687 0 ▶ if( defined( $this ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this) { } 0 0 0
2688 {
2689 0 ▶ if( !ref( $this ) ||
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not ref $this or ref $this and overload::Overloaded($this) and overload::Method($this, '""')) { } 0 0 0
elsif (ref $this and $self->_is_object($this) and $this->isa('HTML::Object::DOM::Element')) { } 0 0 0
Condition0%0/9
CORE::not ref $this or ref $this and overload::Overloaded($this) and overload::Method($this, "\"\"")
l!l&&r!l&&!r
000
ref $this and overload::Overloaded($this) and overload::Method($this, "\"\"")
!ll&&!rl&&r
000
ref $this and overload::Overloaded($this)
!ll&&!rl&&r
000
MC/DC0%0/4
CORE::not ref $this or ref $this and overload::Overloaded($this) and overload::Method($this, "\"\"")
CORE::not ref $this ref $this overload::Overloaded($this) overload::Method($this, "\"\"")
Truth table0%0/5
not(A) or B and C and D
A= CORE::not ref $thisB= ref $thisC= overload::Overloaded($this)D= overload::Method($this, "\"\"")
ABCDresult
1XXX1
01111
00XX0
010X0
01100
2690 ( ref( $this ) && overload::Overloaded( $this ) && overload::Method( $this, '""' ) ) )
2691 {
2692 0 my $xpath = $self->_xpath_value( "$this" );
2693 0 ▶ if( $self->isa_collection() )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
2694 {
2695 0 my $found;
2696 $self->children->for(sub
2697 {
2698 0 ▶ my( $i, $e ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
2699 0 ▶ if( $e->matches( $xpath ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->matches($xpath)) 0 0 0
2700 {
2701 0 $found = $i;
2702 # Exit the for loop
2703 0 return(1);
2704 }
2705 0 });
2706 0 ▶ return( $self->new_number(-1) ) if( !defined( $found ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $found 0 0 0
2707 0 return( $self->new_number( $found ) );
2708 }
2709 else
2710 {
2711 0 ▶ if( $self->matches( $xpath ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->matches($xpath)) { } 0 0 0
2712 {
2713 0 ▶ return( $self->new_number(0) ) if( !$self->parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->parent 0 0 0
2714 0 my $pos = $self->parent->children->pos( $self );
2715 0 ▶ return( $self->new_number( defined( $pos ) ? $pos : -1 ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $pos ? : 0 0 0
2716 }
2717 else
2718 {
2719 0 return( $self->new_number(-1) );
2720 }
2721 }
2722 }
2723 ▶ elsif( ref( $this ) && $self->_is_object( $this ) && $this->isa( 'HTML::Object::DOM::Element' ) )
Condition0%0/6
ref $this and $self->_is_object($this) and $this->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
000
ref $this and $self->_is_object($this)
!ll&&!rl&&r
000
MC/DC0%0/3
ref $this and $self->_is_object($this) and $this->isa("HTML::Object::DOM::Element")
ref $this $self->_is_object($this) $this->isa("HTML::Object::DOM::Element")
Truth table0%0/4
A and B and C
A= ref $thisB= $self->_is_object($this)C= $this->isa("HTML::Object::DOM::Element")
ABCresult
0XX0
10X0
1100
1111
2724 {
2725 0 ▶ my $elem = $this->isa_collection() ? $this->children->first : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->isa_collection ? : 0 0 0
2726 0 my $found;
2727 0 ▶ if( $self->isa_collection() )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
2728 {
2729 $self->children->for(sub
2730 {
2731 0 ▶ my( $i, $e ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
2732 0 ▶ if( $e->eid eq $elem->eid )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->eid eq $elem->eid) 0 0 0
2733 {
2734 0 $found = $i;
2735 0 return;
2736 }
2737 0 });
2738 }
2739 else
2740 {
2741 0 ▶ return( $self->new_number( $self->eid eq $elem->eid ? 0 : -1 ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->eid eq $elem->eid ? : 0 0 0
2742 }
2743 }
2744 }
2745 # Return the position of the element or if this is a collection, the position of the first element in the collection
2746 else
2747 {
2748 0 ▶ my $elem = ( $self->isa_collection ? $self->children->first : $self );
Branch: 1 branch
BranchTrueFalseTotal
$self->isa_collection ? : 0 0 0
2749 0 ▶ return( $self->new_number(-1) ) if( !defined( $elem ) || !CORE::length( $elem ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elem and CORE::length $elem 0 0 0
Condition0%0/3
defined $elem and CORE::length $elem
!ll&&!rl&&r
000
MC/DC0%0/2
defined $elem and CORE::length $elem
defined $elem CORE::length $elem
Truth table0%0/3
A and B
A= defined $elemB= CORE::length $elem
ABresult
0X0
100
111
2750 0 ▶ return( $self->new_number(0) ) if( !$elem->parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->parent 0 0 0
2751 0 my $pos = $elem->parent->children->pos( $elem );
2752 0 ▶ return( $self->new_number( defined( $pos ) ? $pos : -1 ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $pos ? : 0 0 0
2753 }
2754 }
2755  
2756 0 ▶sub insertAfter { return( shift->_insert_before_after( @_, { action => 'after' }) ); }
Subroutine insertAfter: not called CC=1 SCAR=6.9
Pod documented
2757  
2758 0 ▶sub insertBefore { return( shift->_insert_before_after( @_, { action => 'before' }) ); }
Subroutine insertBefore: not called CC=1 SCAR=6.9
Pod documented
2759  
2760 # Takes a selector; or
2761 # an element object; or
2762 # a collection object; or
2763 # a code reference and
2764 # return true or false object
2765 # "Check the current matched set of elements against a selector, element, or jQuery object and return true if at least one of these elements matches the given arguments."
2766 # <https://api.jquery.com/is/#is-selector>
2767 sub is
2768 {
2769 0 ▶ my $self = shift( @_ );
Subroutine is: not called CC=16 SCAR=56.1
Pod documented
2770 0 my $this = shift( @_ );
2771 0 my $found = $self->false;
2772 0 ▶ if( ref( $this ) CORE::eq 'CODE' )
Branch: 3 branches
BranchTrueFalseTotal
if (ref $this eq 'CODE') { } 0 0 0
elsif (ref $this and $self->_is_object($this) and $this->isa('HTML::Object::DOM::Element')) { } 0 0 0
elsif (CORE::not ref $this or ref $this and overload::Overloaded($this) and overload::Method($this, '""')) { } 0 0 0
2773 {
2774 0 ▶ if( $self->isa_collection() )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
2775 {
2776 $self->children->for(sub
2777 {
2778 0 ▶ my( $i, $e ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
2779 0 local $_ = $e;
2780 0 ▶ if( $this->( $i, $e ) )
Branch: 1 branch
BranchTrueFalseTotal
if (&$this($i, $e)) 0 0 0
2781 {
2782 0 $found = $self->true;
2783 0 return(1);
2784 }
2785 0 });
2786 }
2787 else
2788 {
2789 0 ▶ my $pos = ( $self->parent ? $self->parent->children->pos( $self ) : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$self->parent ? : 0 0 0
2790 0 ▶ if( $this->( $pos, $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (&$this($pos, $self)) 0 0 0
2791 {
2792 0 $found = $self->true;
2793 }
2794 }
2795 0 return( $found );
2796 }
2797 ▶ elsif( ref( $this ) && $self->_is_object( $this ) && $this->isa( 'HTML::Object::DOM::Element' ) )
Condition0%0/6
ref $this and $self->_is_object($this) and $this->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
000
ref $this and $self->_is_object($this)
!ll&&!rl&&r
000
MC/DC0%0/3
ref $this and $self->_is_object($this) and $this->isa("HTML::Object::DOM::Element")
ref $this $self->_is_object($this) $this->isa("HTML::Object::DOM::Element")
Truth table0%0/4
A and B and C
A= ref $thisB= $self->_is_object($this)C= $this->isa("HTML::Object::DOM::Element")
ABCresult
0XX0
10X0
1100
1111
2798 {
2799 0 ▶ my $a = $this->isa_collection() ? $this->children() : $self->new_array( [ $this ] );
Branch: 1 branch
BranchTrueFalseTotal
$this->isa_collection ? : 0 0 0
2800 0 ▶ if( $self->isa_collection() )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
2801 {
2802 0 my $kids = $self->children;
2803 $kids->foreach(sub
2804 {
2805 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
2806 $a->foreach(sub
2807 {
2808 0 ▶ my $other = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
2809 0 ▶ if( $e->eid CORE::eq $other->eid )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->eid eq $other->eid) 0 0 0
2810 {
2811 0 $found = $self->true;
2812 # Exit this loop and tell the upper loop to exit as well
2813 0 return( $kids->return( undef() ) );
2814 }
2815 0 });
2816 0 });
2817 }
2818 else
2819 {
2820 $a->foreach(sub
2821 {
2822 0 ▶ if( $_->eid CORE::eq $self->eid )
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if ($_->eid eq $self->eid) 0 0 0
2823 {
2824 0 $found = $self->true;
2825 0 return(1);
2826 }
2827 0 });
2828 }
2829 0 return( $found );
2830 }
2831 # Works for xpath, but also need to account for special keywords starting with ':'
2832 # e.g.:
2833 # is( ":first-child" )
2834 # is( ":contains('Peter')" )
2835 # is( ":checked" )
2836 ▶ elsif( !ref( $this ) ||
Condition0%0/9
CORE::not ref $this or ref $this and overload::Overloaded($this) and overload::Method($this, "\"\"")
l!l&&r!l&&!r
000
ref $this and overload::Overloaded($this) and overload::Method($this, "\"\"")
!ll&&!rl&&r
000
ref $this and overload::Overloaded($this)
!ll&&!rl&&r
000
MC/DC0%0/4
CORE::not ref $this or ref $this and overload::Overloaded($this) and overload::Method($this, "\"\"")
CORE::not ref $this ref $this overload::Overloaded($this) overload::Method($this, "\"\"")
Truth table0%0/5
not(A) or B and C and D
A= CORE::not ref $thisB= ref $thisC= overload::Overloaded($this)D= overload::Method($this, "\"\"")
ABCDresult
1XXX1
01111
00XX0
010X0
01100
2837 ( ref( $this ) && overload::Overloaded( $this ) && overload::Method( $this, '""' ) ) )
2838 {
2839 0 my $xpath = $self->_xpath_value( $this );
2840 # false() method is inherited from Module::Generic module.
2841 0 ▶ if( $self->isa_collection() )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
2842 {
2843 $self->children->foreach(sub
2844 {
2845 0 ▶ if( $_->matches( $xpath ) )
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if ($_->matches($xpath)) 0 0 0
2846 {
2847 0 $found = $self->true;
2848 0 return(1);
2849 }
2850 0 });
2851 }
2852 else
2853 {
2854 0 ▶ $found = $self->true if( $self->matches( $xpath ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->matches($xpath) 0 0 0
2855 }
2856 0 return( $found );
2857 }
2858 else
2859 {
2860 0 return( $self->error( "I was expecting a selector, an element object, a collection object or a code reference, but got '$this'." ) );
2861 }
2862 }
2863  
2864 0 ▶sub isArray { return( shift->_is_array( @_ ) ); }
Subroutine isArray: not called CC=1 SCAR=6.9
Pod undocumented
2865  
2866 sub isa_collection
2867 {
2868 2057 ▶ my $self = shift( @_ );
Subroutine isa_collection: called CC=2 SCAR=6.9
Pod undocumented
2869 2057 ▶ if( scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 2 2055 2057
2870 {
2871 2 return( $_[0]->isa( 'HTML::Object::Collection' ) );
2872 }
2873 2055 return( $self->isa( 'HTML::Object::Collection' ) );
2874 }
2875  
2876 sub isa_element
2877 {
2878 5 ▶ my $self = shift( @_ );
Subroutine isa_element: called CC=2 SCAR=6.9
Pod undocumented
2879 5 ▶ my $e = scalar( @_ ) ? shift( @_ ) : $self;
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ ? : 1 4 5
2880 5 return( $self->_is_a( $e, 'HTML::Object::DOM::Element' ) );
2881 }
2882  
2883 sub length
2884 {
2885 0 ▶ my $self = shift( @_ );
Subroutine length: not called CC=2 SCAR=17.9
Pod undocumented
2886 0 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
2887 {
2888 0 return( $self->children->length );
2889 }
2890 else
2891 {
2892 0 return( $self->new_number(1) );
2893 }
2894 }
2895  
2896 # $e->load( 'https://example.org/some/where' );
2897 # $e->load( 'https://example.org/some/where', { param1 => value1, param2 => value2 } );
2898 # $e->load( 'https://example.org/some/where', { param1 => value1, param2 => value2 }, sub
2899 # {
2900 # my( $responseText, $responseStatus, $responseObject ) = @_;
2901 # # do something
2902 # });
2903 # <https://api.jquery.com/load/#load-url-data-complete>
2904 # $e->load( 'https://example.org/some/where', sub
2905 # {
2906 # my( $responseText, $responseStatus, $responseObject ) = @_;
2907 # # do something
2908 # });
2909 # $e->load({
2910 # url => 'https://example.org/some/where',
2911 # data => { param1 => value1, param2 => value2 },
2912 # callback => sub
2913 # {
2914 # my( $responseText, $responseStatus, $responseObject ) = @_;
2915 # # do something
2916 # }
2917 # });
2918 # <https://api.jquery.com/load/#load-url-data-complete>
2919 sub load
2920 {
2921 0 ▶ my $self = shift( @_ );
Subroutine load: not called CC=57 SCAR=81.0
Pod undocumented
2922 0 my( $url, $data, $complete ) = @_;
2923 0 my $opts = {};
2924 0 ▶ if( scalar( @_ ) == 1 && ref( $_[0] ) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 1 and ref $_[0] eq 'HASH') { } 0 0 0
elsif (scalar @_ > 2 and ref $_[-1] 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
2925 {
2926 0 $opts = shift( @_ );
2927 0 ( $url, $data, $complete ) = @$opts{qw( url data callback )};
2928 }
2929 # e.g. $e->load( $url, $data, $complete, $options );
2930 ▶ elsif( scalar( @_ ) > 2 && ref( $_[-1] ) eq 'HASH' )
Condition0%0/3
scalar @_ > 2 and ref $_[-1] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ > 2 and ref $_[-1] eq "HASH"
scalar @_ > 2 ref $_[-1] eq "HASH"
Truth table0%0/3
A and B
A= scalar @_ > 2B= ref $_[-1] eq "HASH"
ABresult
0X0
100
111
2931 {
2932 0 $opts = pop( @_ );
2933 }
2934  
2935 0 ▶ return( $self->error( "No url was provided to load data" ) ) if( !defined( $url ) || !CORE::length( "$url" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url and CORE::length "$url" 0 0 0
Condition0%0/3
defined $url and CORE::length "$url"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $url and CORE::length "$url"
defined $url CORE::length "$url"
Truth table0%0/3
A and B
A= defined $urlB= CORE::length "$url"
ABresult
0X0
100
111
2936 0 ▶ if( !defined( $complete ) && defined( $data ) && ref( $data ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::not defined $complete and defined $data and ref $data eq "CODE") 0 0 0
Condition0%0/6
CORE::not defined $complete and defined $data and ref $data eq "CODE"
!ll&&!rl&&r
000
CORE::not defined $complete and defined $data
!ll&&!rl&&r
000
MC/DC0%0/3
CORE::not defined $complete and defined $data and ref $data eq "CODE"
CORE::not defined $complete defined $data ref $data eq "CODE"
Truth table0%0/4
not(A) and B and C
A= CORE::not defined $completeB= defined $dataC= ref $data eq "CODE"
ABCresult
0XX0
10X0
1100
1111
2937 {
2938 0 $complete = $data;
2939 0 undef( $data );
2940 }
2941 0 ▶ if( defined( $data ) && ref( $data ) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data and ref $data ne "HASH") 0 0 0
Condition0%0/3
defined $data and ref $data ne "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $data and ref $data ne "HASH"
defined $data ref $data ne "HASH"
Truth table0%0/3
A and B
A= defined $dataB= ref $data ne "HASH"
ABresult
0X0
100
111
2942 {
2943 0 ▶ warn( "Data to be submitted to $url was provided, but I was expecting an hash reference and I got '", overload::StrVal( $data ), "'" ) if( $self->_is_warnings_enabled( 'HTML::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTML::Object") 0 0 0
2944 0 return( $self->error( "Data to be submitted to $url was provided, but I was expecting an hash reference and I got '", overload::StrVal( $data ), "'" ) );
2945 }
2946 0 ▶ if( defined( $complete ) && ref( $complete ) ne 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $complete and ref $complete ne "CODE") 0 0 0
Condition0%0/3
defined $complete and ref $complete ne "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $complete and ref $complete ne "CODE"
defined $complete ref $complete ne "CODE"
Truth table0%0/3
A and B
A= defined $completeB= ref $complete ne "CODE"
ABresult
0X0
100
111
2947 {
2948 0 return( $self->error( "A callback parameter was provided, and I was expecting a code reference, such as an anonymous subroutine, but instead I got '", overload::StrVal( $complete ), "'" ) );
2949 }
2950  
2951 # No need to go further if there is nothing in our collection
2952 0 ▶ my $children = $self->isa_collection ? $self->children : $self->new_array( $self );
Branch: 1 branch
BranchTrueFalseTotal
$self->isa_collection ? : 0 0 0
2953 0 ▶ return( $self ) if( !$children->length );
Branch: 1 branch
BranchTrueFalseTotal
unless $children->length 0 0 0
2954 # if( !$children->length )
2955 # {
2956 # if( defined( $complete ) )
2957 # {
2958 # my $resp = HTTP::Response->new( 204, 'No content', [] );
2959 # $children->foreach(sub
2960 # {
2961 # $complete->( '', 'nocontent', $resp );
2962 # });
2963 # }
2964 # return( $self );
2965 # }
2966  
2967 # Ultimately, if the callback is not set, we set a dummy one instead
2968 0 ▶ $complete = sub{1} if( !defined( $complete ) );
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless defined $complete 0 0 0
2969  
2970 0 ▶ if( !$self->_load_class( 'HTTP::Promise', { version => 'v0.5.0' } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_load_class("HTTP::Promise", {"version", "v0.5.0"})) 0 0 0
2971 {
2972 0 return( $self->error( "HTTP::Promise version v0.5.0 or higher is required to use load()" ) );
2973 }
2974 0 ▶ if( !$self->_load_class( 'URI', { version => '1.74' } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_load_class("URI", {"version", "1.74"})) 0 0 0
2975 {
2976 0 return( $self->error( "URI version 1.74 or higher is required to use load()" ) );
2977 }
2978 0 ▶ $opts->{timeout} //= 10;
Condition0%0/2
$opts->{"timeout"} //= 10
l!l
00
MC/DC0%0/1
$opts->{"timeout"} //= 10
$opts->{"timeout"}
Truth table0%0/2
A
A= $opts->{"timeout"}
Aresult
11
00
2979 0 ▶ $opts->{agent} ||= "HTML::Object/$VERSION";
Condition0%0/2
$opts->{"agent"} ||= "HTML::Object/$HTML::Object::DOM::Element::VERSION"
l!l
00
MC/DC0%0/1
$opts->{"agent"} ||= "HTML::Object/$HTML::Object::DOM::Element::VERSION"
$opts->{"agent"}
Truth table0%0/2
A
A= $opts->{"agent"}
Aresult
11
00
2980 # "If one or more space characters are included in the string, the portion of the string following the first space is assumed to be a jQuery selector that determines the content to be loaded."
2981 # e.g.: $( "#new-projects" )->load( "/resources/load.html #projects li" );
2982 # <https://api.jquery.com/load/#load-url-data-complete>
2983 0 ( $url, my $target ) = split( /[[:blank:]\h]+/, $url, 2 );
2984  
2985 0 my $uri;
2986 # try-catch
2987 0 local $@;
2988 eval
2989 0 {
2990 0 $uri = URI->new( "$url" );
2991 };
2992 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2993 {
2994 0 return( $self->error( "Bad url provided \"$url\": $@" ) );
2995 }
2996  
2997 0 my $content;
2998 my $resp;
2999 0 my @http_options = qw(
3000 accept_encoding accept_language auto_switch_https cookie_jar dnt max_redirect
3001 proxy
3002 );
3003 0 my $params = {};
3004 0 foreach my $k ( @http_options )
3005 {
3006 0 ▶ if( exists( $opts->{ $k } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{$k} and defined $opts->{$k} and CORE::length $opts->{$k}) 0 0 0
Condition0%0/6
exists $opts->{$k} and defined $opts->{$k} and CORE::length $opts->{$k}
!ll&&!rl&&r
000
exists $opts->{$k} and defined $opts->{$k}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $opts->{$k} and defined $opts->{$k} and CORE::length $opts->{$k}
exists $opts->{$k} defined $opts->{$k} CORE::length $opts->{$k}
Truth table0%0/4
A and B and C
A= exists $opts->{$k}B= defined $opts->{$k}C= CORE::length $opts->{$k}
ABCresult
0XX0
10X0
1100
1111
3007 defined( $opts->{ $k } ) &&
3008 CORE::length( $opts->{ $k } ) )
3009 {
3010 0 $params->{ $k } = $opts->{ $k };
3011 }
3012 }
3013 0 $params->{use_promise} = 0;
3014 # try-catch
3015 0 my $ua = HTTP::Promise->new( %$params );
3016 0 ▶ return( $self->pass_error( HTTP::Promise->error ) ) if( !defined( $ua ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ua 0 0 0
3017  
3018 # Contextual URL that requires a base URL.
3019 # We check for documentURI of the root element, if any
3020 0 my( $doc_root, $doc_uri );
3021 0 ▶ if( ( substr( $uri, 0, 1 ) eq '/' ||
Branch: 1 branch
BranchTrueFalseTotal
if (substr($uri, 0, 1) eq "/" || substr($uri, 0, 2) eq "./" || substr($uri, 0, 3) eq "../" and $doc_root = $self->getRootNode and $doc_root->isa("HTML::Object::DOM::Document") and $doc_uri = $doc_root->documentURI) 0 0 0
Condition0%0/15
substr($uri, 0, 1) eq "/" || substr($uri, 0, 2) eq "./" || substr($uri, 0, 3) eq "../" and $doc_root = $self->getRootNode and $doc_root->isa("HTML::Object::DOM::Document") and $doc_uri = $doc_root->documentURI
!ll&&!rl&&r
000
substr($uri, 0, 1) eq "/" || substr($uri, 0, 2) eq "./" || substr($uri, 0, 3) eq "../" and $doc_root = $self->getRootNode and $doc_root->isa("HTML::Object::DOM::Document")
!ll&&!rl&&r
000
substr($uri, 0, 1) eq "/" || substr($uri, 0, 2) eq "./" || substr($uri, 0, 3) eq "../" and $doc_root = $self->getRootNode
!ll&&!rl&&r
000
substr($uri, 0, 1) eq "/" or substr($uri, 0, 2) eq "./" or substr($uri, 0, 3) eq "../"
l!l&&r!l&&!r
000
substr($uri, 0, 1) eq "/" or substr($uri, 0, 2) eq "./"
l!l&&r!l&&!r
000
MC/DC0%0/6
substr($uri, 0, 1) eq "/" || substr($uri, 0, 2) eq "./" || substr($uri, 0, 3) eq "../" and $doc_root = $self->getRootNode and $doc_root->isa("HTML::Object::DOM::Document") and $doc_uri = $doc_root->documentURI
substr($uri, 0, 1) eq "/" substr($uri, 0, 2) eq "./" substr($uri, 0, 3) eq "../" $doc_root = $self->getRootNode $doc_root->isa("HTML::Object::DOM::Document") $doc_uri = $doc_root->documentURI
Truth table0%0/13
A or B or C and D and E and F
A= substr($uri, 0, 1) eq "/"B= substr($uri, 0, 2) eq "./"C= substr($uri, 0, 3) eq "../"D= $doc_root = $self->getRootNodeE= $doc_root->isa("HTML::Object::DOM::Document")F= $doc_uri = $doc_root->documentURI
ABCDEFresult
000XXX0
1XX0XX0
01X0XX0
0010XX0
1XX10X0
01X10X0
00110X0
1XX1100
01X1100
0011100
1XX1111
01X1111
0011111
3022 substr( $uri, 0, 2 ) eq './' ||
3023 substr( $uri, 0, 3 ) eq '../' ) &&
3024 ( $doc_root = $self->getRootNode ) &&
3025 $doc_root->isa( 'HTML::Object::DOM::Document' ) &&
3026 ( $doc_uri = $doc_root->documentURI ) )
3027 {
3028 0 my $clone = $doc_uri->clone;
3029 0 $clone->path( $uri );
3030 0 $uri = $clone;
3031 }
3032  
3033 0 ▶ if( $uri->scheme eq 'http' || $uri->scheme eq 'https' )
Branch: 2 branches
BranchTrueFalseTotal
if ($uri->scheme eq 'http' or $uri->scheme eq 'https') { } 0 0 0
elsif ($uri->scheme eq 'file') { } 0 0 0
Condition0%0/3
$uri->scheme eq "http" or $uri->scheme eq "https"
l!l&&r!l&&!r
000
MC/DC0%0/2
$uri->scheme eq "http" or $uri->scheme eq "https"
$uri->scheme eq "http" $uri->scheme eq "https"
Truth table0%0/3
A or B
A= $uri->scheme eq "http"B= $uri->scheme eq "https"
ABresult
1X1
011
000
3034 {
3035 # "The POST method is used if data is provided as an object; otherwise, GET is assumed."
3036 # <https://api.jquery.com/load/#load-url-data-complete>
3037 0 ▶ if( defined( $data ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data) { } 0 0 0
3038 {
3039 0 ▶ $resp = $ua->post( $uri, $data, ( ref( $opts->{headers} ) eq 'HASH' && scalar( keys( %{$opts->{headers}} ) ) ) ? %{$opts->{headers}} : () );
Branch: 1 branch
BranchTrueFalseTotal
ref $opts->{'headers'} eq 'HASH' && scalar keys %{$$opts{'headers'};} ? : 0 0 0
Condition0%0/2
ref $opts->{"headers"} eq "HASH" and scalar keys %{$$opts{"headers"};}
!ll
00
MC/DC0%0/1
ref $opts->{"headers"} eq "HASH" and scalar keys %{$$opts{"headers"};}
ref $opts->{"headers"} eq "HASH"
Truth table0%0/2
A
A= ref $opts->{"headers"} eq "HASH"
Aresult
00
11
3040 }
3041 else
3042 {
3043 0 ▶ $resp = $ua->get( $uri, ( ref( $opts->{headers} ) eq 'HASH' && scalar( keys( %{$opts->{headers}} ) ) ) ? %{$opts->{headers}} : () );
Branch: 1 branch
BranchTrueFalseTotal
ref $opts->{'headers'} eq 'HASH' && scalar keys %{$$opts{'headers'};} ? : 0 0 0
Condition0%0/2
ref $opts->{"headers"} eq "HASH" and scalar keys %{$$opts{"headers"};}
!ll
00
MC/DC0%0/1
ref $opts->{"headers"} eq "HASH" and scalar keys %{$$opts{"headers"};}
ref $opts->{"headers"} eq "HASH"
Truth table0%0/2
A
A= ref $opts->{"headers"} eq "HASH"
Aresult
00
11
3044 }
3045  
3046 0 ▶ if( !$resp )
Branch: 1 branch
BranchTrueFalseTotal
unless ($resp) 0 0 0
3047 {
3048 0 ▶ $self->_load_class( 'HTTP::Promise::Response' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Response") or return $self->pass_error 0 0 0
3049 0 ▶ my $err = "Error trying to get url \"${url}\": " . ( $ua->error ? $ua->error->message : 'unknown' );
Branch: 1 branch
BranchTrueFalseTotal
$ua->error ? : 0 0 0
3050 0 my $resp2 = HTTP::Promise::Response->new( 500, "Unexpected error", [], $err );
3051 0 $complete->( $err, 'error', $resp2, $ua );
3052 0 return( $self->error({
3053 code => 500,
3054 message => $err,
3055 }) );
3056 }
3057 0 $content = $resp->decoded_content;
3058  
3059 0 ▶ if( $resp->header( 'Client-Warning' ) || !$resp->is_success )
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->header("Client-Warning") or CORE::not $resp->is_success) 0 0 0
Condition0%0/3
$resp->header("Client-Warning") or CORE::not $resp->is_success
l!l&&r!l&&!r
000
MC/DC0%0/2
$resp->header("Client-Warning") or CORE::not $resp->is_success
$resp->header("Client-Warning") CORE::not $resp->is_success
Truth table0%0/3
A or not(B)
A= $resp->header("Client-Warning")B= CORE::not $resp->is_success
ABresult
1X1
011
000
3060 {
3061 0 $complete->( $content, 'error', $resp, $ua );
3062 0 return( $self->error({
3063 code => $resp->code,
3064 message => $resp->message,
3065 }) );
3066 }
3067 }
3068 elsif( $uri->scheme eq 'file' )
3069 {
3070 0 ▶ $self->_load_class( 'HTTP::Promise::Response' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Response") or return $self->pass_error 0 0 0
3071 0 ▶ my $f = $self->new_file( $uri ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($uri) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($uri) || (return $self->pass_error)
$self->new_file($uri)
Truth table0%0/2
A
A= $self->new_file($uri)
Aresult
11
00
3072 0 ▶ if( $f->exists )
Branch: 1 branch
BranchTrueFalseTotal
if ($f->exists) { } 0 0 0
3073 {
3074 0 $resp = HTTP::Promise::Response->new( 200 => 'OK' );
3075 0 $content = $f->load;
3076 }
3077 else
3078 {
3079 0 my $resp2 = HTTP::Promise::Response->new( 404 => 'Not found' );
3080 0 my $err = "File $uri is not found.";
3081 0 $complete->( $err, 'error', $resp2, $ua );
3082 0 return( $self->error({
3083 code => 404,
3084 message => $err,
3085 }) );
3086 }
3087 }
3088 else
3089 {
3090 0 my $resp2 = HTTP::Promise::Response->new( 400 => 'Bad request' );
3091 0 my $err = "The URL provided is unsupported.";
3092 0 $complete->( $err, 'error', $resp2, $ua );
3093 0 return( $self->error({
3094 code => 400,
3095 message => $err,
3096 }) );
3097 }
3098  
3099 0 my $new;
3100 0 ▶ if( defined( $content ) && CORE::length( $content // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content and CORE::length($content // '')) { } 0 0 0
Condition0%0/5
defined $content and CORE::length($content // "")
!ll&&!rl&&r
000
$content // ""
l!l
00
MC/DC0%0/2
defined $content and CORE::length($content // "")
defined $content $content
Truth table0%0/3
A and B
A= defined $contentB= $content
ABresult
0X0
100
111
3101 {
3102 0 my $parser = $self->new_parser;
3103 # HTML::Object::DOM::Document
3104 0 ▶ my $doc = $parser->parse_data( $content ) ||
Condition0%0/2
$parser->parse_data($content) || (return $self->pass_error($parser->error))
l!l
00
MC/DC0%0/1
$parser->parse_data($content) || (return $self->pass_error($parser->error))
$parser->parse_data($content)
Truth table0%0/2
A
A= $parser->parse_data($content)
Aresult
11
00
3105 return( $self->pass_error( $parser->error ) );
3106 0 $new = $doc->children;
3107 # "When this method executes, it retrieves the content of ajax/test.html, but then jQuery parses the returned document to find the element with an ID of container. This element, along with its contents, is inserted into the element with an ID of result, and the rest of the retrieved document is discarded."
3108 0 ▶ if( defined( $target ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $target) 0 0 0
3109 {
3110 0 $doc->debug( $self->debug );
3111 0 ▶ my $elem = $doc->find( $target ) || return( $self->pass_error( $doc->error ) );
Condition0%0/2
$doc->find($target) || (return $self->pass_error($doc->error))
l!l
00
MC/DC0%0/1
$doc->find($target) || (return $self->pass_error($doc->error))
$doc->find($target)
Truth table0%0/2
A
A= $doc->find($target)
Aresult
11
00
3112 # $new = $self->new_array( $elem );
3113 0 $new = $elem->children;
3114 }
3115 }
3116 # The content returned is empty, so we cannot parse it, and instead we provide a HTML::Object::DOM::Text element with an empty value inside.
3117 else
3118 {
3119 0 ▶ my $txt = $self->new_text( value => '' ) || return( $self->pass_error );
Condition0%0/2
$self->new_text('value', '') || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_text('value', '') || (return $self->pass_error)
$self->new_text('value', '')
Truth table0%0/2
A
A= $self->new_text('value', '')
Aresult
11
00
3120 0 $new = $self->new_array( $txt );
3121 }
3122  
3123 # "If a "complete" callback is provided, it is executed after post-processing and HTML insertion has been performed. The callback is fired once for each element in the collection, and $_ is set to each DOM element in turn."
3124 $children->foreach(sub
3125 {
3126 0 ▶ my $child = shift( @_ );
Subroutine __ANON__: not called CC=5 SCAR=34.0
3127 # Make a deep copy for each child element and set each child element's children
3128 0 ▶ my $clone = $new->map(sub{ $_->clone });
Subroutine __ANON__: not called CC=1 SCAR=6.9
3129 0 $child->children( $clone );
3130 0 $child->reset(1);
3131 0 my $status = 'error';
3132 0 ▶ if( $resp->code >= 200 && $resp->code < 300 )
Branch: 3 branches
BranchTrueFalseTotal
if ($resp->code >= 200 and $resp->code < 300) { } 0 0 0
elsif ($resp->code == 304) { } 0 0 0
elsif ($resp->is_error) { } 0 0 0
Condition0%0/3
$resp->code >= 200 and $resp->code < 300
!ll&&!rl&&r
000
MC/DC0%0/2
$resp->code >= 200 and $resp->code < 300
$resp->code >= 200 $resp->code < 300
Truth table0%0/3
A and B
A= $resp->code >= 200B= $resp->code < 300
ABresult
0X0
100
111
3133 {
3134 0 $status = 'success';
3135 }
3136 elsif( $resp->code == 304 )
3137 {
3138 0 $status = 'notmodified';
3139 }
3140 elsif( $resp->is_error )
3141 {
3142 0 $status = 'error';
3143 }
3144 0 $complete->( $content, $status, $resp );
3145 0 });
3146 0 return( $self );
3147 }
3148  
3149 sub map
3150 {
3151 0 ▶ my $self = shift( @_ );
Subroutine map: not called CC=3 SCAR=24.8
Pod undocumented
3152 0 ▶ my $code = shift( @_ ) || return( $self->error( "No code reference was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No code reference was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No code reference was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
3153 0 ▶ return( $self->error( "I was expecting a code reference, but instead I was provided with this: \"", overload::StrVal( $code ), "\"." ) ) if( ref( $code ) ne 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $code ne "CODE" 0 0 0
3154 0 return( $self->children->for( $code ) );
3155 }
3156  
3157 sub matches
3158 {
3159 4 ▶ my( $self, $path ) = @_;
Subroutine matches: called CC=1 SCAR=0.0
Pod documented
3160 4 return( $self->xp->matches( $self, $path, $self ) );
3161 }
3162  
3163 0 ▶sub name { return( shift->attr( name => shift( @_ ) ) ); }
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
3164  
3165 sub new_attribute
3166 {
3167 0 ▶ my $self = shift( @_ );
Subroutine new_attribute: not called CC=3 SCAR=24.8
Pod documented
3168 0 my $opts = $self->_get_args_as_hash( @_ );
3169 0 ▶ $opts->{debug} = $self->debug unless( exists( $opts->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"debug"} 0 0 0
3170 0 ▶ my $e = HTML::Object::DOM::Attribute->new( $opts ) ||
Condition0%0/2
'HTML::Object::DOM::Attribute'->new($opts) || (return $self->pass_error('HTML::Object::DOM::Attribute'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::DOM::Attribute'->new($opts) || (return $self->pass_error('HTML::Object::DOM::Attribute'->error))
'HTML::Object::DOM::Attribute'->new($opts)
Truth table0%0/2
A
A= 'HTML::Object::DOM::Attribute'->new($opts)
Aresult
11
00
3171 return( $self->pass_error( HTML::Object::DOM::Attribute->error ) );
3172 0 return( $e );
3173 }
3174  
3175 3 ▶sub new_parser { HTML::Object::DOM->new }
Subroutine new_parser: called CC=1 SCAR=0.0
Pod documented
3176  
3177 sub new_collection
3178 {
3179 45 ▶ my $self = shift( @_ );
Subroutine new_collection: called CC=4 SCAR=13.9
Pod undocumented
3180 45 my $opts = $self->_get_args_as_hash( @_ );
3181 45 ▶ $opts->{debug} = $self->debug unless( exists( $opts->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"debug"} 44 1 45
3182 45 ▶ $opts->{end} = $self unless( exists( $opts->{end} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"end"} 41 4 45
3183 45 ▶ my $e = HTML::Object::Collection->new( $opts ) ||
Condition50%1/2
'HTML::Object::Collection'->new($opts) || (return $self->pass_error('HTML::Object::Collection'->error))
l!l
450
MC/DC0%0/1
'HTML::Object::Collection'->new($opts) || (return $self->pass_error('HTML::Object::Collection'->error))
'HTML::Object::Collection'->new($opts)
Truth table50%1/2
A
A= 'HTML::Object::Collection'->new($opts)
Aresult
11
00
3184 return( $self->pass_error( HTML::Object::Collection->error ) );
3185 45 return( $e );
3186 }
3187  
3188 sub new_root
3189 {
3190 0 ▶ my $self = shift( @_ );
Subroutine new_root: not called CC=3 SCAR=24.8
Pod undocumented
3191 0 my $opts = $self->_get_args_as_hash( @_ );
3192 0 ▶ $opts->{debug} = $self->debug unless( exists( $opts->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"debug"} 0 0 0
3193 0 ▶ my $e = HTML::Object::DOM::Root->new( $opts ) ||
Condition0%0/2
'HTML::Object::DOM::Root'->new($opts) || (return $self->pass_error('HTML::Object::DOM::Root'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::DOM::Root'->new($opts) || (return $self->pass_error('HTML::Object::DOM::Root'->error))
'HTML::Object::DOM::Root'->new($opts)
Truth table0%0/2
A
A= 'HTML::Object::DOM::Root'->new($opts)
Aresult
11
00
3194 return( $self->pass_error( HTML::Object::DOM::Root->error ) );
3195 0 return( $e );
3196 }
3197  
3198 sub normalize_content
3199 {
3200 0 ▶ my $self = shift( @_ );
Subroutine normalize_content: not called CC=2 SCAR=17.9
Pod documented
3201 0 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
3202 {
3203 $self->children->foreach(sub
3204 {
3205 0 ▶ $_->normalize_content;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3206 0 });
3207 0 return( $self );
3208 }
3209 else
3210 {
3211 0 $self->SUPER::normalize_content;
3212 }
3213 }
3214  
3215 # Takes a selector expression; or
3216 # a element object; or
3217 # a collection of elements; or
3218 # an array of element objects to match against the set.
3219 sub not
3220 {
3221 0 ▶ my $self = shift( @_ );
Subroutine not: not called CC=12 SCAR=50.5
Pod documented
3222 0 my $this;
3223 0 ▶ $this = shift( @_ ) if( scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 0 0 0
3224 0 my $collection = $self->new_collection( end => $self );
3225 # Process array of elements
3226 0 my $process;
3227 $process = sub
3228 {
3229 0 ▶ my( $kids, $to_exclude ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3230 0 my $exclude = $self->new_array;
3231 $kids->foreach(sub
3232 {
3233 0 ▶ my $elem = shift( @_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
3234 0 my $path = $elem->getNodePath();
3235 $to_exclude->foreach(sub
3236 {
3237 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=8 SCAR=42.8
3238 0 ▶ return(1) if( !$self->_is_object( $e ) || !$e->isa( 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($e) and $e->isa("HTML::Object::DOM::Element") 0 0 0
Condition0%0/3
$self->_is_object($e) and $e->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($e) and $e->isa("HTML::Object::DOM::Element")
$self->_is_object($e) $e->isa("HTML::Object::DOM::Element")
Truth table0%0/3
A and B
A= $self->_is_object($e)B= $e->isa("HTML::Object::DOM::Element")
ABresult
0X0
100
111
3239 0 ▶ return(1) if( !$e->isa( 'HTML::Object::DOM::Comment' ) || $e->isa( 'HTML::Object::DOM::Text' ) || $e->isa( 'HTML::Object::DOM::Declaration' ) || $e->isa( 'HTML::Object::DOM::Space' ) );
Branch: 1 branch
BranchTrueFalseTotal
if CORE::not $e->isa("HTML::Object::DOM::Comment") or $e->isa("HTML::Object::DOM::Text") or $e->isa("HTML::Object::DOM::Declaration") or $e->isa("HTML::Object::DOM::Space") 0 0 0
Condition0%0/9
CORE::not $e->isa("HTML::Object::DOM::Comment") or $e->isa("HTML::Object::DOM::Text") or $e->isa("HTML::Object::DOM::Declaration") or $e->isa("HTML::Object::DOM::Space")
l!l&&r!l&&!r
000
CORE::not $e->isa("HTML::Object::DOM::Comment") or $e->isa("HTML::Object::DOM::Text") or $e->isa("HTML::Object::DOM::Declaration")
l!l&&r!l&&!r
000
CORE::not $e->isa("HTML::Object::DOM::Comment") or $e->isa("HTML::Object::DOM::Text")
l!l&&r!l&&!r
000
MC/DC0%0/4
CORE::not $e->isa("HTML::Object::DOM::Comment") or $e->isa("HTML::Object::DOM::Text") or $e->isa("HTML::Object::DOM::Declaration") or $e->isa("HTML::Object::DOM::Space")
CORE::not $e->isa("HTML::Object::DOM::Comment") $e->isa("HTML::Object::DOM::Text") $e->isa("HTML::Object::DOM::Declaration") $e->isa("HTML::Object::DOM::Space")
Truth table0%0/5
not(A) or B or C or D
A= CORE::not $e->isa("HTML::Object::DOM::Comment")B= $e->isa("HTML::Object::DOM::Text")C= $e->isa("HTML::Object::DOM::Declaration")D= $e->isa("HTML::Object::DOM::Space")
ABCDresult
1XXX1
01XX1
001X1
00011
00000
3240 # This element matches the xpath of one of the collection element, so we exclude it from the result
3241 0 ▶ if( $e->matches( $path ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->matches($path)) 0 0 0
3242 {
3243 0 $exclude->push( $elem );
3244 0 return(1);
3245 }
3246 0 });
3247 0 });
3248 0 return( $kids->clone->remove( $exclude ) );
3249 0 };
3250  
3251 # No parameter provided, thus we return an empty collection
3252 0 ▶ if( !defined( $this ) )
Branch: 5 branches
BranchTrueFalseTotal
if (CORE::not defined $this) { } 0 0 0
elsif (CORE::not ref $this or $self->_is_object($this) and overload::Overloaded($this) and overload::Method('""')) { } 0 0 0
elsif ($self->_is_array($this)) { } 0 0 0
elsif ($self->_is_object($this) and $self->isa_collection($this)) { } 0 0 0
elsif ($self->_is_object($this) and $this->isa('HTML::Object::DOM::Element')) { } 0 0 0
3253 {
3254 0 return( $collection );
3255 }
3256 ▶ elsif( !ref( $this ) || ( $self->_is_object( $this ) && overload::Overloaded( $this ) && overload::Method( '""' ) ) )
Condition0%0/9
CORE::not ref $this or $self->_is_object($this) and overload::Overloaded($this) and overload::Method("\"\"")
l!l&&r!l&&!r
000
$self->_is_object($this) and overload::Overloaded($this) and overload::Method("\"\"")
!ll&&!rl&&r
000
$self->_is_object($this) and overload::Overloaded($this)
!ll&&!rl&&r
000
MC/DC0%0/4
CORE::not ref $this or $self->_is_object($this) and overload::Overloaded($this) and overload::Method("\"\"")
CORE::not ref $this $self->_is_object($this) overload::Overloaded($this) overload::Method("\"\"")
Truth table0%0/5
not(A) or B and C and D
A= CORE::not ref $thisB= $self->_is_object($this)C= overload::Overloaded($this)D= overload::Method("\"\"")
ABCDresult
1XXX1
01111
00XX0
010X0
01100
3257 {
3258 0 my $xpath = $self->_xpath_value( "$this" );
3259 my $doc = $self->filter(sub
3260 {
3261 0 ▶ my $elem = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
3262 # try-catch
3263 my $rv = eval
3264 0 {
3265 0 return( !$elem->matches( $xpath ) );
3266 };
3267 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
3268 {
3269 0 return( $self->error( "Caught an exception while calling matches with xpath '$xpath' for element of class ", ref( $elem ), " and tag '", $elem->tag, "': $@" ) );
3270 }
3271 0 return( $rv );
3272 0 });
3273 0 $collection->children( $doc->children );
3274 }
3275 elsif( $self->_is_array( $this ) )
3276 {
3277 0 $this = $self->new_array( $this );
3278 #my $new = $self->children->clone->remove( $this );
3279 #$collection->children( $new );
3280 0 $this->unique(1);
3281 0 my $new = $process->( $self->children, $this );
3282 0 $collection->children( $new );
3283 }
3284 ▶ elsif( $self->_is_object( $this ) && $self->isa_collection( $this ) )
Condition0%0/3
$self->_is_object($this) and $self->isa_collection($this)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($this) and $self->isa_collection($this)
$self->_is_object($this) $self->isa_collection($this)
Truth table0%0/3
A and B
A= $self->_is_object($this)B= $self->isa_collection($this)
ABresult
0X0
100
111
3285 {
3286 0 my $kids = $this->children;
3287 0 my $new = $process->( $self->children, $kids );
3288 0 $collection->children( $new );
3289 }
3290 ▶ elsif( $self->_is_object( $this ) && $this->isa( 'HTML::Object::DOM::Element' ) )
Condition0%0/3
$self->_is_object($this) and $this->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($this) and $this->isa("HTML::Object::DOM::Element")
$self->_is_object($this) $this->isa("HTML::Object::DOM::Element")
Truth table0%0/3
A and B
A= $self->_is_object($this)B= $this->isa("HTML::Object::DOM::Element")
ABresult
0X0
100
111
3291 {
3292 0 $this = $self->new_array( [ $this ] );
3293 0 my $new = $process->( $self->children, $this );
3294 0 $collection->children( $new );
3295 }
3296 else
3297 {
3298 0 return( $self->error( "I receive an object \"", ref( $this ), "\", but I do not know what to do with it." ) );
3299 }
3300 0 return( $collection );
3301 }
3302  
3303 # Returns a new collection of elements whose position is an even number
3304 sub odd
3305 {
3306 0 ▶ my $self = shift( @_ );
Subroutine odd: not called CC=2 SCAR=17.9
Pod undocumented
3307 0 ▶ return( $self ) unless( $self->isa_collection );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isa_collection 0 0 0
3308 0 my $odd = $self->children->odd;
3309 0 my $collection = $self->new_collection;
3310 0 $collection->children( $odd );
3311 0 return( $collection );
3312 }
3313  
3314 # Takes html string (start with <tag...), text object (HTML::Object::DOM::Text), array or element object
3315 # or alternatively a code reference that returns the above
3316 0 ▶sub prepend { return( shift->_append_prepend( @_, { action => 'prepend' } ) ); }
Subroutine prepend: not called CC=1 SCAR=6.9
Pod documented
3317  
3318 0 ▶sub prependTo { return( shift->_append_prepend_to( @_, { action => 'prepend' } ) ); }
Subroutine prependTo: not called CC=1 SCAR=6.9
Pod undocumented
3319  
3320 # TODO: prop(), e.g. $e->prop('outerHTML') or $e->prop('tagName')
3321 sub prop
3322 {
3323 0 ▶ my $self = shift( @_ );
Subroutine prop: not called CC=17 SCAR=57.2
Pod undocumented
3324 # In get mode, this only affects the first element of the set
3325 # In set mode, this affect all elements of the set
3326 # <https://api.jquery.com/prop/#prop-propertyName>
3327 # <https://developer.mozilla.org/en-US/docs/Web/API/Element#properties>
3328 my $map =
3329 {
3330 0 ▶ checked => sub{ return( shift->attr( 'checked' ) ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3331 # Returns the number of child elements of this element.
3332 0 ▶ childElementCount => sub{ return( shift->children->length ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3333 # Returns the child elements of this element.
3334 0 ▶ children => sub{ return( shift->children ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3335 # Is a DOMString representing the class of the element.
3336 0 ▶ className => sub{ return( shift->attr( 'class' ) ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3337 0 ▶ disabled => sub{ return( shift->attr( 'disabled' ) ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3338 # Returns the first child element of this element.
3339 0 ▶ firstElementChild => sub{ return( shift->children->first ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3340 # Is a DOMString representing the id of the element.
3341 0 ▶ id => sub{ return( shift->attr( 'id' ) ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3342 # Is a DOMString representing the markup of the element's content.
3343 innerHTML => sub
3344 {
3345 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
3346 0 my $a = $self->new_array;
3347 $self->children->foreach(sub
3348 {
3349 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
3350 0 my $v = $e->as_string;
3351 0 ▶ $a->push( defined( $v ) ? $v->scalar : $v );
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 0 0 0
3352 0 });
3353 0 return( $a->join( '' ) );
3354 },
3355 # Returns the last child element of this element.
3356 0 ▶ lastElementChild => sub{ return( shift->children->last ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3357 # A DOMString representing the local part of the qualified name of the element.
3358 0 ▶ localName => sub{ return( shift->tag ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3359 # Is an Element, the element immediately following the given one in the tree, or null if there's no sibling node.
3360 nextElementSibling => sub
3361 {
3362 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
3363 0 ▶ my $parent = $e->parent || return;
Condition0%0/2
$e->parent || (return)
l!l
00
MC/DC0%0/1
$e->parent || (return)
$e->parent
Truth table0%0/2
A
A= $e->parent
Aresult
11
00
3364 0 my $pos = $parent->children->pos( $e );
3365 0 return( $parent->children->index( $pos + 1 ) );
3366 },
3367 # Is a DOMString representing the markup of the element including its content. When used as a setter, replaces the element with nodes parsed from the given string.
3368 0 ▶ outerHTML => sub{ return( shift->as_string ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3369 # Is a Element, the element immediately preceding the given one in the tree, or null if there is no sibling element.
3370 previousElementSibling => sub
3371 {
3372 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
3373 0 ▶ my $parent = $e->parent || return;
Condition0%0/2
$e->parent || (return)
l!l
00
MC/DC0%0/1
$e->parent || (return)
$e->parent
Truth table0%0/2
A
A= $e->parent
Aresult
11
00
3374 0 my $pos = $parent->children->pos( $e );
3375 0 return( $parent->children->index( $pos - 1 ) );
3376 },
3377 0 ▶ readonly => sub{ return( shift->attr( 'readonly' ) ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3378 # Returns a String with the name of the tag for the given element.
3379 0 ▶ tagName => sub{ return( shift->tag ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3380 0 };
3381 0 my $ro = $self->new_array( [qw(
3382 childelementcount children firstelementchild
3383 )] );
3384  
3385 # Get
3386 0 ▶ if( scalar( @_ ) == 1 )
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 1) { } 0 0 0
elsif (scalar @_ > 1) { } 0 0 0
3387 {
3388 0 ▶ my $e = $self->isa_collection ? $self->children->first : $self;
Branch: 1 branch
BranchTrueFalseTotal
$self->isa_collection ? : 0 0 0
3389 0 ▶ return if( !$e );
Branch: 1 branch
BranchTrueFalseTotal
unless $e 0 0 0
3390 0 my $prop = lc( shift( @_ ) );
3391 0 ▶ return( $self->error( "No such property \"$prop\"." ) ) if( !CORE::exists( $map->{ $prop } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $map->{$prop} 0 0 0
3392 0 my $code = $map->{ $prop };
3393 0 return( $code->( $e ) );
3394 }
3395 # Set
3396 elsif( scalar( @_ ) > 1 )
3397 {
3398 0 ▶ my $all = $self->new_array( $self->isa_collection ? $self->children : [ $self ] );
Branch: 1 branch
BranchTrueFalseTotal
$self->isa_collection ? : 0 0 0
3399 0 my @props = @_;
3400 0 ▶ while( scalar( @props ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @props) 0 0 0
3401 {
3402 0 my( $prop, $val ) = CORE::splice( @props, 0, 2 );
3403 0 $prop = lc( $prop );
3404 0 ▶ if( defined( $val ) && CORE::length( $val ) && $ro->exists( $prop ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and CORE::length $val and $ro->exists($prop)) 0 0 0
Condition0%0/6
defined $val and CORE::length $val and $ro->exists($prop)
!ll&&!rl&&r
000
defined $val and CORE::length $val
!ll&&!rl&&r
000
MC/DC0%0/3
defined $val and CORE::length $val and $ro->exists($prop)
defined $val CORE::length $val $ro->exists($prop)
Truth table0%0/4
A and B and C
A= defined $valB= CORE::length $valC= $ro->exists($prop)
ABCresult
0XX0
10X0
1100
1111
3405 {
3406 0 next;
3407 }
3408  
3409 # process the html
3410 0 ▶ if( $prop eq 'innerHTML' )
Branch: 2 branches
BranchTrueFalseTotal
if ($prop eq 'innerHTML') { } 0 0 0
elsif ($prop eq 'outerHTML') { } 0 0 0
3411 {
3412 0 ▶ if( defined( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
3413 {
3414 0 my $p = HTML::Object::DOM->new;
3415 my $doc = $p->parse_data( $val ) || do
3416 0 ▶ {
Condition0%0/3
$p->parse_data($val) || do {
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->parse_data($val) || do { $! = $p->error; return }
$p->parse_data($val) do { $! = $p->error; return }
Truth table0%0/3
A || B
A= $p->parse_data($val)B= do { $! = $p->error; return }
ABresult
1X1
011
000
3417 0 $! = $p->error;
3418 0 return;
3419 };
3420 $all->foreach(sub
3421 {
3422 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
3423 0 $e->children( $doc->children );
3424 0 $e->reset(1);
3425 0 });
3426 }
3427 else
3428 {
3429 $all->foreach(sub
3430 {
3431 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
3432 0 $e->children->empty;
3433 0 $e->reset(1);
3434 0 });
3435 }
3436 0 next;
3437 }
3438 elsif( $prop eq 'outerHTML' )
3439 {
3440 0 ▶ if( defined( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
3441 {
3442 0 my $p = HTML::Object::DOM->new;
3443 my $doc = $p->parse_data( $val ) || do
3444 0 ▶ {
Condition0%0/3
$p->parse_data($val) || do {
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->parse_data($val) || do { $! = $p->error; return }
$p->parse_data($val) do { $! = $p->error; return }
Truth table0%0/3
A || B
A= $p->parse_data($val)B= do { $! = $p->error; return }
ABresult
1X1
011
000
3445 0 $! = $p->error;
3446 0 return;
3447 };
3448 $all->foreach(sub
3449 {
3450 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
3451 0 my $parent = $e->parent;
3452 0 ▶ return(1) if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
3453 0 my $pos = $parent->children->pos( $e );
3454 0 my @new = ();
3455 $doc->children->foreach(sub
3456 {
3457 0 ▶ my $kid = shift( @_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
3458 0 my $clone = $kid->clone;
3459 0 $clone->parent( $parent );
3460 0 push( @new, $clone );
3461 0 });
3462 0 $parent->children->splice( $pos, 1, @new );
3463 0 $parent->reset(1);
3464 0 });
3465 }
3466 else
3467 {
3468 $all->foreach(sub
3469 {
3470 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
3471 0 my $parent = $e->parent;
3472 0 ▶ return(1) if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
3473 0 my $pos = $parent->children->pos( $e );
3474 0 $e->children->splice( $pos, 1 );
3475 0 $e->reset(1);
3476 0 });
3477 }
3478 0 next;
3479 }
3480  
3481 $all->foreach(sub
3482 {
3483 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=11 SCAR=48.8
3484 0 ▶ if( $prop eq 'checked' )
Branch: 5 branches
BranchTrueFalseTotal
if ($prop eq 'checked') { } 0 0 0
elsif ($prop eq 'className') { } 0 0 0
elsif ($prop eq 'disabled') { } 0 0 0
elsif ($prop eq 'id') { } 0 0 0
elsif ($prop eq 'readonly') { } 0 0 0
3485 {
3486 0 ▶ if( $val )
Branch: 1 branch
BranchTrueFalseTotal
if ($val) { } 0 0 0
3487 {
3488 0 $e->attr( checked => 'checked' );
3489 }
3490 else
3491 {
3492 0 $e->attributes->delete( $prop );
3493 }
3494 0 $e->reset(1);
3495 }
3496 elsif( $prop eq 'className' )
3497 {
3498 0 ▶ if( defined( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
3499 {
3500 0 $e->attr( class => $val );
3501 }
3502 else
3503 {
3504 0 $e->attributes->delete( 'class' );
3505 }
3506 0 $e->reset(1);
3507 }
3508 elsif( $prop eq 'disabled' )
3509 {
3510 0 ▶ if( $val )
Branch: 1 branch
BranchTrueFalseTotal
if ($val) { } 0 0 0
3511 {
3512 0 $e->attr( disabled => 'disabled' );
3513 }
3514 else
3515 {
3516 0 $e->attributes->delete( $prop );
3517 }
3518 0 $e->reset(1);
3519 }
3520 elsif( $prop eq 'id' )
3521 {
3522 0 ▶ if( defined( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
3523 {
3524 0 $e->attr( id => $val );
3525 }
3526 else
3527 {
3528 0 $e->attributes->delete( $prop );
3529 }
3530 0 $e->reset(1);
3531 }
3532 elsif( $prop eq 'readonly' )
3533 {
3534 0 ▶ if( $val )
Branch: 1 branch
BranchTrueFalseTotal
if ($val) { } 0 0 0
3535 {
3536 0 $e->attr( readonly => 'readonly' );
3537 }
3538 else
3539 {
3540 0 $e->attributes->delete( $prop );
3541 }
3542 0 $e->reset(1);
3543 }
3544 0 });
3545 }
3546 }
3547 }
3548  
3549 sub promise
3550 {
3551 0 ▶ my $self = shift( @_ );
Subroutine promise: not called CC=1 SCAR=6.9
Pod undocumented
3552 0 return( Promise::Me->new( @_ ) );
3553 # my $deferred = Promise::XS::deferred();
3554 # return( $deferred->promise() );
3555 }
3556  
3557 # NOTE: queue is not implemented
3558 # <https://api.jquery.com/queue/>
3559  
3560 32 ▶sub rank { return( shift->_set_get_number_as_object( 'rank', @_ ) ); }
Subroutine rank: called CC=1 SCAR=0.0
Pod undocumented
3561  
3562 # <https://api.jquery.com/remove/>
3563 # TODO: Need to check again and do some test to ensure this api is compliant
3564 sub remove
3565 {
3566 1 ▶ my $self = shift( @_ );
Subroutine remove: called CC=4 SCAR=17.3
Pod documented
3567 1 ▶ if( $self->isa_collection )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->isa_collection) { } 1 0 1
elsif (@_) { } 0 0 0
3568 {
3569 $self->children->foreach(sub
3570 {
3571 4 ▶ my $e = shift( @_ );
Subroutine __ANON__: called CC=1 SCAR=0.0
3572 4 my $pos = $e->pos;
3573 4 my $parent = $e->parent;
3574 4 $e->delete;
3575 1 });
3576 }
3577 # xpath provided
3578 elsif( @_ )
3579 {
3580 0 ▶ my $xpath = $self->_xpath_value( shift( @_ ) ) || return;
Condition0%0/2
$self->_xpath_value(shift @_) || (return)
l!l
00
MC/DC0%0/1
$self->_xpath_value(shift @_) || (return)
$self->_xpath_value(shift @_)
Truth table0%0/2
A
A= $self->_xpath_value(shift @_)
Aresult
11
00
3581 0 $self->find( $xpath )->remove;
3582 }
3583 # Equivalent to delete
3584 else
3585 {
3586 0 $self->delete;
3587 }
3588 1 return( $self );
3589 }
3590  
3591 sub removeAttr
3592 {
3593 0 ▶ my $self = shift( @_ );
Subroutine removeAttr: not called CC=3 SCAR=24.8
Pod undocumented
3594 0 my $attr = shift( @_ );
3595 0 ▶ return( $self ) if( !defined( $attr ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attr 0 0 0
3596 0 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
3597 {
3598 $self->children->foreach(sub
3599 {
3600 0 ▶ $_->attributes->delete( $attr );
Subroutine __ANON__: not called CC=1 SCAR=6.9
3601 0 $_->reset(1);
3602 0 });
3603 }
3604 else
3605 {
3606 0 $self->attributes->delete( $attr );
3607 0 $self->reset(1);
3608 }
3609 0 return( $self );
3610 }
3611  
3612 # class name, array of class name or a code reference
3613 # If parameter is a code reference it must return a class name or an array of class name
3614 # It receives "the index position of the element in the set and the old class value as arguments"
3615 sub removeClass
3616 {
3617 0 ▶ my $self = shift( @_ );
Subroutine removeClass: not called CC=6 SCAR=37.4
Pod undocumented
3618 0 my $this;
3619 0 ▶ $this = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
3620 0 my $a;
3621 # No class provided, so we will remove all existing class
3622 0 ▶ if( !defined( $this ) )
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not defined $this) { } 0 0 0
elsif ($self->_is_array($this)) { } 0 0 0
3623 {
3624 0 $a = $self->new_array;
3625 }
3626 elsif( $self->_is_array( $this ) )
3627 {
3628 0 $a = $self->new_array( $this );
3629 0 my $failed = 0;
3630 $a->foreach(sub
3631 {
3632 0 ▶ if( ref( $_ ) && !( overload::Overloaded( $_ ) && overload::Method( $_, '""' ) ) )
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ and CORE::not overload::Overloaded($_) && overload::Method($_, "\"\"")) 0 0 0
Condition0%0/6
ref $_ and CORE::not overload::Overloaded($_) && overload::Method($_, "\"\"")
!ll&&!rl&&r
000
overload::Overloaded($_) && overload::Method($_, '""')
!ll&&!rl&&r
000
MC/DC0%0/3
ref $_ and CORE::not overload::Overloaded($_) && overload::Method($_, "\"\"")
ref $_ overload::Overloaded($_) overload::Method($_, '""')
Truth table0%0/4
A and not(B && C)
A= ref $_B= overload::Overloaded($_)C= overload::Method($_, '""')
ABCresult
0XX0
1110
10X1
1101
3633 {
3634 0 $failed++;
3635 0 $self->error( "Class provided to be removed \"$_\" is not a string nor an overloaded object." );
3636 0 return(0);
3637 }
3638 0 });
3639 0 ▶ return( $self ) if( $failed );
Branch: 1 branch
BranchTrueFalseTotal
if $failed 0 0 0
3640 }
3641  
3642 0 my $process;
3643 $process = sub
3644 {
3645 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
3646 0 ▶ return( $e ) unless( $e->attributes->exists( 'class' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $e->attributes->exists("class") 0 0 0
3647 0 my $c = $self->new_array( [split( /[[:blank:]\h]+/, $e->attributes->get( 'class' ) )] );
3648 # Loop through the element classes
3649 $c->for(sub
3650 {
3651 0 ▶ my( $i, $v ) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
3652 0 ▶ if( ref( $this ) CORE::eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this eq "CODE") 0 0 0
3653 {
3654 0 local $_ = $self;
3655 0 my $res = $this->( $i, $v );
3656 0 ▶ if( $self->_is_array( $res ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($res)) { } 0 0 0
3657 {
3658 0 $a = $self->new_array( $res );
3659 }
3660 else
3661 {
3662 0 $a = $self->new_array( [ $res ] );
3663 }
3664 }
3665 $a->foreach(sub
3666 {
3667 0 ▶ my $to_remove = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
3668 0 ▶ if( $v CORE::eq "$to_remove" )
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq "$to_remove") 0 0 0
3669 {
3670 0 $c->splice( $i, 1 );
3671 0 $c->return( -1 );
3672 }
3673 0 return;
3674 0 });
3675 0 });
3676 0 $e->reset(1);
3677 0 return(1);
3678 0 };
3679 0 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
3680 {
3681 0 $self->children->foreach( $process );
3682 }
3683 else
3684 {
3685 0 $process->( $self );
3686 }
3687 0 return( $self );
3688 }
3689  
3690 sub removeData
3691 {
3692 1 ▶ my $self = shift( @_ );
Subroutine removeData: called CC=13 SCAR=34.2
Pod undocumented
3693 1 my $elem;
3694 1 ▶ if( $self->isa_collection )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->isa_collection) { } 1 0 1
elsif (CORE::not $self->_is_a($self, 'HTML::Object::DOM::Element')) { } 0 0 0
3695 {
3696 1 $elem = $self->children->first;
3697 }
3698 elsif( !$self->_is_a( $self => 'HTML::Object::DOM::Element' ) )
3699 {
3700 0 return( $self->error( "You can only call the removeData() method on html elements." ) );
3701 }
3702 else
3703 {
3704 0 $elem = $self;
3705 }
3706  
3707 1 my $keys;
3708 # If no @_ is provided this is undef and it is ok, we would remove all data attributes then
3709 1 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 0 1
3710 {
3711 1 my $this = shift( @_ );
3712 1 ▶ if( $self->_is_empty( $this ) )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_is_empty($this)) { } 0 1 1
elsif (CORE::not ref $this or ref $this and $self->_can_overload($this, '""')) { } 1 0 1
elsif ($self->_is_array($this)) { } 0 0 0
3713 {
3714 0 return( $self->error( "Data name value provided is empty. If you want to remove all data attributes, simply call removeData() without argument." ) );
3715 }
3716 ▶ elsif( !ref( $this ) ||
Condition16%1/6
CORE::not ref $this or ref $this and $self->_can_overload($this, "\"\"")
l!l&&r!l&&!r
100
ref $this and $self->_can_overload($this, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/3
CORE::not ref $this or ref $this and $self->_can_overload($this, "\"\"")
CORE::not ref $this ref $this $self->_can_overload($this, "\"\"")
Truth table25%1/4
not(A) or B and C
A= CORE::not ref $thisB= ref $thisC= $self->_can_overload($this, "\"\"")
ABCresult
1XX1
0111
00X0
0100
3717 ( ref( $this ) && $self->_can_overload( $this => '""' ) ) )
3718 {
3719 1 $this = "$this";
3720 1 ▶ if( CORE::index( $this, ' ' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::index($this, ' ') != -1) { } 0 1 1
3721 {
3722 0 $keys = [CORE::split( /[[:blank:]\h]+/, $this )];
3723 }
3724 else
3725 {
3726 1 $keys = [$this];
3727 }
3728 }
3729 elsif( $self->_is_array( $this ) )
3730 {
3731 0 $keys = $this;
3732 }
3733 else
3734 {
3735 0 return( $self->error( "Data name value to remove is unsupported. You can only provide a string, a space-separated string of names, or an array reference." ) );
3736 }
3737 }
3738 else
3739 {
3740 0 $keys = $elem->attributes_sequence;
3741 }
3742  
3743 1 my $changed = 0;
3744 1 foreach my $k ( @$keys )
3745 {
3746 1 ▶ if( $elem->hasAttribute( 'data-' . $k ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->hasAttribute('data-' . $k)) 1 0 1
3747 {
3748 1 $elem->removeAttribute( 'data-' . $k );
3749 1 $changed++;
3750 }
3751 }
3752 1 ▶ $elem->reset(1) if( $changed );
Branch: 1 branch
BranchTrueFalseTotal
if $changed 1 0 1
3753 # Return undef
3754 1 return;
3755 }
3756  
3757 # Takes html string, array of elements, an element (including a collection object) or a code reference
3758 sub replaceWith
3759 {
3760 0 ▶ my $self = shift( @_ );
Subroutine replaceWith: not called CC=20 SCAR=60.4
Pod documented
3761 0 ▶ my $this = shift( @_ ) || return( $self->error( "Nothing was provided to replace." ) );
Condition0%0/2
shift @_ || (return $self->error('Nothing was provided to replace.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('Nothing was provided to replace.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
3762 0 my $a;
3763 0 ▶ if( !ref( $this ) )
Branch: 4 branches
BranchTrueFalseTotal
if (CORE::not ref $this) { } 0 0 0
elsif ($self->_is_array($this)) { } 0 0 0
elsif ($self->_is_object($this)) { } 0 0 0
elsif (ref $this ne 'CODE') { } 0 0 0
3764 {
3765 0 my $p = $self->new_parser;
3766 0 ▶ $this = $p->parse_data( $this ) || return( $self->pass_error( $p->error ) );
Condition0%0/2
$p->parse_data($this) || (return $self->pass_error($p->error))
l!l
00
MC/DC0%0/1
$p->parse_data($this) || (return $self->pass_error($p->error))
$p->parse_data($this)
Truth table0%0/2
A
A= $p->parse_data($this)
Aresult
11
00
3767 0 $a = $self->new_array( [ $this ] );
3768 }
3769 elsif( $self->_is_array( $this ) )
3770 {
3771 # Make sure this is a Module::Generic::Array object
3772 0 $a = $self->new_array( $this );
3773 }
3774 elsif( $self->_is_object( $this ) )
3775 {
3776 0 ▶ return( $self->error( "Object provided '$this' (", overload::StrVal( $this ), ") is not an HTML::Object::DOM::Element object." ) ) if( !$this->isa( 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $this->isa("HTML::Object::DOM::Element") 0 0 0
3777 0 $a = $self->new_array( [ $this ] );
3778 }
3779 elsif( ref( $this ) ne 'CODE' )
3780 {
3781 0 return( $self->error( "I do not know what to do with '$this'. I was expecing an html string, or an HTML::Object::DOM::Element or an array of element objects or a collection object (HTML::Object::Collection) or a code reference." ) );
3782 }
3783  
3784 0 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
3785 {
3786 0 my $failed = 0;
3787 $self->children->foreach(sub
3788 {
3789 0 ▶ my $elem = shift( @_ );
Subroutine __ANON__: not called CC=10 SCAR=47.0
3790 0 ▶ if( ref( $this ) CORE::eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this eq "CODE") 0 0 0
3791 {
3792 0 local $_ = $elem;
3793 0 my $res = $this->( $elem );
3794 0 ▶ if( !defined( $res ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 0 0
3795 {
3796 0 $failed++;
3797 0 $self->error( "An error occurred while executing code reference to replace html element(s). Code reference returned undef." );
3798 0 return(0);
3799 }
3800 0 ▶ if( $self->_is_object( $res ) && $res->isa( 'HTML::Object::DOM::Element' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_object($res) and $res->isa('HTML::Object::DOM::Element')) { } 0 0 0
elsif (overload::Overloaded($res) and overload::Method($res, '""')) { } 0 0 0
Condition0%0/3
$self->_is_object($res) and $res->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($res) and $res->isa("HTML::Object::DOM::Element")
$self->_is_object($res) $res->isa("HTML::Object::DOM::Element")
Truth table0%0/3
A and B
A= $self->_is_object($res)B= $res->isa("HTML::Object::DOM::Element")
ABresult
0X0
100
111
3801 {
3802 0 $a = $self->new_array( [ $res ] );
3803 }
3804 ▶ elsif( overload::Overloaded( $res ) && overload::Method( $res, '""' ) )
Condition0%0/3
overload::Overloaded($res) and overload::Method($res, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/2
overload::Overloaded($res) and overload::Method($res, "\"\"")
overload::Overloaded($res) overload::Method($res, "\"\"")
Truth table0%0/3
A and B
A= overload::Overloaded($res)B= overload::Method($res, "\"\"")
ABresult
0X0
100
111
3805 {
3806 0 my $elem = $self->new_parser( "$res" );
3807 0 ▶ if( !defined( $elem ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $elem) 0 0 0
3808 {
3809 0 $failed++;
3810 0 return(0);
3811 }
3812 0 $a = $self->new_array( [ $elem ] );
3813 }
3814 else
3815 {
3816 0 $failed++;
3817 0 $self->error( "Value returned from code reference to be used in replaceWith is neither a string nor a HTML::Object::DOM::Element, so I do not know what to do with it." );
3818 0 return(0);
3819 }
3820 }
3821 0 ▶ if( !$elem->parent )
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem->parent) 0 0 0
3822 {
3823 0 $self->error( "Found an element within a collection that has no parent! Element has tag \"", $elem->tag, "\"." );
3824 0 return(0);
3825 }
3826 0 my $pos = $elem->parent->pos( $elem );
3827 0 ▶ if( !defined( $pos ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pos) 0 0 0
3828 {
3829 0 $self->error( "This element with tag \"", $self->tag, "\" has a parent and yet I could not find its position." );
3830 0 return(0);
3831 }
3832 0 my $new = $self->new_array;
3833 $a->foreach(sub
3834 {
3835 0 ▶ my $e = $_->detach->clone();
Subroutine __ANON__: not called CC=1 SCAR=6.9
3836 0 $e->parent( $elem->parent );
3837 0 $new->push( $e );
3838 0 });
3839 0 $elem->parent->children->splice( $pos, 1, $a->list );
3840 0 $elem->parent->reset(1);
3841 0 });
3842 # Now that the element have been copied to their replacement location, we remove them
3843 $a->foreach(sub
3844 {
3845 0 ▶ $_->delete;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3846 0 });
3847 0 ▶ return if( $failed );
Branch: 1 branch
BranchTrueFalseTotal
if $failed 0 0 0
3848 }
3849 else
3850 {
3851 0 ▶ if( ref( $this ) CORE::eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this eq "CODE") 0 0 0
3852 {
3853 0 local $_ = $self;
3854 0 my $res = $this->( $self );
3855 0 ▶ return( $self->error( "An error occurred while executing code reference to replace html element(s). Code reference returned undef." ) ) if( !defined( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 0 0
3856 0 ▶ if( $self->_is_object( $res ) && $res->isa( 'HTML::Object::DOM::Element' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_object($res) and $res->isa('HTML::Object::DOM::Element')) { } 0 0 0
elsif (overload::Overloaded($res) and overload::Method($res, '""')) { } 0 0 0
Condition0%0/3
$self->_is_object($res) and $res->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($res) and $res->isa("HTML::Object::DOM::Element")
$self->_is_object($res) $res->isa("HTML::Object::DOM::Element")
Truth table0%0/3
A and B
A= $self->_is_object($res)B= $res->isa("HTML::Object::DOM::Element")
ABresult
0X0
100
111
3857 {
3858 0 $a = $self->new_array( [ $res ] );
3859 }
3860 ▶ elsif( overload::Overloaded( $res ) && overload::Method( $res, '""' ) )
Condition0%0/3
overload::Overloaded($res) and overload::Method($res, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/2
overload::Overloaded($res) and overload::Method($res, "\"\"")
overload::Overloaded($res) overload::Method($res, "\"\"")
Truth table0%0/3
A and B
A= overload::Overloaded($res)B= overload::Method($res, "\"\"")
ABresult
0X0
100
111
3861 {
3862 0 my $elem = $self->new_parser( "$res" );
3863 0 ▶ return if( !defined( $elem ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elem 0 0 0
3864 0 $a = $self->new_array( [ $elem ] );
3865 }
3866 else
3867 {
3868 0 return( $self->error( "Value returned from code reference to be used in replaceWith is neither a string nor a HTML::Object::DOM::Element, so I do not know what to do with it." ) );
3869 }
3870 }
3871  
3872 # Object has no parent, so we are essentially replace 1 element for one or more others with no attachment to the dom
3873 0 ▶ if( !$self->parent )
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::not $self->parent) { } 0 0 0
3874 {
3875 # Basically swapping one element for another
3876 0 ▶ if( $a->length == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($a->length == 1) { } 0 0 0
3877 {
3878 0 my $e = $a->first;
3879 0 $e->detach;
3880 0 return( $e );
3881 }
3882 # There are multiple element, create a document element
3883 else
3884 {
3885 0 my $doc = HTML::Object::DOM::Document->new;
3886 0 $doc->children( $a );
3887 $a->foreach(sub
3888 {
3889 0 ▶ $_->detach;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3890 0 $_->parent( $doc );
3891 0 $_->parent->reset(1);
3892 0 });
3893 0 return( $doc );
3894 }
3895 }
3896 else
3897 {
3898 0 my $pos = $self->parent->pos( $self );
3899 0 ▶ return( $self->error( "This element with tag \"", $self->tag, "\" has a parent and yet I could not find its position." ) ) if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
3900 $a->foreach(sub
3901 {
3902 0 ▶ $_->detach->parent( $self->parent );
Subroutine __ANON__: not called CC=1 SCAR=6.9
3903 0 });
3904 0 $self->parent->children->splice( $pos, 1, $a->list );
3905 0 $self->parent->reset(1);
3906 }
3907 }
3908 0 return( $self );
3909 }
3910  
3911 sub set_namespace
3912 {
3913 0 ▶ my $self = shift( @_ );
Subroutine set_namespace: not called CC=1 SCAR=6.9
Pod undocumented
3914 0 return( $self->xp->new->set_namespace( @_ ) );
3915 }
3916  
3917 # Since this is a perl context, this only set the inline css 1) back to its previous value,
3918 # if any; or 2) remove the display property if there was no previous value set.
3919 # Any parameter provided will be ignored
3920 # See the hide() method for its alter ego.
3921 sub show
3922 {
3923 0 ▶ my $self = shift( @_ );
Subroutine show: not called CC=5 SCAR=34.0
Pod undocumented
3924 0 my( $this, $code ) = @_;
3925 0 ▶ $code = $this if( ref( $this ) eq 'CODE' && !defined( $code ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $this eq "CODE" and CORE::not defined $code 0 0 0
Condition0%0/3
ref $this eq "CODE" and CORE::not defined $code
!ll&&!rl&&r
000
MC/DC0%0/2
ref $this eq "CODE" and CORE::not defined $code
ref $this eq "CODE" CORE::not defined $code
Truth table0%0/3
A and not(B)
A= ref $this eq "CODE"B= CORE::not defined $code
ABresult
0X0
100
111
3926 0 my $process;
3927 $process = sub
3928 {
3929 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=7 SCAR=40.3
3930 0 my $internal = $e->internal;
3931 0 my $rule = $self->_css_object();
3932 0 ▶ if( defined( $rule ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rule) 0 0 0
3933 {
3934 0 my $display = $rule->get_property_by_name( 'display' );
3935 0 my $val = $display->value;
3936 # if display current value is 'none', we check if there was a previous value we kept
3937 # and if there is we restore it, otherwise we simply just remove the property
3938 0 ▶ if( $val eq 'none' )
Branch: 1 branch
BranchTrueFalseTotal
if ($val eq "none") 0 0 0
3939 {
3940 0 my $previous_val = $internal->{css_display_value};
3941 0 ▶ if( defined( $previous_val ) && CORE::length( $previous_val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $previous_val and CORE::length $previous_val) { } 0 0 0
Condition0%0/3
defined $previous_val and CORE::length $previous_val
!ll&&!rl&&r
000
MC/DC0%0/2
defined $previous_val and CORE::length $previous_val
defined $previous_val CORE::length $previous_val
Truth table0%0/3
A and B
A= defined $previous_valB= CORE::length $previous_val
ABresult
0X0
100
111
3942 {
3943 0 $display->value( $previous_val );
3944 }
3945 else
3946 {
3947 0 $display->remove_from( $rule );
3948 }
3949 }
3950 }
3951 # otherwise, there is no rule inline defined, and thus, nothing to do.
3952  
3953 # Is there any rule and properties to save back?
3954 0 ▶ if( defined( $rule ) && $rule->elements->length > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rule and $rule->elements->length > 0) 0 0 0
Condition0%0/3
defined $rule and $rule->elements->length > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $rule and $rule->elements->length > 0
defined $rule $rule->elements->length > 0
Truth table0%0/3
A and B
A= defined $ruleB= $rule->elements->length > 0
ABresult
0X0
100
111
3955 {
3956 0 $e->_css_object( $rule );
3957 }
3958 0 };
3959  
3960 0 ▶ if( $self->isa_collection )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
elsif ($self->tag->substr(0, 1) eq '_') { } 0 0 0
3961 {
3962 $self->children->foreach(sub
3963 {
3964 0 ▶ $process->( $_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
3965 0 $_->reset(1);
3966 0 });
3967 }
3968 elsif( $self->tag->substr( 0, 1 ) eq '_' )
3969 {
3970 0 return( $self->error( "You can only use the hide() or show() method on html object elements. The element you are calling hide() with is an object of class \"", ref( $self ), "\"." ) );
3971 }
3972 else
3973 {
3974 0 $process->( $self );
3975 0 $self->reset(1);
3976 }
3977 }
3978  
3979 # This is here and although it has been deprecated, so that $.uniqueSort() works
3980 # <https://stackoverflow.com/questions/63575333/javascript-replacement-of-sourceindex-in-chromium-browsers>
3981 # <https://developer.mozilla.org/en-US/docs/Web/API/Document/all>
3982 11 ▶sub sourceIndex : lvalue { return( shift->_set_get_lvalue( 'sourceIndex', @_ ) ); }
Subroutine sourceIndex: called CC=1 SCAR=0.0
Pod undocumented
3983  
3984 sub string_value
3985 {
3986 224 ▶ my $self = shift( @_ );
Subroutine string_value: called CC=2 SCAR=7.1
Pod undocumented
3987 224 ▶ return( $self->value ) if( $self->isCommentNode );
Branch: 1 branch
BranchTrueFalseTotal
if $self->isCommentNode 0 224 224
3988 224 return( $self->as_text );
3989 }
3990  
3991 # This is normally a HTML::Object::DOM::Element property and it should not be used equally
3992 # by a collection object, because of its nature, so we created it here to catch calls to it
3993 # while still allowing HTML::Object::DOM::Element to use it normally
3994 sub tag
3995 {
3996 1613 ▶ my $self = shift( @_ );
Subroutine tag: called CC=6 SCAR=18.7
Pod documented
3997 1613 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 164 1449 1613
3998 {
3999 164 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 164 164
4000 {
4001 0 return( $self->error( "tag is a read-only property" ) );
4002 }
4003 else
4004 {
4005 164 return( $self->_set_get_scalar_as_object( 'tag', @_ ) );
4006 }
4007 }
4008 else
4009 {
4010 1449 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 5 1444 1449
4011 {
4012 5 my $first = $self->children->first;
4013 5 ▶ return unless( $first && $self->_is_a( $first, 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $first and $self->_is_a($first, "HTML::Object::DOM::Element") 0 5 5
Condition33%1/3
$first and $self->_is_a($first, "HTML::Object::DOM::Element")
!ll&&!rl&&r
005
MC/DC0%0/2
$first and $self->_is_a($first, "HTML::Object::DOM::Element")
$first $self->_is_a($first, "HTML::Object::DOM::Element")
Truth table33%1/3
A and B
A= $firstB= $self->_is_a($first, "HTML::Object::DOM::Element")
ABresult
0X0
100
111
4014 5 return( $first->_set_get_scalar_as_object( 'tag' ) );
4015 }
4016 else
4017 {
4018 1444 return( $self->_set_get_scalar_as_object( 'tag' ) );
4019 }
4020 }
4021 }
4022  
4023 sub tagname
4024 {
4025 0 ▶ my $self = shift( @_ );
Subroutine tagname: not called CC=1 SCAR=6.9
Pod undocumented
4026 0 my @args = @_;
4027 0 my $map =
4028 {
4029 Comment => '#comment',
4030 Text => '#text'
4031 };
4032 0 my $a = $self->new_array;
4033 $self->children->foreach(sub
4034 {
4035 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
4036 0 my $type = [split( /::/, ref( $e ) )]->[-1];
4037 0 ▶ $a->push( exists( $map->{ $type } ) ? $map->{ $type } : $e->tag( @args ) );
Branch: 1 branch
BranchTrueFalseTotal
exists $map->{$type} ? : 0 0 0
4038 0 });
4039 0 return( $a );
4040 }
4041  
4042 # This method work for absolutely any element, including the root element (html)
4043 sub text
4044 {
4045 2 ▶ my $self = shift( @_ );
Subroutine text: called CC=9 SCAR=43.3
Pod documented
4046 2 my $this = shift( @_ );
4047 # Mutator
4048 2 ▶ if( defined( $this ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this) { } 0 2 2
4049 {
4050 0 ▶ if( !ref( $this ) ||
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not ref $this or ref $this and overload::Overloaded($this) and overload::Method($this, '""')) { } 0 0 0
elsif (ref $this ne 'CODE') { } 0 0 0
Condition0%0/9
CORE::not ref $this or ref $this and overload::Overloaded($this) and overload::Method($this, "\"\"")
l!l&&r!l&&!r
000
ref $this and overload::Overloaded($this) and overload::Method($this, "\"\"")
!ll&&!rl&&r
000
ref $this and overload::Overloaded($this)
!ll&&!rl&&r
000
MC/DC0%0/4
CORE::not ref $this or ref $this and overload::Overloaded($this) and overload::Method($this, "\"\"")
CORE::not ref $this ref $this overload::Overloaded($this) overload::Method($this, "\"\"")
Truth table0%0/5
not(A) or B and C and D
A= CORE::not ref $thisB= ref $thisC= overload::Overloaded($this)D= overload::Method($this, "\"\"")
ABCDresult
1XXX1
01111
00XX0
010X0
01100
4051 ( ref( $this ) && overload::Overloaded( $this ) && overload::Method( $this, '""' ) ) )
4052 {
4053 0 $this = "$this";
4054 }
4055 elsif( ref( $this ) ne 'CODE' )
4056 {
4057 0 return( $self->error( "I was expecting some text data or a code reference in replacement of text for this element \"", $self->tag, "\", but instead got '$this'." ) );
4058 }
4059  
4060 0 ▶ my $is_code = ref( $this ) eq 'CODE' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
ref $this eq 'CODE' ? : 0 0 0
4061 my $process = sub
4062 {
4063 0 ▶ my( $e, $i ) = @_;
Subroutine __ANON__: not called CC=11 SCAR=48.8
4064 0 ▶ if( $is_code )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_code) { } 0 0 0
4065 {
4066 0 my $current_text = $e->as_text( unescape => 1 );
4067 0 my $text = $this->( $i, $current_text );
4068 0 ▶ if( !defined( $text ) || !CORE::length( $text ) )
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not defined $text && CORE::length $text) { } 0 0 0
elsif (ref $text and CORE::not overload::Overloaded($text) && overload::Method($text, '""')) { } 0 0 0
Condition0%0/3
defined $text && CORE::length $text
!ll&&!rl&&r
000
MC/DC0%0/2
defined $text && CORE::length $text
defined $text CORE::length $text
Truth table0%0/3
A && B
A= defined $textB= CORE::length $text
ABresult
0X0
100
111
4069 {
4070 0 $e->empty();
4071 # Next please
4072 0 return(1);
4073 }
4074 ▶ elsif( ref( $text ) &&
Condition0%0/6
ref $text and CORE::not overload::Overloaded($text) && overload::Method($text, "\"\"")
!ll&&!rl&&r
000
overload::Overloaded($text) && overload::Method($text, '""')
!ll&&!rl&&r
000
MC/DC0%0/3
ref $text and CORE::not overload::Overloaded($text) && overload::Method($text, "\"\"")
ref $text overload::Overloaded($text) overload::Method($text, '""')
Truth table0%0/4
A and not(B && C)
A= ref $textB= overload::Overloaded($text)C= overload::Method($text, '""')
ABCresult
0XX0
1110
10X1
1101
4075 !( overload::Overloaded( $text ) && overload::Method( $text, '""' ) ) )
4076 {
4077 0 warn( "I was provided a reference '$text' as a result from calling this code reference to get the replacement text for tag \"", $e->tag, "\", but I do not know what to do with it.\n" );
4078 0 return(1);
4079 }
4080 0 $text = "$text";
4081 0 $text =~ s/</\&lt;/gs;
4082 0 $text =~ s/>/\&gt;/gs;
4083 0 $text =~ s,\n,<br />\n,gs;
4084 0 ▶ if( $self->isa( 'HTML::Object::DOM::Comment' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa('HTML::Object::DOM::Comment') or $self->isa('HTML::Object::DOM::Text')) { } 0 0 0
Condition0%0/3
$self->isa("HTML::Object::DOM::Comment") or $self->isa("HTML::Object::DOM::Text")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->isa("HTML::Object::DOM::Comment") or $self->isa("HTML::Object::DOM::Text")
$self->isa("HTML::Object::DOM::Comment") $self->isa("HTML::Object::DOM::Text")
Truth table0%0/3
A or B
A= $self->isa("HTML::Object::DOM::Comment")B= $self->isa("HTML::Object::DOM::Text")
ABresult
1X1
011
000
4085 $self->isa( 'HTML::Object::DOM::Text' ) )
4086 {
4087 0 $self->value( $text );
4088 }
4089 else
4090 {
4091 0 my $new = $self->new_text( value => $text, parent => $self );
4092 # If this is an empty tag, such as <input /> or <img />, the text cannot be added to it.
4093 # jQuery actually accepts the text and attach it to the element as a child, but the web browser does not show it, because it is an empty element.
4094 # Since this is not a web browser interface, we need to silently ignore it, so it does not end up in the DOM and turn an empty tag into a tag with children and a closing tag, which would be an heresy.
4095 0 ▶ if( !$e->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::not $e->is_empty) 0 0 0
4096 {
4097 0 $e->children->set( $new );
4098 }
4099 }
4100 }
4101 else
4102 {
4103 0 my $new = $self->new_text( value => $this, parent => $e );
4104 # See comment just above
4105 0 ▶ if( !$e->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::not $e->is_empty) 0 0 0
4106 {
4107 0 $e->children->set( $new );
4108 }
4109 }
4110 0 };
4111  
4112 0 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
4113 {
4114 $self->children->for(sub
4115 {
4116 0 ▶ my( $i, $e ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
4117 0 $process->( $e, $i );
4118 0 $e->reset(1);
4119 # Return true at the end to satisfy Module::Generic::Array->for
4120 0 return(1);
4121 0 });
4122 }
4123 else
4124 {
4125 0 $process->( $self, 0 );
4126 0 $self->reset(1);
4127 }
4128 }
4129 # Accessor
4130 else
4131 {
4132 2 return( $self->as_text( unescape => 1 ) );
4133 }
4134 }
4135  
4136 # Takes a class name; or
4137 # class name and state (true or false); or
4138 # array of class names; or
4139 # array of class names and a state; or
4140 # a code reference called with the index position of the current class and its name. Returns a space separated list of classes or an array
4141 # <https://api.jquery.com/toggleClass/>
4142 sub toggleClass
4143 {
4144 0 ▶ my $self = shift( @_ );
Subroutine toggleClass: not called CC=10 SCAR=47.0
Pod undocumented
4145 0 my $this;
4146 0 ▶ $this = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
4147 0 my $state;
4148 0 ▶ $state = scalar( @_ ) ? shift( @_ ) : 1;
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ ? : 0 0 0
4149 0 my $a = $self->new_array;
4150 0 my $has_code = 0;
4151 0 ▶ if( defined( $this ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this) 0 0 0
4152 {
4153 0 ▶ if( $self->_is_array( $this ) )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_is_array($this)) { } 0 0 0
elsif (ref $this eq 'CODE') { } 0 0 0
elsif (ref $this and overload::Overloaded($this) and overload::Method($this, '""')) { } 0 0 0
4154 {
4155 0 $a = $self->new_array( $this );
4156 }
4157 elsif( ref( $this ) CORE::eq 'CODE' )
4158 {
4159 # ok
4160 0 $has_code++;
4161 }
4162 ▶ elsif( ref( $this ) && overload::Overloaded( $this ) && overload::Method( $this, '""' ) )
Condition0%0/6
ref $this and overload::Overloaded($this) and overload::Method($this, "\"\"")
!ll&&!rl&&r
000
ref $this and overload::Overloaded($this)
!ll&&!rl&&r
000
MC/DC0%0/3
ref $this and overload::Overloaded($this) and overload::Method($this, "\"\"")
ref $this overload::Overloaded($this) overload::Method($this, "\"\"")
Truth table0%0/4
A and B and C
A= ref $thisB= overload::Overloaded($this)C= overload::Method($this, "\"\"")
ABCresult
0XX0
10X0
1100
1111
4163 {
4164 0 $a = $self->new_array( [split( /[[:blank:]\h]+/, "$this" )] );
4165 }
4166 else
4167 {
4168 0 return( $self->error( "I was expecting an array reference of classes, or class string or a code reference, but instead I got '$this', and I do not know what to do with it." ) );
4169 }
4170 # Make sure the classes we are provided are unique
4171 0 $a->unique(1);
4172 }
4173  
4174 0 my $process;
4175 $process = sub
4176 {
4177 0 ▶ my( $i, $e ) = @_;
Subroutine __ANON__: not called CC=15 SCAR=54.8
4178 0 my $ref = $e->internal->{class};
4179 0 ▶ $ref //= {};
Condition0%0/2
$ref //= {}
l!l
00
MC/DC0%0/1
$ref //= {}
$ref
Truth table0%0/2
A
A= $ref
Aresult
11
00
4180 0 ▶ $ref->{toggle_status} //= 0;
Condition0%0/2
$ref->{"toggle_status"} //= 0
l!l
00
MC/DC0%0/1
$ref->{"toggle_status"} //= 0
$ref->{"toggle_status"}
Truth table0%0/2
A
A= $ref->{"toggle_status"}
Aresult
11
00
4181 0 my $classes;
4182 0 ▶ if( $e->attributes->exists( 'class' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->attributes->exists("class")) 0 0 0
4183 {
4184 0 $classes = $self->new_array( [split( /[[:blank:]\h]+/, $e->attributes->get( 'class' ) )] );
4185 0 ▶ $ref->{original_classes} //= $classes;
Condition0%0/3
$ref->{"original_classes"} //= $classes
l!l&&r!l&&!r
000
MC/DC0%0/2
$ref->{"original_classes"} //= $classes
$ref->{"original_classes"} $classes
Truth table0%0/3
A //= B
A= $ref->{"original_classes"}B= $classes
ABresult
1X1
011
000
4186 }
4187 # No class on this element yet
4188  
4189 0 ▶ if( $has_code )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_code) 0 0 0
4190 {
4191 0 local $_ = $e;
4192 0 my $res = $this->( $i, $classes, $ref->{toggle_status} );
4193 0 ▶ if( $self->_is_array( $res ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_array($res)) { } 0 0 0
elsif (CORE::not ref $res or overload::Overloaded($res) and overload::Method($res, '""')) { } 0 0 0
4194 {
4195 0 $a = $self->new_array( $res );
4196 }
4197 ▶ elsif( !ref( $res ) || ( overload::Overloaded( $res ) && overload::Method( $res, '""' ) ) )
Condition0%0/6
CORE::not ref $res or overload::Overloaded($res) and overload::Method($res, "\"\"")
l!l&&r!l&&!r
000
overload::Overloaded($res) and overload::Method($res, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/3
CORE::not ref $res or overload::Overloaded($res) and overload::Method($res, "\"\"")
CORE::not ref $res overload::Overloaded($res) overload::Method($res, "\"\"")
Truth table0%0/4
not(A) or B and C
A= CORE::not ref $resB= overload::Overloaded($res)C= overload::Method($res, "\"\"")
ABCresult
1XX1
0111
00X0
0100
4198 {
4199 0 $a = $self->new_array( [ split( /[[:blank:]\h]+/, "$res" ) ] );
4200 }
4201 else
4202 {
4203 0 warn( "Code reference for class of element with tag \"", $e->tag, "\" returned '$this', but I do not know what to do with it.\n" );
4204 0 return( 1 );
4205 }
4206 0 $a->unique(1);
4207 }
4208  
4209 # No class set yet on this element
4210 0 ▶ if( !defined( $classes ) )
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::not defined $classes) { } 0 0 0
4211 {
4212 # and we have no class either, so we skip to the next element. Nothing to do here
4213 0 ▶ if( !$a->length )
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::not $a->length) { } 0 0 0
4214 {
4215 0 return(1);
4216 }
4217 # we activate our classes
4218 else
4219 {
4220 0 $ref->{toggle_status} = 1;
4221 0 $e->attributes->set( class => $a->join( ' ' ) );
4222 0 $e->reset(1);
4223 }
4224 }
4225 else
4226 {
4227 # we found existing class, and we toggled without specifying any
4228 # which mean we switch them all on/off
4229 0 ▶ if( !$a->length )
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::not $a->length) { } 0 0 0
4230 {
4231 0 ▶ $e->attributes->set( class => ( $ref->{toggle_status} ? $ref->{original_classes} : '' ) );
Branch: 1 branch
BranchTrueFalseTotal
$ref->{'toggle_status'} ? : 0 0 0
4232 }
4233 # Specific were provided. We toggle them on/off
4234 else
4235 {
4236 0 ▶ if( $ref->{toggle_status} )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->{'toggle_status'}) { } 0 0 0
4237 {
4238 0 $classes->remove( $a );
4239 }
4240 else
4241 {
4242 0 $classes->push( $a->list )->unique;
4243 }
4244 0 $e->attributes->set( class => $classes->join( ' ' ) );
4245 0 $e->reset(1);
4246 0 $ref->{toggle_status} = !$ref->{toggle_status};
4247 }
4248 }
4249 0 };
4250  
4251 0 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
4252 {
4253 0 $self->children->for( $process );
4254 }
4255 else
4256 {
4257 0 $process->( 0, $self );
4258 }
4259 }
4260  
4261 0 ▶sub to_number { return( HTML::Object::DOM::Number->new( shift->getValue ) ); }
Subroutine to_number: not called CC=1 SCAR=6.9
Pod documented
4262  
4263 0 ▶sub toString { return( shift->as_xml( @_ ) ); }
Subroutine toString: not called CC=1 SCAR=6.9
Pod documented
4264  
4265 sub uniqueSort
4266 {
4267 0 ▶ my $self = shift( @_ );
Subroutine uniqueSort: not called CC=3 SCAR=24.8
Pod undocumented
4268 0 my $collection = $self->new_collection;
4269 0 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
4270 {
4271 0 ▶ my $elems = xQuery->uniqueSort( $self->children ) ||
Condition0%0/2
'xQuery'->uniqueSort($self->children) || (return $self->pass_error('xQuery'->error))
l!l
00
MC/DC0%0/1
'xQuery'->uniqueSort($self->children) || (return $self->pass_error('xQuery'->error))
'xQuery'->uniqueSort($self->children)
Truth table0%0/2
A
A= 'xQuery'->uniqueSort($self->children)
Aresult
11
00
4272 return( $self->pass_error( xQuery->error ) );
4273 0 $collection->children->push( $elems->list );
4274 }
4275 else
4276 {
4277 0 $collection->children->push( $self );
4278 }
4279 0 return( $collection );
4280 }
4281  
4282 sub wrap
4283 {
4284 5 ▶ my $self = shift( @_ );
Subroutine wrap: called CC=25 SCAR=38.9
Pod undocumented
4285 5 my @args = @_;
4286 5 my( $this, $more ) = @args;
4287 5 ▶ return( $self->error( "Nothing was provided to wrap elements." ) ) if( !$this );
Branch: 1 branch
BranchTrueFalseTotal
unless $this 0 5 5
4288 5 my( $wrapper, $elems, $is_code );
4289 # "When you pass a collection object containing more than one element, or a selector matching more than one element, the first element will be used."
4290 5 ▶ if( $self->_is_a( $this => 'HTML::Object::Collection' ) )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_is_a($this, 'HTML::Object::Collection')) { } 0 5 5
elsif ($self->_is_a($this, 'HTML::Object::DOM::Element')) { } 0 5 5
elsif ($self->_is_code($this)) { } 1 4 5
4291 {
4292 0 ▶ return( $self->error( "Collection provided as wrapper is actually empty!" ) ) if( $this->children->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $this->children->is_empty 0 0 0
4293 0 $wrapper = $this->children->first;
4294 0 ▶ return( $self->error( "The first element of the collection provided did not yield an element object." ) ) if( !$self->_is_a( $wrapper => 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($wrapper, "HTML::Object::DOM::Element") 0 0 0
4295 }
4296 elsif( $self->_is_a( $this => 'HTML::Object::DOM::Element' ) )
4297 {
4298 0 $wrapper = $this;
4299 }
4300 elsif( $self->_is_code( $this ) )
4301 {
4302 1 $is_code = 1;
4303 1 $wrapper = $this;
4304 }
4305 # selector, html to parse
4306 else
4307 {
4308 4 ▶ my $tmp = xq( @args ) || return( $self->pass_error );
Condition50%1/2
xq(@args) || (return $self->pass_error)
l!l
40
MC/DC0%0/1
xq(@args) || (return $self->pass_error)
xq(@args)
Truth table50%1/2
A
A= xq(@args)
Aresult
11
00
4309 4 ▶ return( $self->error( "Selector or HTML provided as wrapper did not yield any wrapping element." ) ) if( $tmp->children->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->children->is_empty 0 4 4
4310 4 ▶ $wrapper = $tmp->children->first ||
Condition50%1/2
$tmp->children->first || (return $self->error('Collection returned from selector or HTML provided is empty.'))
l!l
40
MC/DC0%0/1
$tmp->children->first || (return $self->error('Collection returned from selector or HTML provided is empty.'))
$tmp->children->first
Truth table50%1/2
A
A= $tmp->children->first
Aresult
11
00
4311 return( $self->error( "Collection returned from selector or HTML provided is empty." ) );
4312 4 ▶ return( $self->error( "Collection returned from selector or HTML provided did not yield an element object." ) ) if( !$self->_is_a( $wrapper => 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($wrapper, "HTML::Object::DOM::Element") 0 4 4
4313 }
4314  
4315 5 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 5 0 5
4316 {
4317 5 $elems = $self->children;
4318 }
4319 else
4320 {
4321 0 $elems = $self->new_array( $self );
4322 }
4323  
4324 5 my $find_nested;
4325 $find_nested = sub
4326 {
4327 20 ▶ my( $el, $kids ) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.2
4328 20 my $n = $kids->length;
4329 20 ▶ if( !$n )
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not $n) { } 12 8 20
elsif ($n == 1) { } 8 0 8
4330 {
4331 12 return( $el );
4332 }
4333 elsif( $n == 1 )
4334 {
4335 8 return( $find_nested->( $kids->[0] => $kids->[0]->children ) );
4336 }
4337 else
4338 {
4339 0 return( '' );
4340 }
4341 5 };
4342  
4343 5 local $@;
4344 5 ▶ for( my $i = 0; $i < scalar( @$elems ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$elems) 12 5 17
4345 {
4346 12 my $e = $elems->[$i];
4347 12 my $parent = $e->parent;
4348 12 my $pos = $parent->children->pos( $e );
4349 12 ▶ return( $self->error( "Unable to find element No $i position in its parent." ) ) if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 12 12
4350 12 my $wrap;
4351 12 ▶ if( $is_code )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_code) { } 2 10 12
4352 {
4353 # try-catch
4354 my $rv = eval
4355 2 {
4356 2 local $_ = $e;
4357 2 $wrapper->( $i );
4358 };
4359 2 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
4360 {
4361 0 return( $self->error( "An error occurred executing the wrapper callback code reference for element at offset $i: $@" ) );
4362 }
4363 2 my $thingy;
4364 2 ▶ if( $self->_is_a( $rv => 'HTML::Object::Collection' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($rv, 'HTML::Object::Collection')) { } 0 2 2
elsif ($self->_is_a($rv, 'HTML::Object::DOM::Element')) { } 0 2 2
4365 {
4366 0 ▶ return( $self->error( "Collection provided as wrapper is actually empty!" ) ) if( $rv->children->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $rv->children->is_empty 0 0 0
4367 0 $thingy = $rv->children->first;
4368 0 ▶ return( $self->error( "The first element of the collection provided did not yield an element object." ) ) if( !$self->_is_a( $thingy => 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($thingy, "HTML::Object::DOM::Element") 0 0 0
4369 }
4370 elsif( $self->_is_a( $rv => 'HTML::Object::DOM::Element' ) )
4371 {
4372 0 $thingy = $rv;
4373 }
4374 # selector, html to parse
4375 else
4376 {
4377 2 ▶ my $tmp = xq( $rv, ( defined( $more ) ? $more : () ) ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
defined $more ? : 0 2 2
Condition50%1/2
xq($rv, defined $more ? $more : ()) || (return $self->pass_error)
l!l
20
MC/DC0%0/1
xq($rv, defined $more ? $more : ()) || (return $self->pass_error)
xq($rv, defined $more ? $more : ())
Truth table50%1/2
A
A= xq($rv, defined $more ? $more : ())
Aresult
11
00
4378 2 ▶ return( $self->error( "Selector or HTML returned from callback as wrapper did not yield any wrapping element." ) ) if( $tmp->children->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->children->is_empty 0 2 2
4379 2 ▶ $thingy = $tmp->children->first ||
Condition50%1/2
$tmp->children->first || (return $self->error('Collection returned from selector or HTML provided is empty.'))
l!l
20
MC/DC0%0/1
$tmp->children->first || (return $self->error('Collection returned from selector or HTML provided is empty.'))
$tmp->children->first
Truth table50%1/2
A
A= $tmp->children->first
Aresult
11
00
4380 return( $self->error( "Collection returned from selector or HTML provided is empty." ) );
4381 2 ▶ return( $self->error( "Collection returned from selector or HTML provided did not yield an element object." ) ) if( !$self->_is_a( $thingy => 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($thingy, "HTML::Object::DOM::Element") 0 2 2
4382 }
4383 2 $wrap = $thingy->clone;
4384 }
4385 else
4386 {
4387 10 $wrap = $wrapper->clone;
4388 }
4389 12 my $nested = $find_nested->( $wrap => $wrap->children );
4390 # $e->detach;
4391 12 $wrap->parent( $parent );
4392 12 $parent->children->splice( $pos, 1, $wrap );
4393 12 $nested->children->set( $e );
4394 12 $e->parent( $nested );
4395 }
4396 5 return( $self );
4397 }
4398  
4399 sub xp
4400 {
4401 5 ▶ my $self = shift( @_ );
Subroutine xp: called CC=2 SCAR=6.9
Pod documented
4402 5 ▶ unless( $XP )
Branch: 1 branch
BranchTrueFalseTotal
unless ($HTML::Object::DOM::Element::XP) 2 3 5
4403 {
4404 2 $XP = HTML::Object::XPath->new;
4405 }
4406 # $XP->debug( $self->debug );
4407 5 return( $XP );
4408 }
4409  
4410 # Ref: <https://api.jquery.com/Types/#jQuery>
4411 # xq( '#myId', $document )
4412 # xq( '<div />', { id => 'Pouec', class => 'Hello' } );
4413 # xq( '<html><head><title>Hello world</title></head><body>Hello!</body></html>' );
4414 # xq();
4415 sub xq
4416 {
4417 37 ▶ my( @args ) = @_;
Subroutine xq: called CC=28 SCAR=37.4
Pod undocumented
4418 # Check if this might be all some HTML::Object::DOM::Element objects passed to form a collection
4419 37 my $is_all_objects = 1;
4420 7 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
4421 37 my $opts =
4422 {
4423 xq_debug => $HTML::Object::xQuery::DEBUG,
4424 };
4425 37 ▶ if( scalar( @args ) > 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args > 1 and defined $args[-1] and ref $args[-1] eq "HASH" and exists $args[-1]{"xq_debug"}) 0 37 37
Condition77%7/9
scalar @args > 1 and defined $args[-1] and ref $args[-1] eq "HASH" and exists $args[-1]{"xq_debug"}
!ll&&!rl&&r
3340
scalar @args > 1 and defined $args[-1] and ref $args[-1] eq "HASH"
!ll&&!rl&&r
2854
scalar @args > 1 and defined $args[-1]
!ll&&!rl&&r
2809
MC/DC0%0/4
scalar @args > 1 and defined $args[-1] and ref $args[-1] eq "HASH" and exists $args[-1]{"xq_debug"}
scalar @args > 1 defined $args[-1] ref $args[-1] eq "HASH" exists $args[-1]{"xq_debug"}
Truth table60%3/5
A and B and C and D
A= scalar @args > 1B= defined $args[-1]C= ref $args[-1] eq "HASH"D= exists $args[-1]{"xq_debug"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
4426 defined( $args[-1] ) &&
4427 ref( $args[-1] ) eq 'HASH' &&
4428 CORE::exists( $args[-1]->{xq_debug} ) )
4429 {
4430 0 $opts = CORE::pop( @args );
4431 }
4432 # A dummy accessor
4433 37 my $self = HTML::Object::DOM::Element->new( debug => $opts->{xq_debug} );
4434 # We check if xq was not called with a bunch of HTML::Object::DOM::Element objects, such as:
4435 # $(@elements) or maybe xq(@elements), which would return a new collection.
4436 37 ▶ for( my $i = 0; $i < scalar( @args ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @args) 40 1 41
4437 {
4438 40 ▶ unless( $self->_is_a( $args[$i] => 'HTML::Object::DOM::Element' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($args[$i], "HTML::Object::DOM::Element")) 36 4 40
4439 {
4440 36 $is_all_objects = 0;
4441 36 last;
4442 }
4443 }
4444 # Shortcut
4445 37 ▶ if( $is_all_objects )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_all_objects) 1 36 37
4446 {
4447 1 my $collection = $self->new_collection( debug => $opts->{xq_debug} );
4448 1 $collection->children->set( @args );
4449 1 return( $collection );
4450 }
4451 36 my( $this, $more ) = @args;
4452 # e.g. $('<div />', { id => 'pouec', class => 'hello' });
4453 36 ▶ if( $this =~ /^$LOOK_LIKE_HTML/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($this =~ /^$HTML::Object::DOM::Element::LOOK_LIKE_HTML/) { } 14 22 36
elsif (!ref($this) || overload::Overloaded($this) && overload::Method($this, '""') and CORE::index("$this", "\n") == -1) { } 22 0 22
4454 {
4455 14 my $p = HTML::Object::DOM->new;
4456 14 $this = "$this";
4457 # We trim the string, so that leading and trailing space do not get counted
4458 14 $this =~ s/^[[:blank:]\h\v]+|[[:blank:]\h\v]+$//gs;
4459 my $doc = $p->parse_data( $this ) || do
4460 14 ▶ {
Condition33%1/3
$p->parse_data($this) || do {
l!l&&r!l&&!r
1400
MC/DC0%0/2
$p->parse_data($this) || do { $! = $p->error; return }
$p->parse_data($this) do { $! = $p->error; return }
Truth table33%1/3
A || B
A= $p->parse_data($this)B= do { $! = $p->error; return }
ABresult
1X1
011
000
4461 0 $! = $p->error;
4462 0 return;
4463 };
4464 # $doc is a HTML::Object::DOM::Document, which is not suitable, so we change it to a
4465 # collection object
4466 14 my $collection = $doc->new_collection;
4467 14 $collection->children( $doc->children );
4468 14 ▶ if( $doc->children->length == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($doc->children->length == 1) 14 0 14
4469 {
4470 14 my $e = $doc->children->first;
4471 # I do not use Module::Generic::_is_hash on purpose because I do not want to catch objects inadvertently
4472 # We found attributes, so we set them up now
4473 14 ▶ if( ref( $more ) CORE::eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $more eq "HASH") 4 10 14
4474 {
4475 4 ▶ my $debug = CORE::delete( $more->{_debug} ) if( CORE::exists( $more->{_debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $more->{"_debug"} 0 4 4
4476 4 $e->attributes->merge( $more );
4477 4 $e->debug( $debug );
4478 4 $collection->debug( $debug );
4479 }
4480 # We correct a situation where the user called for example $('<div />', { class => 'hello', id => 'pouec' });
4481 # And this would lead the parser to flag it to be empty, respecting the user decision,
4482 # but in this case, this is merely a short-hand notation to create a tag, and is not a
4483 # reflexion that this tag should indeed be treated as empty when it is not by standard
4484 # hus, we correct it here.
4485 14 ▶ if( $e->children->length == 0 && $e->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->children->length == 0 and $e->is_empty) 6 8 14
Condition100%3/3
$e->children->length == 0 and $e->is_empty
!ll&&!rl&&r
356
MC/DC100%2/2
$e->children->length == 0 and $e->is_empty
$e->children->length == 0 $e->is_empty
Truth table100%3/3
A and B
A= $e->children->length == 0B= $e->is_empty
ABresult
0X0
100
111
4486 {
4487 6 my $def = $p->get_definition( $e->tag );
4488 6 ▶ $e->is_empty(0) if( !$def->{is_empty} );
Branch: 1 branch
BranchTrueFalseTotal
unless $def->{"is_empty"} 6 0 6
4489 6 $e->close;
4490 }
4491 }
4492 14 return( $collection );
4493 }
4494 # Hmmm, I wanted to support $.parseXML and consequently allow $($xmlDoc), but our interface is really just tailored for HTML::Object::Element and not for XML::libXML, so all of the HTML::Object::XQuery methods would not work.
4495 # elsif( $self->_is_a( $this => 'XML::LibXML::Node' ) )
4496 # {
4497 # my $collection = $self->new_collection;
4498 # my @childnodes = $this->childNodes;
4499 # $collection->children->push( @childNodes );
4500 # return( $collection );
4501 # }
4502 ▶ elsif( ( !ref( $this ) || ( overload::Overloaded( $this ) && overload::Method( $this, '""' ) ) ) && CORE::index( "$this", "\n" ) == -1 )
Condition22%2/9
!ref($this) || overload::Overloaded($this) && overload::Method($this, "\"\"") and CORE::index("$this", "\n") == -1
!ll&&!rl&&r
0022
CORE::not ref $this or overload::Overloaded($this) and overload::Method($this, "\"\"")
l!l&&r!l&&!r
2200
overload::Overloaded($this) and overload::Method($this, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/4
!ref($this) || overload::Overloaded($this) && overload::Method($this, "\"\"") and CORE::index("$this", "\n") == -1
CORE::not ref $this overload::Overloaded($this) overload::Method($this, "\"\"") CORE::index("$this", "\n") == -1
Truth table16%1/6
not(A) or B and C and D
A= CORE::not ref $thisB= overload::Overloaded($this)C= overload::Method($this, "\"\"")D= CORE::index("$this", "\n") == -1
ABCDresult
00XX0
010X0
1XX00
01100
1XX11
01111
4503 {
4504 # e.g. $('div')
4505 22 ▶ if( !defined( $more ) )
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not defined $more) { } 18 4 22
elsif (CORE::not ref $more or ref $more and CORE::not $more->isa('HTML::Object::DOM::Element')) { } 1 3 4
4506 {
4507 # e.g. $('body')
4508 18 ▶ if( defined( $HTML::Object::DOM::GLOBAL_DOM ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $HTML::Object::DOM::GLOBAL_DOM) { } 18 0 18
4509 {
4510 18 ▶ my $collection = $HTML::Object::DOM::GLOBAL_DOM->find( $this ) || return;
Condition50%1/2
$HTML::Object::DOM::GLOBAL_DOM->find($this) || (return)
l!l
180
MC/DC0%0/1
$HTML::Object::DOM::GLOBAL_DOM->find($this) || (return)
$HTML::Object::DOM::GLOBAL_DOM->find($this)
Truth table50%1/2
A
A= $HTML::Object::DOM::GLOBAL_DOM->find($this)
Aresult
11
00
4511 18 $collection->debug( $self->debug );
4512 18 return( $collection );
4513 }
4514 else
4515 {
4516 0 ▶ warn( "No context was specified for '$this'. You need to provide some context to the selector by supplying an HTML::Object::DOM::Element object." ) if( $self->_is_warnings_enabled( 'HTML::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTML::Object") 0 0 0
4517 0 return( HTML::Object::DOM->error( "You need to provide some context to the selector by supplying an HTML::Object::DOM::Element object." ) );
4518 }
4519 }
4520 # e.g., with context: $('div', $element);
4521 ▶ elsif( !ref( $more ) || ( ref( $more ) && !$more->isa( 'HTML::Object::DOM::Element' ) ) )
Condition50%3/6
CORE::not ref $more or ref $more and CORE::not $more->isa("HTML::Object::DOM::Element")
l!l&&r!l&&!r
103
ref $more and CORE::not $more->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
030
MC/DC33%1/3
CORE::not ref $more or ref $more and CORE::not $more->isa("HTML::Object::DOM::Element")
CORE::not ref $more ref $more CORE::not $more->isa("HTML::Object::DOM::Element")
Truth table50%2/4
not(A) or B and not(C)
A= CORE::not ref $moreB= ref $moreC= CORE::not $more->isa("HTML::Object::DOM::Element")
ABCresult
1XX1
0111
00X0
0100
4522 {
4523 1 return( HTML::Object::DOM->error( "Context provided selector must be an element object. Got '", overload::StrVal( $more ), "'" ) );
4524 }
4525 3 ▶ my $collection = $more->find( $this ) || return( HTML::Object::DOM->pass_error( $more->error ) );
Condition50%1/2
$more->find($this) || (return 'HTML::Object::DOM'->pass_error($more->error))
l!l
30
MC/DC0%0/1
$more->find($this) || (return 'HTML::Object::DOM'->pass_error($more->error))
$more->find($this)
Truth table50%1/2
A
A= $more->find($this)
Aresult
11
00
4526 3 $collection->debug( $more->debug );
4527 3 return( $collection );
4528 }
4529 else
4530 {
4531 0 return( HTML::Object::DOM->error( "I do not know what to do with '$this'." ) );
4532 }
4533 }
4534  
4535 sub _append_prepend
4536 {
4537 0 ▶ my $self = shift( @_ );
Subroutine _append_prepend: not called CC=21 SCAR=61.4
4538 0 ▶ my $this = shift( @_ ) || return( $self->error( "Nothing was provided to append or prepend." ) );
Condition0%0/2
shift @_ || (return $self->error('Nothing was provided to append or prepend.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('Nothing was provided to append or prepend.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
4539 0 my $opts = $self->_get_args_as_hash( @_ );
4540 0 ▶ if( !exists( $opts->{action} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"action"}) 0 0 0
4541 {
4542 0 my @caller_info = caller(1);
4543 0 my $caller = [split( /::/, $caller_info[3])]->[-1];
4544 0 ▶ return( $self->error( "No action argument was provided and I am unable to guess it." ) ) if( $caller !~ /^(append|prepend)$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $caller =~ /^(append|prepend)$/ 0 0 0
4545 0 $opts->{action} = $caller;
4546 }
4547 0 ▶ return( $self->error( "Invalid value for argument \"action\": '$opts->{action}'" ) ) if( $opts->{action} !~ /^(append|prepend)$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"action"} =~ /^(append|prepend)$/ 0 0 0
4548 0 my $a;
4549 0 ▶ if( !ref( $this ) )
Branch: 4 branches
BranchTrueFalseTotal
if (CORE::not ref $this) { } 0 0 0
elsif ($self->_is_array($this)) { } 0 0 0
elsif ($self->_is_object($this)) { } 0 0 0
elsif (ref $this ne 'CODE') { } 0 0 0
4550 {
4551 0 my $p = $self->new_parser;
4552 0 ▶ $this = $p->parse_data( $this ) || return( $self->pass_error( $p->error ) );
Condition0%0/2
$p->parse_data($this) || (return $self->pass_error($p->error))
l!l
00
MC/DC0%0/1
$p->parse_data($this) || (return $self->pass_error($p->error))
$p->parse_data($this)
Truth table0%0/2
A
A= $p->parse_data($this)
Aresult
11
00
4553 0 $a = $self->new_array( [ $this ] );
4554 }
4555 elsif( $self->_is_array( $this ) )
4556 {
4557 # Make sure this is a Module::Generic::Array object
4558 0 $a = $self->new_array( $this );
4559 }
4560 elsif( $self->_is_object( $this ) )
4561 {
4562 0 ▶ return( $self->error( "Object provided '$this' (", overload::StrVal( $this ), ") is not an HTML::Object::DOM::Element object." ) ) if( !$this->isa( 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $this->isa("HTML::Object::DOM::Element") 0 0 0
4563 0 $a = $self->new_array( [ $this ] );
4564 }
4565 elsif( ref( $this ) ne 'CODE' )
4566 {
4567 0 return( $self->error( "I do not know what to do with '$this'. I was expecing an html string, or an HTML::Object::DOM::Element or an array of element objects or a collection object (HTML::Object::Collection) or a code reference." ) );
4568 }
4569  
4570 0 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
4571 {
4572 0 my $failed = 0;
4573 # Going through each object in the collection
4574 $self->children->for(sub
4575 {
4576 0 ▶ my( $i, $e ) = @_;
Subroutine __ANON__: not called CC=9 SCAR=45.0
4577 0 $e->reset(1);
4578 # will silently fail just like jQuery does
4579 0 my $parent = $e->parent;
4580 0 ▶ my $pos = $parent ? $parent->children->pos( $e ) : $i;
Branch: 1 branch
BranchTrueFalseTotal
$parent ? : 0 0 0
4581 0 ▶ if( ref( $this ) CORE::eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this eq "CODE") 0 0 0
4582 {
4583 0 local $_ = $e;
4584 0 my $res = $this->( $pos, $e->as_string );
4585 0 ▶ if( !defined( $res ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 0 0
4586 {
4587 0 $failed++;
4588 0 $self->error( "An error occurred while executing code reference to $opts->{action} html element(s). Code reference returned undef." );
4589 0 return(0);
4590 }
4591 0 ▶ if( $self->_is_object( $res ) && $res->isa( 'HTML::Object::DOM::Element' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_object($res) and $res->isa('HTML::Object::DOM::Element')) { } 0 0 0
elsif (overload::Overloaded($res) and overload::Method($res, '""')) { } 0 0 0
Condition0%0/3
$self->_is_object($res) and $res->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($res) and $res->isa("HTML::Object::DOM::Element")
$self->_is_object($res) $res->isa("HTML::Object::DOM::Element")
Truth table0%0/3
A and B
A= $self->_is_object($res)B= $res->isa("HTML::Object::DOM::Element")
ABresult
0X0
100
111
4592 {
4593 0 $a = $self->new_array( [ $res ] );
4594 }
4595 ▶ elsif( overload::Overloaded( $res ) && overload::Method( $res, '""' ) )
Condition0%0/3
overload::Overloaded($res) and overload::Method($res, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/2
overload::Overloaded($res) and overload::Method($res, "\"\"")
overload::Overloaded($res) overload::Method($res, "\"\"")
Truth table0%0/3
A and B
A= overload::Overloaded($res)B= overload::Method($res, "\"\"")
ABresult
0X0
100
111
4596 {
4597 0 my $elem = $self->new_parser( "$res" );
4598 0 ▶ if( !defined( $elem ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $elem) 0 0 0
4599 {
4600 0 $failed++;
4601 0 return(0);
4602 }
4603 0 $a = $self->new_array( [ $elem ] );
4604 }
4605 else
4606 {
4607 0 $failed++;
4608 0 $self->error( "Value returned from code reference to be used in $opts->{action}\(\) is neither a string nor a HTML::Object::DOM::Element, so I do not know what to do with it." );
4609 0 return(0);
4610 }
4611 }
4612 $a->foreach(sub
4613 {
4614 0 ▶ my $elem = $_->detach->clone;
Subroutine __ANON__: not called CC=3 SCAR=24.8
4615 0 $elem->parent( $e );
4616 0 ▶ if( $opts->{action} CORE::eq 'append' )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'action'} eq 'append') { } 0 0 0
elsif ($opts->{'action'} eq 'prepend') { } 0 0 0
4617 {
4618 0 $e->children->push( $elem );
4619 }
4620 elsif( $opts->{action} CORE::eq 'prepend' )
4621 {
4622 0 $e->children->unshift( $elem );
4623 }
4624 0 });
4625 0 });
4626 0 ▶ return if( $failed );
Branch: 1 branch
BranchTrueFalseTotal
if $failed 0 0 0
4627 }
4628 else
4629 {
4630 0 $self->reset(1);
4631 # will silently fail just like jQuery does
4632 0 my $parent = $self->parent;
4633 0 ▶ my $pos = $parent ? $parent->children->pos( $self ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$parent ? : 0 0 0
4634 0 ▶ if( ref( $this ) CORE::eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this eq "CODE") 0 0 0
4635 {
4636 0 local $_ = $self;
4637 0 my $res = $this->( $pos, $self->as_string );
4638 0 ▶ return( $self->error( "An error occurred while executing code reference to $opts->{action} html element(s). Code reference returned undef." ) ) if( !defined( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 0 0
4639 0 ▶ if( $self->_is_object( $res ) && $res->isa( 'HTML::Object::DOM::Element' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_object($res) and $res->isa('HTML::Object::DOM::Element')) { } 0 0 0
elsif (overload::Overloaded($res) and overload::Method($res, '""')) { } 0 0 0
Condition0%0/3
$self->_is_object($res) and $res->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($res) and $res->isa("HTML::Object::DOM::Element")
$self->_is_object($res) $res->isa("HTML::Object::DOM::Element")
Truth table0%0/3
A and B
A= $self->_is_object($res)B= $res->isa("HTML::Object::DOM::Element")
ABresult
0X0
100
111
4640 {
4641 0 $a = $self->new_array( [ $res ] );
4642 }
4643 ▶ elsif( overload::Overloaded( $res ) && overload::Method( $res, '""' ) )
Condition0%0/3
overload::Overloaded($res) and overload::Method($res, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/2
overload::Overloaded($res) and overload::Method($res, "\"\"")
overload::Overloaded($res) overload::Method($res, "\"\"")
Truth table0%0/3
A and B
A= overload::Overloaded($res)B= overload::Method($res, "\"\"")
ABresult
0X0
100
111
4644 {
4645 0 my $elem = $self->new_parser( "$res" );
4646 0 ▶ return if( !defined( $elem ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elem 0 0 0
4647 0 $a = $self->new_array( [ $elem ] );
4648 }
4649 else
4650 {
4651 0 return( $self->error( "Value returned from code reference to be used in $opts->{action}\(\) is neither a string nor a HTML::Object::DOM::Element, so I do not know what to do with it." ) );
4652 }
4653 }
4654 $a->foreach(sub
4655 {
4656 0 ▶ $_->detach();
Subroutine __ANON__: not called CC=3 SCAR=24.8
4657 0 $_->parent( $self );
4658 0 ▶ if( $opts->{action} CORE::eq 'append' )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'action'} eq 'append') { } 0 0 0
elsif ($opts->{'action'} eq 'prepend') { } 0 0 0
4659 {
4660 0 $self->children->push( $_ );
4661 }
4662 elsif( $opts->{action} CORE::eq 'prepend' )
4663 {
4664 0 $self->children->unshift( $_ );
4665 }
4666 0 });
4667 }
4668 0 return( $self );
4669 }
4670  
4671 # Takes html string; or
4672 # selector; or
4673 # element object; or
4674 # array of objects; or
4675 # collection
4676 # "If there is more than one target element, however, cloned copies of the inserted element will be created for each target except the last, and that new set (the original element plus clones) is returned."
4677 sub _append_prepend_to
4678 {
4679 1 ▶ my $self = shift( @_ );
Subroutine _append_prepend_to: called CC=23 SCAR=49.6
4680 1 ▶ my $this = shift( @_ ) || return( $self->error( "No target was provided to insert element." ) );
Condition50%1/2
shift @_ || (return $self->error('No target was provided to insert element.'))
l!l
10
MC/DC0%0/1
shift @_ || (return $self->error('No target was provided to insert element.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
4681 # For example: $sel->appendTo( 'body', $doc );
4682 1 ▶ my $context = shift( @_ ) if( $self->_is_a( $_[0] => 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_a($_[0], "HTML::Object::DOM::Element") 0 1 1
4683 1 my $opts = $self->_get_args_as_hash( @_ );
4684 1 ▶ if( !exists( $opts->{action} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"action"}) 0 1 1
4685 {
4686 0 my @caller_info = caller(1);
4687 0 my $caller = [split( /::/, $caller_info[3])]->[-1];
4688 0 ▶ return( $self->error( "No action argument was provided and I am unable to guess it." ) ) if( $caller !~ /^(appendTo|prependTo|append_to|prepend_to)$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $caller =~ /^(appendTo|prependTo|append_to|prepend_to)$/ 0 0 0
4689 0 $opts->{action} = ( $caller =~ /^(append|prepend)(?:To|_to)$/ )[0];
4690 }
4691 1 ▶ return( $self->error( "Invalid value for argument \"action\": '$opts->{action}'" ) ) if( $opts->{action} !~ /^(append|prepend)$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"action"} =~ /^(append|prepend)$/ 0 1 1
4692 1 my( $src, $dst );
4693 # A collection to be returned if there is more than 1 target
4694 1 my $collection = $self->new_collection;
4695 1 ▶ if( !ref( $this ) )
Branch: 3 branches
BranchTrueFalseTotal
if (CORE::not ref $this) { } 1 0 1
elsif ($self->_is_array($this)) { } 0 0 0
elsif ($self->_is_object($this)) { } 0 0 0
4696 {
4697 1 ▶ if( $self->_is_html( $this ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_html($this)) { } 0 1 1
4698 {
4699 0 my $p = $self->new_parser;
4700 0 ▶ $this = $p->parse_data( $this ) || return( $self->pass_error( $p->error ) );
Condition0%0/2
$p->parse_data($this) || (return $self->pass_error($p->error))
l!l
00
MC/DC0%0/1
$p->parse_data($this) || (return $self->pass_error($p->error))
$p->parse_data($this)
Truth table0%0/2
A
A= $p->parse_data($this)
Aresult
11
00
4701 0 $dst = $self->new_array( [ $this ] );
4702 }
4703 # otherwise this has to be a selector
4704 # TODO: Need to correct this and adjust the object used as a base for the find
4705 # since $self could very well be a dynamically created dom object
4706 else
4707 {
4708 1 ▶ if( !defined( $context ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not defined $context and defined $HTML::Object::DOM::GLOBAL_DOM) { } 1 0 1
elsif (CORE::not defined $context and $self->isa_collection and CORE::not $self->children->is_empty) { } 0 0 0
Condition33%1/3
CORE::not defined $context and defined $HTML::Object::DOM::GLOBAL_DOM
!ll&&!rl&&r
001
MC/DC0%0/2
CORE::not defined $context and defined $HTML::Object::DOM::GLOBAL_DOM
CORE::not defined $context defined $HTML::Object::DOM::GLOBAL_DOM
Truth table33%1/3
not(A) and B
A= CORE::not defined $contextB= defined $HTML::Object::DOM::GLOBAL_DOM
ABresult
0X0
100
111
4709 defined( $HTML::Object::DOM::GLOBAL_DOM ) )
4710 {
4711 1 $context = $HTML::Object::DOM::GLOBAL_DOM;
4712 }
4713 ▶ elsif( !defined( $context ) &&
Condition0%0/6
CORE::not defined $context and $self->isa_collection and CORE::not $self->children->is_empty
!ll&&!rl&&r
000
CORE::not defined $context and $self->isa_collection
!ll&&!rl&&r
000
MC/DC0%0/3
CORE::not defined $context and $self->isa_collection and CORE::not $self->children->is_empty
CORE::not defined $context $self->isa_collection CORE::not $self->children->is_empty
Truth table0%0/4
not(A) and B and not(C)
A= CORE::not defined $contextB= $self->isa_collectionC= CORE::not $self->children->is_empty
ABCresult
0XX0
10X0
1100
1111
4714 $self->isa_collection &&
4715 !$self->children->is_empty )
4716 {
4717 0 $context = $self->children->first->getRootNode;
4718 }
4719 1 ▶ $this = defined( $context ) ? $context->find( $this ) : $self->find( $this );
Branch: 1 branch
BranchTrueFalseTotal
defined $context ? : 1 0 1
4720 1 ▶ return( $self->pass_error ) unless( $this );
Branch: 1 branch
BranchTrueFalseTotal
unless $this 0 1 1
4721 # $dst = $self->new_array( [ $this ] );
4722 1 $dst = $this->children;
4723 }
4724 }
4725 elsif( $self->_is_array( $this ) )
4726 {
4727 # Make sure this is a Module::Generic::Array object
4728 0 $dst = $self->new_array( $this );
4729 }
4730 elsif( $self->_is_object( $this ) )
4731 {
4732 0 ▶ return( $self->error( "Object provided '$this' (", overload::StrVal( $this ), ") is not an HTML::Object::DOM::Element object." ) ) if( !$this->isa( 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $this->isa("HTML::Object::DOM::Element") 0 0 0
4733 0 $dst = $self->new_array( [ $this ] );
4734 }
4735 else
4736 {
4737 0 return( $self->error( "I do not know what to do with \"$this\". I was expecting a selector, html data, an element object or an array." ) );
4738 }
4739  
4740 # If the content to be inserted is a collection, we loop through it, duplicate each element and insert them
4741 1 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 1 0 1
4742 {
4743 1 $src = $self->children;
4744 }
4745 else
4746 {
4747 0 $src = $self->new_array( $self );
4748 }
4749  
4750 # If the target is just one element, we do not duplicate them, but simply move them
4751 1 ▶ if( $dst->length == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($dst->length == 1) { } 1 0 1
4752 {
4753 1 my $elem = $dst->first;
4754 1 my $parent = $elem->parent;
4755 1 ▶ return( 1 ) if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 1 1
4756 1 $elem->reset(1);
4757 1 my $pos = $parent->children->pos( $elem );
4758 1 ▶ return( $self->error( "Found a parent for tag \"", $elem->tag, "\", but somehow I could not find its position among its children elements." ) ) if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 1 1
4759 $src->foreach(sub
4760 {
4761 4 ▶ my $e = shift( @_ );
Subroutine __ANON__: called CC=3 SCAR=11.4
4762 # Making sure the content element is detached from its original parent
4763 4 $e->detach;
4764 4 $e->parent( $elem );
4765 4 $e->reset(1);
4766 4 ▶ if( $opts->{action} CORE::eq 'prepend' )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'action'} eq 'prepend') { } 0 4 4
elsif ($opts->{'action'} eq 'append') { } 4 0 4
4767 {
4768 0 $elem->children->unshift( $e );
4769 }
4770 elsif( $opts->{action} CORE::eq 'append' )
4771 {
4772 4 $elem->children->push( $e );
4773 }
4774 4 $collection->children->push( $e );
4775 1 });
4776 }
4777 # However, if the target contain multiple element, we clone the content element
4778 else
4779 {
4780 $dst->foreach(sub
4781 {
4782 0 ▶ my $elem = $_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
4783 0 my $parent = $elem->parent;
4784 0 ▶ return(1) if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
4785 0 $elem->reset(1);
4786 0 my $pos = $parent->children->pos( $elem );
4787 0 ▶ warn( "Found a parent for tag \"", $elem->tag, "\", but somehow I could not find its position among its children elements.\n" ) if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
4788 0 ▶ return(1) if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
4789 $src->foreach(sub
4790 {
4791 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=3 SCAR=24.8
4792 # Making sure the content element is detached from its original parent
4793 0 my $clone = $e->detach->clone;
4794 0 $clone->parent( $elem );
4795 0 $clone->reset(1);
4796 0 ▶ if( $opts->{action} CORE::eq 'prepend' )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'action'} eq 'prepend') { } 0 0 0
elsif ($opts->{'action'} eq 'append') { } 0 0 0
4797 {
4798 0 $elem->children->unshift( $clone );
4799 }
4800 elsif( $opts->{action} CORE::eq 'append' )
4801 {
4802 0 $elem->children->push( $clone );
4803 }
4804 0 $collection->children->push( $clone );
4805 0 });
4806 0 });
4807 }
4808 1 return( $collection );
4809 }
4810  
4811 # Takes html string (start with <tag...), text object (HTML::Object::DOM::Text), array or element object
4812 # or alternatively a code reference that returns the above
4813 sub _before_after
4814 {
4815 3 ▶ my $self = shift( @_ );
Subroutine _before_after: called CC=22 SCAR=52.1
4816 3 ▶ my $this = shift( @_ ) || return( $self->error( "Nothing was provided to insert before or after." ) );
Condition50%1/2
shift @_ || (return $self->error('Nothing was provided to insert before or after.'))
l!l
30
MC/DC0%0/1
shift @_ || (return $self->error('Nothing was provided to insert before or after.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
4817 3 my $opts = $self->_get_args_as_hash( @_ );
4818 3 ▶ if( !exists( $opts->{action} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"action"}) 0 3 3
4819 {
4820 0 my @caller_info = caller(1);
4821 0 my $caller = [split( /::/, $caller_info[3])]->[-1];
4822 0 ▶ return( $self->error( "No action argument was provided and I am unable to guess it." ) ) if( $caller !~ /^(before|after)$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $caller =~ /^(before|after)$/ 0 0 0
4823 0 $opts->{action} = $caller;
4824 }
4825 3 ▶ return( $self->error( "Invalid value for argument \"action\": '$opts->{action}'" ) ) if( $opts->{action} !~ /^(before|after)$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"action"} =~ /^(before|after)$/ 0 3 3
4826 3 my $a;
4827 3 ▶ if( !ref( $this ) )
Branch: 4 branches
BranchTrueFalseTotal
if (CORE::not ref $this) { } 3 0 3
elsif ($self->_is_array($this)) { } 0 0 0
elsif ($self->_is_object($this)) { } 0 0 0
elsif (ref $this ne 'CODE') { } 0 0 0
4828 {
4829 3 my $p = $self->new_parser;
4830 3 ▶ $this = $p->parse_data( $this ) || return( $self->pass_error( $p->error ) );
Condition50%1/2
$p->parse_data($this) || (return $self->pass_error($p->error))
l!l
30
MC/DC0%0/1
$p->parse_data($this) || (return $self->pass_error($p->error))
$p->parse_data($this)
Truth table50%1/2
A
A= $p->parse_data($this)
Aresult
11
00
4831 # $a = $self->new_array( [ $this ] );
4832 # $this is a HTML::Document; we take its children
4833 3 $a = $this->children;
4834 }
4835 elsif( $self->_is_array( $this ) )
4836 {
4837 # Make sure this is a Module::Generic::Array object
4838 0 $a = $self->new_array( $this );
4839 }
4840 elsif( $self->_is_object( $this ) )
4841 {
4842 0 ▶ return( $self->error( "Object provided '$this' (", overload::StrVal( $this ), ") is not an HTML::Object::DOM::Element object." ) ) if( !$this->isa( 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $this->isa("HTML::Object::DOM::Element") 0 0 0
4843 0 $a = $self->new_array( [ $this ] );
4844 }
4845 elsif( ref( $this ) ne 'CODE' )
4846 {
4847 0 return( $self->error( "I do not know what to do with '$this'. I was expecing an html string, or an HTML::Object::DOM::Element or an array of element objects or a collection object (HTML::Object::Collection) or a code reference." ) );
4848 }
4849  
4850 3 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 3 0 3
4851 {
4852 3 my $failed = 0;
4853 # Going through each object in the collection
4854 $self->children->for(sub
4855 {
4856 5 ▶ my( $i, $e ) = @_;
Subroutine __ANON__: called CC=12 SCAR=37.4
4857 5 $e->reset(1);
4858 # will silently fail just like jQuery does
4859 5 my $parent = $e->parent;
4860 5 ▶ return( 1 ) if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 5 5
4861 5 my $pos;
4862 5 ▶ if( $opts->{action} CORE::eq 'before' )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'action'} eq 'before') { } 2 3 5
elsif ($opts->{'action'} eq 'after') { } 3 0 3
4863 {
4864 2 $pos = $parent->children->pos( $e );
4865 }
4866 elsif( $opts->{action} CORE::eq 'after' )
4867 {
4868 # $pos = $parent->children->pos( $e->close_tag ? $e->close_tag : $e );
4869 3 $pos = $parent->children->pos( $e );
4870 }
4871 5 ▶ if( !defined( $pos ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pos) 0 5 5
4872 {
4873 0 $failed++;
4874 0 $self->error( "Element with tag \"", $e->tag, "\" has a parent, but I could not find it among its children elements." );
4875 0 return(0);
4876 }
4877 5 ▶ if( ref( $this ) CORE::eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this eq "CODE") 0 5 5
4878 {
4879 0 local $_ = $e;
4880 0 my $res = $this->( $pos, $e->as_string );
4881 0 ▶ if( !defined( $res ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 0 0
4882 {
4883 0 $failed++;
4884 0 $self->error( "An error occurred while executing code reference to $opts->{action} html element(s). Code reference returned undef." );
4885 0 return(0);
4886 }
4887 0 ▶ if( $self->_is_object( $res ) && $res->isa( 'HTML::Object::DOM::Element' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_object($res) and $res->isa('HTML::Object::DOM::Element')) { } 0 0 0
elsif (overload::Overloaded($res) and overload::Method($res, '""')) { } 0 0 0
Condition0%0/3
$self->_is_object($res) and $res->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($res) and $res->isa("HTML::Object::DOM::Element")
$self->_is_object($res) $res->isa("HTML::Object::DOM::Element")
Truth table0%0/3
A and B
A= $self->_is_object($res)B= $res->isa("HTML::Object::DOM::Element")
ABresult
0X0
100
111
4888 {
4889 0 $a = $self->new_array( [ $res ] );
4890 }
4891 ▶ elsif( overload::Overloaded( $res ) && overload::Method( $res, '""' ) )
Condition0%0/3
overload::Overloaded($res) and overload::Method($res, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/2
overload::Overloaded($res) and overload::Method($res, "\"\"")
overload::Overloaded($res) overload::Method($res, "\"\"")
Truth table0%0/3
A and B
A= overload::Overloaded($res)B= overload::Method($res, "\"\"")
ABresult
0X0
100
111
4892 {
4893 0 my $elem = $self->new_parser( "$res" );
4894 0 ▶ if( !defined( $elem ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $elem) 0 0 0
4895 {
4896 0 $failed++;
4897 0 return(0);
4898 }
4899 0 $a = $self->new_array( [ $elem ] );
4900 }
4901 else
4902 {
4903 0 $failed++;
4904 0 $self->error( "Value returned from code reference to be used in $opts->{action}\(\) is neither a string nor a HTML::Object::DOM::Element, so I do not know what to do with it." );
4905 0 return(0);
4906 }
4907 }
4908 $a->foreach(sub
4909 {
4910 5 ▶ my $elem = $_->clone;
Subroutine __ANON__: called CC=3 SCAR=11.0
4911 5 $elem->parent( $e );
4912 5 ▶ if( $opts->{action} CORE::eq 'before' )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'action'} eq 'before') { } 2 3 5
elsif ($opts->{'action'} eq 'after') { } 3 0 3
4913 {
4914 2 $parent->children->splice( $pos, 0, $_ );
4915 }
4916 elsif( $opts->{action} CORE::eq 'after' )
4917 {
4918 3 $parent->children->splice( $pos + 1, 0, $_ );
4919 }
4920 5 $pos++;
4921 5 });
4922 3 });
4923 3 ▶ return( $self->pass_error ) if( $failed );
Branch: 1 branch
BranchTrueFalseTotal
if $failed 0 3 3
4924 }
4925 else
4926 {
4927 # will silently fail just like jQuery does
4928 0 my $parent = $self->parent;
4929 0 ▶ return(1) if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
4930 0 my $pos = $parent->children->pos( $self );
4931 0 ▶ return( $self->error( "Element with tag \"", $self->tag, "\" has a parent, but I could not find it among its children elements." ) ) if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
4932 0 ▶ if( ref( $this ) CORE::eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this eq "CODE") 0 0 0
4933 {
4934 0 local $_ = $self;
4935 0 my $res = $this->( $pos, $self->as_string );
4936 0 ▶ return( $self->error( "An error occurred while executing code reference to $opts->{action} html element(s). Code reference returned undef." ) ) if( !defined( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 0 0
4937 0 ▶ if( $self->_is_object( $res ) && $res->isa( 'HTML::Object::DOM::Element' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_object($res) and $res->isa('HTML::Object::DOM::Element')) { } 0 0 0
elsif (overload::Overloaded($res) and overload::Method($res, '""')) { } 0 0 0
Condition0%0/3
$self->_is_object($res) and $res->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($res) and $res->isa("HTML::Object::DOM::Element")
$self->_is_object($res) $res->isa("HTML::Object::DOM::Element")
Truth table0%0/3
A and B
A= $self->_is_object($res)B= $res->isa("HTML::Object::DOM::Element")
ABresult
0X0
100
111
4938 {
4939 0 $a = $self->new_array( [ $res ] );
4940 }
4941 ▶ elsif( overload::Overloaded( $res ) && overload::Method( $res, '""' ) )
Condition0%0/3
overload::Overloaded($res) and overload::Method($res, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/2
overload::Overloaded($res) and overload::Method($res, "\"\"")
overload::Overloaded($res) overload::Method($res, "\"\"")
Truth table0%0/3
A and B
A= overload::Overloaded($res)B= overload::Method($res, "\"\"")
ABresult
0X0
100
111
4942 {
4943 0 my $elem = $self->new_parser( "$res" );
4944 0 ▶ return if( !defined( $elem ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elem 0 0 0
4945 0 $a = $self->new_array( [ $elem ] );
4946 }
4947 else
4948 {
4949 0 return( $self->error( "Value returned from code reference to be used in $opts->{action}\(\) is neither a string nor a HTML::Object::DOM::Element, so I do not know what to do with it." ) );
4950 }
4951 }
4952 $a->foreach(sub
4953 {
4954 0 ▶ $_->detach();
Subroutine __ANON__: not called CC=3 SCAR=24.8
4955 0 $_->parent( $self );
4956 0 $_->reset(1);
4957 0 ▶ if( $opts->{action} CORE::eq 'before' )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'action'} eq 'before') { } 0 0 0
elsif ($opts->{'action'} eq 'after') { } 0 0 0
4958 {
4959 0 $parent->children->splice( $pos, 0, $_ );
4960 }
4961 elsif( $opts->{action} CORE::eq 'after' )
4962 {
4963 0 $parent->children->splice( $pos + 1, 0, $_ );
4964 }
4965 0 });
4966 }
4967 3 return( $self );
4968 }
4969  
4970 sub _same_as
4971 {
4972 311 ▶ my $self = shift( @_ );
Subroutine _same_as: called CC=10 SCAR=29.6
4973 311 my $this = shift( @_ );
4974 311 ▶ return(0) if( !defined( $this ) || !$self->_is_object( $this ) || !$this->isa( 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this and $self->_is_object($this) and $this->isa("HTML::Object::DOM::Element") 85 226 311
Condition66%4/6
defined $this and $self->_is_object($this) and $this->isa("HTML::Object::DOM::Element")
!ll&&!rl&&r
850226
defined $this and $self->_is_object($this)
!ll&&!rl&&r
085226
MC/DC33%1/3
defined $this and $self->_is_object($this) and $this->isa("HTML::Object::DOM::Element")
defined $this $self->_is_object($this) $this->isa("HTML::Object::DOM::Element")
Truth table50%2/4
A and B and C
A= defined $thisB= $self->_is_object($this)C= $this->isa("HTML::Object::DOM::Element")
ABCresult
0XX0
10X0
1100
1111
4975 226 ▶ if( $this->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($this->isa_collection) { } 0 226 226
4976 {
4977 # We are not a collection, but the other is
4978 0 ▶ if( !$self->isa_collection )
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not $self->isa_collection) { } 0 0 0
elsif ($self->length == $this->length and $self->length == $self->filter($this)->length) { } 0 0 0
4979 {
4980 0 return(0);
4981 }
4982 # https://css-tricks.com/snippets/jquery/compare-jquery-objects/
4983 ▶ elsif( $self->length == $this->length &&
Condition0%0/3
$self->length == $this->length and $self->length == $self->filter($this)->length
!ll&&!rl&&r
000
MC/DC0%0/2
$self->length == $this->length and $self->length == $self->filter($this)->length
$self->length == $this->length $self->length == $self->filter($this)->length
Truth table0%0/3
A and B
A= $self->length == $this->lengthB= $self->length == $self->filter($this)->length
ABresult
0X0
100
111
4984 $self->length == $self->filter( $this )->length )
4985 {
4986 0 return(1);
4987 }
4988 else
4989 {
4990 0 return(0);
4991 }
4992 }
4993 else
4994 {
4995 226 ▶ return(0) if( $self->tag CORE::ne $this->tag );
Branch: 1 branch
BranchTrueFalseTotal
if $self->tag ne $this->tag 52 174 226
4996 174 ▶ return( $self->eid CORE::eq $this->eid ? 1: 0 );
Branch: 1 branch
BranchTrueFalseTotal
$self->eid eq $this->eid ? : 88 86 174
4997 }
4998 }
4999  
5000 # If argument is provided, pass a CSS::Object::Builder::Rule object
5001 # If no argument is provided, get a CSS::Object::Builder::Rule of the inline css, if any at all.
5002 # Returns undef if no css attribute is set yet.
5003 sub _css_object
5004 {
5005 0 ▶ my $self = shift( @_ );
Subroutine _css_object: not called CC=6 SCAR=37.4
5006 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
5007 {
5008 0 my $rule = shift( @_ );
5009 0 my $css = $rule->css;
5010 0 my $style = $rule->as_string;
5011 0 $self->css_cache_store( $style, $css );
5012 0 $self->attributes->set( css => $style );
5013 0 return( $rule );
5014 }
5015 else
5016 {
5017 0 my $style = $self->attributes->get( 'css' );
5018 0 ▶ return if( !defined( $style ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $style 0 0 0
5019 0 my $css = CSS::Object->new( format => 'CSS::Object::Format::Inline', debug => $self->debug );
5020 0 my $cached = $self->css_cache_check( $style );
5021 0 ▶ if( $cached )
Branch: 1 branch
BranchTrueFalseTotal
if ($cached) { } 0 0 0
5022 {
5023 0 $css = $cached;
5024 }
5025 else
5026 {
5027 ## 'inline' here is just a fake selector to serve as a container rule for the inline properties,
5028 ## because CSS::Object requires properties to be within a rule
5029 0 ▶ $css->read_string( 'inline {' . $style . ' }' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$css->read_string('inline {' . $style . ' }') or return $self->error("Unable to parse existing style for tag name \"", $self->prop("tagName"), "\":", $css->error) 0 0 0
5030 return( $self->error( "Unable to parse existing style for tag name \"", $self->prop( 'tagName' ), "\":", $css->error ) );
5031 }
5032 0 my $main = $css->rules->first;
5033 0 ▶ my $rule = defined( $main ) ? $css->builder->select( $main ) : $css->builder->select( 'inline' );
Branch: 1 branch
BranchTrueFalseTotal
defined $main ? : 0 0 0
5034 0 return( $rule );
5035 }
5036 }
5037  
5038 sub _css_builder
5039 {
5040 0 ▶ my $self = shift( @_ );
Subroutine _css_builder: not called CC=1 SCAR=6.9
5041 0 my $css = CSS::Object->new( format => 'CSS::Object::Format::Inline', debug => $self->debug );
5042 0 return( $css->builder->select( 'inline' ) );
5043 }
5044  
5045 # Private method : BFS (Breadth-First Search) on the sub-tree of $self, returns an array
5046 # of all the elements for which $test->($elem) is true. Ignores the nodes text/space/comment.
5047 sub _fast_find_by
5048 {
5049 24 ▶ my( $self, $test ) = @_;
Subroutine _fast_find_by: called CC=9 SCAR=22.0
5050 24 my $result = $self->new_array;
5051 # Racine(s) à parcourir
5052 24 my @roots;
5053 24 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 3 21 24
5054 {
5055 3 @roots = $self->children->list;
5056 }
5057 else
5058 {
5059 21 @roots = ( $self );
5060 }
5061 24 my @queue = @roots;
5062 24 ▶ while( @queue )
Branch: 1 branch
BranchTrueFalseTotal
if (@queue) 604 24 628
5063 {
5064 604 my $node = shift( @queue );
5065 # We only test on the true elements, no on Text, Space, or Comment
5066 604 ▶ if( $node->isa( 'HTML::Object::DOM::Element' ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("HTML::Object::DOM::Element") and $node->{"tag"} and substr(qq[$node->{"tag"}], 0, 1) ne "_") 216 388 604
Condition83%5/6
$node->isa("HTML::Object::DOM::Element") and $node->{"tag"} and substr(qq[$node->{"tag"}], 0, 1) ne "_"
!ll&&!rl&&r
36721216
$node->isa("HTML::Object::DOM::Element") and $node->{"tag"}
!ll&&!rl&&r
3670237
MC/DC66%2/3
$node->isa("HTML::Object::DOM::Element") and $node->{"tag"} and substr(qq[$node->{"tag"}], 0, 1) ne "_"
$node->isa("HTML::Object::DOM::Element") $node->{"tag"} substr(qq[$node->{"tag"}], 0, 1) ne "_"
Truth table75%3/4
A and B and C
A= $node->isa("HTML::Object::DOM::Element")B= $node->{"tag"}C= substr(qq[$node->{"tag"}], 0, 1) ne "_"
ABCresult
0XX0
10X0
1100
1111
5067 $node->{tag} &&
5068 substr( "$node->{tag}", 0, 1 ) ne '_' )
5069 {
5070 216 ▶ $result->push( $node ) if( $test->( $node ) );
Branch: 1 branch
BranchTrueFalseTotal
if &$test($node) 62 154 216
5071 }
5072 # Crawl down in te children if the method exists.
5073 604 ▶ if( $node->can( 'children' ) && $node->children->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($node->can("children") and $node->children->length) 147 457 604
Condition66%2/3
$node->can("children") and $node->children->length
!ll&&!rl&&r
0457147
MC/DC50%1/2
$node->can("children") and $node->children->length
$node->can("children") $node->children->length
Truth table66%2/3
A and B
A= $node->can("children")B= $node->children->length
ABresult
0X0
100
111
5074 {
5075 147 push( @queue, $node->children->list );
5076 }
5077 }
5078 24 return( $result );
5079 }
5080  
5081 # Takes selector, html, element or array
5082 # xq( '<p>Test</p>' )->insertBefore( xq( '.inner', $doc ) );
5083 # $elem->insertBefore( '.inner' );
5084 sub _insert_before_after
5085 {
5086 0 ▶ my $self = shift( @_ );
Subroutine _insert_before_after: not called CC=18 SCAR=58.3
5087 0 ▶ my $this = shift( @_ ) || return( $self->error( "No target was provided to insert element." ) );
Condition0%0/2
shift @_ || (return $self->error('No target was provided to insert element.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No target was provided to insert element.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
5088 0 my $opts = $self->_get_args_as_hash( @_ );
5089 0 ▶ if( !exists( $opts->{action} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"action"}) 0 0 0
5090 {
5091 0 my @caller_info = caller(1);
5092 0 my $caller = [split( /::/, $caller_info[3])]->[-1];
5093 0 ▶ return( $self->error( "No action argument was provided and I am unable to guess it." ) ) if( $caller !~ /^(?:insert|insert_)(?:Before|After)$/i );
Branch: 1 branch
BranchTrueFalseTotal
unless $caller =~ /^(?:insert|insert_)(?:Before|After)$/i 0 0 0
5094 0 $opts->{action} = lc( ( $caller =~ /^(?:insert|insert_)(?:Before|After)$/i )[0] );
5095 }
5096 0 ▶ return( $self->error( "Invalid value for argument \"action\": '$opts->{action}'" ) ) if( $opts->{action} !~ /^(?:before|after)$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"action"} =~ /^(?:before|after)$/ 0 0 0
5097 0 my $a;
5098 0 ▶ if( !ref( $this ) )
Branch: 3 branches
BranchTrueFalseTotal
if (CORE::not ref $this) { } 0 0 0
elsif ($self->_is_array($this)) { } 0 0 0
elsif ($self->_is_object($this)) { } 0 0 0
5099 {
5100 0 ▶ if( $self->_is_html( $this ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_html($this)) { } 0 0 0
5101 {
5102 0 my $p = $self->new_parser;
5103 0 ▶ $this = $p->parse_data( $this ) || return( $self->pass_error( $p->error ) );
Condition0%0/2
$p->parse_data($this) || (return $self->pass_error($p->error))
l!l
00
MC/DC0%0/1
$p->parse_data($this) || (return $self->pass_error($p->error))
$p->parse_data($this)
Truth table0%0/2
A
A= $p->parse_data($this)
Aresult
11
00
5104 0 $a = $self->new_array( [ $this ] );
5105 }
5106 # otherwise this has to be a selector
5107 # TODO: Need to correct this and adjust the object used as a base for the find
5108 # since $self could very well be a dynamically created dom object
5109 else
5110 {
5111 0 ▶ $this = $self->find( $this ) || return;
Condition0%0/2
$self->find($this) || (return)
l!l
00
MC/DC0%0/1
$self->find($this) || (return)
$self->find($this)
Truth table0%0/2
A
A= $self->find($this)
Aresult
11
00
5112 0 $a = $self->new_array( [ $this ] );
5113 }
5114 }
5115 elsif( $self->_is_array( $this ) )
5116 {
5117 # Make sure this is a Module::Generic::Array object
5118 0 $a = $self->new_array( $this );
5119 }
5120 elsif( $self->_is_object( $this ) )
5121 {
5122 0 ▶ return( $self->error( "Object provided '$this' (", overload::StrVal( $this ), ") is not an HTML::Object::DOM::Element object." ) ) if( !$this->isa( 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $this->isa("HTML::Object::DOM::Element") 0 0 0
5123 0 $a = $self->new_array( [ $this ] );
5124 }
5125 else
5126 {
5127 0 return( $self->error( "I do not know what to do with \"$this\". I was expecting a selector, html data, an element object or an array." ) );
5128 }
5129  
5130 # If the content to be inserted is a collection, we loop through it, duplicate each element and insert them
5131 0 ▶ if( $self->isa_collection )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa_collection) { } 0 0 0
5132 {
5133 $a->foreach(sub
5134 {
5135 0 ▶ my $elem = $_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
5136 0 my $parent = $elem->parent;
5137 0 ▶ return(1) if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
5138 0 $elem->reset(1);
5139 0 my $pos = $parent->children->pos( $elem );
5140 0 ▶ warn( "Found a parent for tag \"", $elem->tag, "\", but somehow I could not find its position among its children elements.\n" ) if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
5141 0 ▶ return(1) if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
5142 $self->children->foreach(sub
5143 {
5144 0 ▶ my $e = shift( @_ );
Subroutine __ANON__: not called CC=3 SCAR=24.8
5145 # Making sure the content element is detached from its original parent
5146 0 my $clone = $e->detach->clone;
5147 0 $clone->parent( $elem );
5148 0 ▶ if( $opts->{action} CORE::eq 'before' )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'action'} eq 'before') { } 0 0 0
elsif ($opts->{'action'} eq 'after') { } 0 0 0
5149 {
5150 0 $parent->children->splice( $pos, 0, $clone );
5151 }
5152 elsif( $opts->{action} CORE::eq 'after' )
5153 {
5154 0 $parent->children->splice( $pos + 1, 0, $clone );
5155 }
5156 0 });
5157 0 });
5158 }
5159 else
5160 {
5161 # If the target is just one element, we do not duplicate them, but simply move them
5162 0 ▶ if( $a->length == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($a->length == 1) { } 0 0 0
5163 {
5164 0 my $elem = $a->first;
5165 0 my $parent = $elem->parent;
5166 0 ▶ return(1) if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
5167 0 $elem->reset(1);
5168 0 my $pos = $parent->children->pos( $elem );
5169 0 ▶ return( $self->error( "Found a parent for tag \"", $elem->tag, "\", but somehow I could not find its position among its children elements." ) ) if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
5170 0 $self->detach;
5171 0 $self->parent( $elem );
5172 0 ▶ if( $opts->{action} CORE::eq 'before' )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'action'} eq 'before') { } 0 0 0
elsif ($opts->{'action'} eq 'after') { } 0 0 0
5173 {
5174 0 $parent->children->splice( $pos, 0, $self );
5175 }
5176 elsif( $opts->{action} CORE::eq 'after' )
5177 {
5178 0 $parent->children->splice( $pos + 1, 0, $self );
5179 }
5180 }
5181 # However, if the target contain multiple element, we clone the content element
5182 else
5183 {
5184 $a->foreach(sub
5185 {
5186 0 ▶ my $elem = $_;
Subroutine __ANON__: not called CC=6 SCAR=37.4
5187 0 my $parent = $elem->parent;
5188 0 ▶ return(1) if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
5189 0 $elem->reset(1);
5190 0 my $pos = $parent->children->pos( $elem );
5191 0 ▶ warn( "Found a parent for tag \"", $elem->tag, "\", but somehow I could not find its position among its children elements.\n" ) if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
5192 0 ▶ return(1) if( !defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
5193 0 my $clone = $self->detach->clone;
5194 0 $clone->parent( $elem );
5195 0 ▶ if( $opts->{action} CORE::eq 'before' )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'action'} eq 'before') { } 0 0 0
elsif ($opts->{'action'} eq 'after') { } 0 0 0
5196 {
5197 0 $parent->children->splice( $pos, 0, $clone );
5198 }
5199 elsif( $opts->{action} CORE::eq 'after' )
5200 {
5201 0 $parent->children->splice( $pos + 1, 0, $clone );
5202 }
5203 0 });
5204 }
5205 }
5206 0 return( $self );
5207 }
5208  
5209 1 ▶sub _is_html { return( $_[1] =~ /^[[:blank:]\h]*<\w+/ ? 1 : 0 ); }
Subroutine _is_html: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[1] =~ /^[[:blank:]\h]*<\w+/ ? : 0 1 1
5210  
5211 0 ▶sub _is_same_node { shift( @_ ); return( shift->eid CORE::eq shift->eid ); }
Subroutine _is_same_node: not called CC=1 SCAR=6.9
5212  
5213 2 ▶sub _xpath_value { shift( @_ ); return( ref( $_[0] ) ? ${$_[0]} : HTML::Selector::XPath::selector_to_xpath( $_[0] ) ); }
Subroutine _xpath_value: called CC=2 SCAR=8.1
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 2 2
5214  
5215 7 1;
5216 # NOTE: POD
5217 __END__
« blib/lib/HTML/Object/XQuery.pm ↑ Summary lib/HTML/Object/DOM/List.pm »