DOM/_Element.pm

filter: Statementstmt 41.6% 430 / 1032 Branchbran 31.3% 243 / 776 Conditioncond 30.8% 148 / 480 MC/DCmcdc 17.0% 46 / 270 Subroutinesub 46.9% 53 / 113 Podpod 0.0% 0 / 81 totaltotal 33.4% 920 / 2752 CC 598 SCAR 52.1
CC
598
Cov
36%
delete_ignorable_whitespace
992.0
__ANON__
600.0
same_as
552.0
CRAP 182.4
« DOM/_TreeBuilder.pm ↑ Summary DOM/EventTarget.pm »
1 # This is a fork of HTML::Element. Eventually the code may be merged.
2  
3 package HTML::DOM::_Element;
4  
5 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 28 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 28 ▶use HTML::Entities ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 28 ▶use HTML::Tagset ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 28 ▶use integer; # vroom vroom!
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 28 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 28 $VERSION = 4.2;
13  
14 # This contorls encoding entities on output.
15 # When set entities won't be re-encoded.
16 # Defaulting off because parser defaults to unencoding entities
17 28 our $encoded_content = 0;
18  
19 28 ▶use vars qw($html_uc $Debug $ID_COUNTER %list_type_to_sub);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 28 ▶$Debug = 0 unless defined $Debug;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $HTML::DOM::_Element::Debug 28 0 28
22  
23 0 ▶sub Version { $VERSION; }
Subroutine Version: not called CC=1 SCAR=6.9
Pod undocumented
24  
25 28 my $nillio = [];
26  
27 28 *HTML::DOM::_Element::emptyElement = \%HTML::Tagset::emptyElement; # legacy
28 28 *HTML::DOM::_Element::optionalEndTag = \%HTML::Tagset::optionalEndTag; # legacy
29 28 *HTML::DOM::_Element::linkElements = \%HTML::Tagset::linkElements; # legacy
30 28 *HTML::DOM::_Element::boolean_attr = \%HTML::Tagset::boolean_attr; # legacy
31 28 *HTML::DOM::_Element::canTighten = \%HTML::Tagset::canTighten; # legacy
32  
33 # Constants for signalling back to the traverser:
34 28 my $travsignal_package = __PACKAGE__ . '::_travsignal';
35 my ( $ABORT, $PRUNE, $PRUNE_SOFTLY, $OK, $PRUNE_UP )
36 28 = map { my $x = $_; bless \$x, $travsignal_package; }
37 qw(
38 ABORT PRUNE PRUNE_SOFTLY OK PRUNE_UP
39 );
40  
41 ## Comments from Father Chrysostomos RT #58880
42 ## The sole purpose for empty parentheses after a sub name is to make it
43 ## parse as a 0-ary (nihilary?) function. I.e., ABORT+1 should parse as
44 ## ABORT()+1, not ABORT(+1). The parentheses also tell perl that it can
45 ### be inlined.
46 ##Deparse is really useful for demonstrating this:
47 ##$ perl -MO=Deparse,-p -e 'sub ABORT {7} print ABORT+8'
48 # Vs
49 # perl -MO=Deparse,-p -e 'sub ABORT() {7} print ABORT+8'
50 #
51 # With the parentheses, it not only makes it parse as a term.
52 # It even resolves the constant at compile-time, making the code run faster.
53  
54 ## no critic
55 0 ▶sub ABORT () {$ABORT}
Subroutine ABORT: not called CC=1 SCAR=6.9
Pod undocumented
56 0 ▶sub PRUNE () {$PRUNE}
Subroutine PRUNE: not called CC=1 SCAR=6.9
Pod undocumented
57 0 ▶sub PRUNE_SOFTLY () {$PRUNE_SOFTLY}
Subroutine PRUNE_SOFTLY: not called CC=1 SCAR=6.9
Pod undocumented
58 0 ▶sub OK () {$OK}
Subroutine OK: not called CC=1 SCAR=6.9
Pod undocumented
59 0 ▶sub PRUNE_UP () {$PRUNE_UP}
Subroutine PRUNE_UP: not called CC=1 SCAR=6.9
Pod undocumented
60 ## use critic
61  
62 28 $html_uc = 0;
63  
64 # set to 1 if you want tag and attribute names from starttag and endtag
65 # to be uc'd
66  
67 # regexs for XML names
68 # http://www.w3.org/TR/2006/REC-xml11-20060816/NT-NameStartChar
69 28 my $START_CHAR
70 = qr/(?:\:|[A-Z]|_|[a-z]|[\x{C0}-\x{D6}]|[\x{D8}-\x{F6}]|[\x{F8}-\x{2FF}]|[\x{370}-\x{37D}]|[\x{37F}-\x{1FFF}]|[\x{200C}-\x{200D}]|[\x{2070}-\x{218F}]|[\x{2C00}-\x{2FEF}]|[\x{3001}-\x{D7FF}]|[\x{F900}-\x{FDCF}]|[\x{FDF0}-\x{FFFD}]|[\x{10000}-\x{EFFFF}])/;
71  
72 # http://www.w3.org/TR/2006/REC-xml11-20060816/#NT-NameChar
73 28 my $NAME_CHAR
74 = qr/(?:$START_CHAR|-|\.|[0-9]|\x{B7}|[\x{0300}-\x{036F}]|[\x{203F}-\x{2040}])/;
75  
76 # Elements that does not have corresponding end tags (i.e. are empty)
77  
78 #==========================================================================
79  
80 #
81 # An HTML::DOM::_Element is represented by blessed hash reference, much like
82 # Tree::DAG_Node objects. Key-names not starting with '_' are reserved
83 # for the SGML attributes of the element.
84 # The following special keys are used:
85 #
86 # '_tag': The tag name (i.e., the generic identifier)
87 # '_parent': A reference to the HTML::DOM::_Element above (when forming a tree)
88 # '_pos': The current position (a reference to a HTML::DOM::_Element) is
89 # where inserts will be placed (look at the insert_element
90 # method) If not set, the implicit value is the object itself.
91 # '_content': A ref to an array of nodes under this.
92 # It might not be set.
93 #
94 # Example: <img src="gisle.jpg" alt="Gisle's photo"> is represented like this:
95 #
96 # bless {
97 # _tag => 'img',
98 # src => 'gisle.jpg',
99 # alt => "Gisle's photo",
100 # }, 'HTML::DOM::_Element';
101 #
102  
103 2001 ▶sub new {
Subroutine new: called CC=8 SCAR=21.5
Pod undocumented
104 2001 my $class = shift;
105 2001 ▶ $class = ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
020010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
106  
107 2001 my $tag = shift;
108 2001 ▶ Carp::croak("No tagname") unless defined $tag and length $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag and length $tag 0 2001 2001
Condition33%1/3
defined $tag and length $tag
!ll&&!rl&&r
002001
MC/DC0%0/2
defined $tag and length $tag
defined $tag length $tag
Truth table33%1/3
A and B
A= defined $tagB= length $tag
ABresult
0X0
100
111
109 2001 ▶ Carp::croak "\"$tag\" isn't a good tag name!"
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ m[[<>/\x00-\x20]] 0 2001 2001
110 if $tag =~ m/[<>\/\x00-\x20]/; # minimal sanity, certainly!
111 2001 my $self = bless { _tag => scalar( $class->_fold_case($tag) ) }, $class;
112 2001 my ( $attr, $val );
113 2001 ▶ while ( ( $attr, $val ) = splice( @_, 0, 2 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 1092 2001 3093
114 ## RT #42209 why does this default to the attribute name and not remain unset or the empty string?
115 1092 ▶ $val = $attr unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 7 1085 1092
116 1092 $self->{ $class->_fold_case($attr) } = $val;
117 }
118 2001 ▶ if ( $tag eq 'html' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "html") 147 1854 2001
119 147 $self->{'_pos'} = undef;
120 }
121 2001 return $self;
122 }
123  
124 9867 ▶sub attr {
Subroutine attr: called CC=3 SCAR=11.0
Pod undocumented
125 9867 my $self = shift;
126 9867 my $attr = scalar( $self->_fold_case(shift) );
127 9867 ▶ if (@_) { # set
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1396 8471 9867
128 1396 ▶ if ( defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) { } 1333 63 1396
129 1333 my $old = $self->{$attr};
130 1333 $self->{$attr} = $_[0];
131 1333 return $old;
132 }
133 else { # delete, actually
134 63 return delete $self->{$attr};
135 }
136 }
137 else { # get
138 8471 return $self->{$attr};
139 }
140 }
141  
142 8541 ▶sub tag {
Subroutine tag: called CC=2 SCAR=6.9
Pod undocumented
143 8541 my $self = shift;
144 8541 ▶ if (@_) { # set
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 8540 8541
145 1 $self->{'_tag'} = $self->_fold_case( $_[0] );
146 }
147 else { # get
148 8540 $self->{'_tag'};
149 }
150 }
151  
152 5466 ▶sub parent {
Subroutine parent: called CC=5 SCAR=17.8
Pod undocumented
153 5466 my $self = shift;
154 5466 ▶ if (@_) { # set
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 7 5459 5466
155 7 ▶ Carp::croak "an element can't be made its own parent"
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and ref $_[0] and $self eq $_[0] 0 7 7
Condition33%2/6
defined $_[0] and ref $_[0] and $self eq $_[0]
!ll&&!rl&&r
700
defined $_[0] and ref $_[0]
!ll&&!rl&&r
700
MC/DC0%0/3
defined $_[0] and ref $_[0] and $self eq $_[0]
defined $_[0] ref $_[0] $self eq $_[0]
Truth table25%1/4
A and B and C
A= defined $_[0]B= ref $_[0]C= $self eq $_[0]
ABCresult
0XX0
10X0
1100
1111
156 if defined $_[0] and ref $_[0] and $self eq $_[0]; # sanity
157 7 $self->{'_parent'} = $_[0];
158 }
159 else {
160 5459 $self->{'_parent'}; # get
161 }
162 }
163  
164 5397 ▶sub content_list {
Subroutine content_list: called CC=4 SCAR=13.9
Pod undocumented
165 return wantarray
166 5247 ▶ ? @{ shift->{'_content'} || return () }
Condition100%2/2
+(shift())->{'_content'} || (return ())
l!l
31052142
MC/DC100%1/1
+(shift())->{'_content'} || (return ())
+(shift())->{'_content'}
Truth table100%2/2
A
A= +(shift())->{'_content'}
Aresult
11
00
167 5397 ▶ : scalar @{ shift->{'_content'} || return 0 };
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5247 150 5397
Condition100%2/2
+(shift())->{'_content'} || (return 0)
l!l
12327
MC/DC100%1/1
+(shift())->{'_content'} || (return 0)
+(shift())->{'_content'}
Truth table100%2/2
A
A= +(shift())->{'_content'}
Aresult
11
00
168 }
169  
170 # a read-only method! can't say $h->content( [] )!
171 0 ▶sub content {
Subroutine content: not called CC=1 SCAR=6.9
Pod undocumented
172 0 return shift->{'_content'};
173 }
174  
175 23 ▶sub content_array_ref {
Subroutine content_array_ref: called CC=2 SCAR=6.9
Pod undocumented
176 23 ▶ return shift->{'_content'} ||= [];
Condition100%2/2
+(shift())->{"_content"} ||= []
l!l
176
MC/DC100%1/1
+(shift())->{"_content"} ||= []
+(shift())->{"_content"}
Truth table100%2/2
A
A= +(shift())->{"_content"}
Aresult
11
00
177 }
178  
179 0 ▶sub content_refs_list {
Subroutine content_refs_list: not called CC=2 SCAR=17.9
Pod undocumented
180 0 ▶ return \( @{ shift->{'_content'} || return () } );
Condition0%0/2
+(shift())->{'_content'} || (return ())
l!l
00
MC/DC0%0/1
+(shift())->{'_content'} || (return ())
+(shift())->{'_content'}
Truth table0%0/2
A
A= +(shift())->{'_content'}
Aresult
11
00
181 }
182  
183 94 ▶sub implicit {
Subroutine implicit: called CC=1 SCAR=0.0
Pod undocumented
184 94 return shift->attr( '_implicit', @_ );
185 }
186  
187 18 ▶sub pos {
Subroutine pos: called CC=5 SCAR=25.2
Pod undocumented
188 18 my $self = shift;
189 18 my $pos = $self->{'_pos'};
190 18 ▶ if (@_) { # set
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 18 18
191 0 my $parm = shift;
192 0 ▶ if ( defined $parm and $parm ne $self ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parm and $parm ne $self) { } 0 0 0
Condition0%0/3
defined $parm and $parm ne $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $parm and $parm ne $self
defined $parm $parm ne $self
Truth table0%0/3
A and B
A= defined $parmB= $parm ne $self
ABresult
0X0
100
111
193 0 $self->{'_pos'} = $parm; # means that element
194 }
195 else {
196 0 $self->{'_pos'} = undef; # means $self
197 }
198 }
199 18 ▶ return $pos if defined($pos);
Branch: 1 branch
BranchTrueFalseTotal
if defined $pos 18 0 18
200 0 return $self;
201 }
202  
203 0 ▶sub all_attr {
Subroutine all_attr: not called CC=1 SCAR=6.9
Pod undocumented
204 0 return %{ $_[0] };
205  
206 # Yes, trivial. But no other way for the user to do the same
207 # without breaking encapsulation.
208 # And if our object representation changes, this method's behavior
209 # should stay the same.
210 }
211  
212 0 ▶sub all_attr_names {
Subroutine all_attr_names: not called CC=1 SCAR=6.9
Pod undocumented
213 0 return keys %{ $_[0] };
214 }
215  
216 0 ▶sub all_external_attr {
Subroutine all_external_attr: not called CC=3 SCAR=24.8
Pod undocumented
217 0 my $self = $_[0];
218 return map( ( length($_) && substr( $_, 0, 1 ) eq '_' )
219 ? ()
220 0 ▶ : ( $_, $self->{$_} ),
Branch: 1 branch
BranchTrueFalseTotal
length $_ && substr($_, 0, 1) eq '_' ? : 0 0 0
Condition0%0/3
length $_ and substr($_, 0, 1) eq "_"
!ll&&!rl&&r
000
MC/DC0%0/2
length $_ and substr($_, 0, 1) eq "_"
length $_ substr($_, 0, 1) eq "_"
Truth table0%0/3
A and B
A= length $_B= substr($_, 0, 1) eq "_"
ABresult
0X0
100
111
221 keys %$self );
222 }
223  
224 24 ▶sub all_external_attr_names {
Subroutine all_external_attr_names: called CC=2 SCAR=7.1
Pod undocumented
225 24 ▶ return grep !( length($_) && substr( $_, 0, 1 ) eq '_' ), keys %{ $_[0] };
Condition66%2/3
length $_ && substr($_, 0, 1) eq '_'
!ll&&!rl&&r
03894
MC/DC50%1/2
length $_ && substr($_, 0, 1) eq '_'
length $_ substr($_, 0, 1) eq '_'
Truth table66%2/3
A && B
A= length $_B= substr($_, 0, 1) eq '_'
ABresult
0X0
100
111
226 }
227  
228 996 ▶sub id {
Subroutine id: called CC=4 SCAR=23.7
Pod undocumented
229 996 ▶ if ( @_ == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1) { } 996 0 996
elsif (@_ == 2) { } 0 0 0
230 996 return $_[0]{'id'};
231 }
232 elsif ( @_ == 2 ) {
233 0 ▶ if ( defined $_[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) { } 0 0 0
234 0 return $_[0]{'id'} = $_[1];
235 }
236 else {
237 0 return delete $_[0]{'id'};
238 }
239 }
240 else {
241 0 Carp::croak '$node->id can\'t take ' . scalar(@_) . ' parameters!';
242 }
243 }
244  
245 0 ▶sub _gensym {
Subroutine _gensym: not called CC=2 SCAR=17.9
246 0 ▶ unless ( defined $ID_COUNTER ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $HTML::DOM::_Element::ID_COUNTER) 0 0 0
247  
248 # start it out...
249 0 $ID_COUNTER = sprintf( '%04x', rand(0x1000) );
250 0 $ID_COUNTER =~ tr<0-9a-f><J-NP-Z>; # yes, skip letter "oh"
251 0 $ID_COUNTER .= '00000';
252 }
253 0 ++$ID_COUNTER;
254 }
255  
256 0 ▶sub idf {
Subroutine idf: not called CC=6 SCAR=37.4
Pod undocumented
257 0 my $nparms = scalar @_;
258  
259 0 ▶ if ( $nparms == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nparms == 1) 0 0 0
260 0 my $x;
261 0 ▶ if ( defined( $x = $_[0]{'id'} ) and length $x ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($x = $_[0]{'id'}) and length $x) { } 0 0 0
Condition0%0/3
defined($x = $_[0]{"id"}) and length $x
!ll&&!rl&&r
000
MC/DC0%0/2
defined($x = $_[0]{"id"}) and length $x
defined($x = $_[0]{"id"}) length $x
Truth table0%0/3
A and B
A= defined($x = $_[0]{"id"})B= length $x
ABresult
0X0
100
111
262 0 return $x;
263 }
264 else {
265 0 return $_[0]{'id'} = _gensym();
266 }
267 }
268 0 ▶ if ( $nparms == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nparms == 2) 0 0 0
269 0 ▶ if ( defined $_[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) { } 0 0 0
270 0 return $_[0]{'id'} = $_[1];
271 }
272 else {
273 0 return delete $_[0]{'id'};
274 }
275 }
276 0 Carp::croak '$node->idf can\'t take ' . scalar(@_) . ' parameters!';
277 }
278  
279 1555 ▶sub push_content {
Subroutine push_content: called CC=9 SCAR=23.2
Pod undocumented
280 1555 my $self = shift;
281 1555 ▶ return $self unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 1555 1555
282  
283 1555 ▶ my $content = ( $self->{'_content'} ||= [] );
Condition100%2/2
$self->{"_content"} ||= []
l!l
817738
MC/DC100%1/1
$self->{"_content"} ||= []
$self->{"_content"}
Truth table100%2/2
A
A= $self->{"_content"}
Aresult
11
00
284 1555 for (@_) {
285 1571 ▶ if ( ref($_) eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_ eq 'ARRAY') { } 0 1571 1571
elsif (ref $_) { } 1070 501 1571
286  
287 # magically call new_from_lol
288 0 push @$content, $self->new_from_lol($_);
289 0 $content->[-1]->{'_parent'} = $self;
290 }
291 elsif ( ref($_) ) { # insert an element
292 1070 ▶ $_->detach if $_->{'_parent'};
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"_parent"} 43 1027 1070
293 1070 $_->{'_parent'} = $self;
294 1070 push( @$content, $_ );
295 }
296 else { # insert text segment
297 501 ▶ if ( @$content && !ref $content->[-1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$content and not ref $content->[-1]) { } 0 501 501
Condition66%2/3
@$content and not ref $content->[-1]
!ll&&!rl&&r
2652360
MC/DC0%0/2
@$content and not ref $content->[-1]
@$content not ref $content->[-1]
Truth table66%2/3
A and not(B)
A= @$contentB= not ref $content->[-1]
ABresult
0X0
100
111
298  
299 # last content element is also text segment -- append
300 0 $content->[-1] .= $_;
301 }
302 else {
303 501 push( @$content, $_ );
304 }
305 }
306 }
307 1555 return $self;
308 }
309  
310 8 ▶sub unshift_content {
Subroutine unshift_content: called CC=9 SCAR=27.9
Pod undocumented
311 8 my $self = shift;
312 8 ▶ return $self unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 8 8
313  
314 8 ▶ my $content = ( $self->{'_content'} ||= [] );
Condition100%2/2
$self->{"_content"} ||= []
l!l
53
MC/DC100%1/1
$self->{"_content"} ||= []
$self->{"_content"}
Truth table100%2/2
A
A= $self->{"_content"}
Aresult
11
00
315 8 for ( reverse @_ ) { # so they get added in the order specified
316 8 ▶ if ( ref($_) eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_ eq 'ARRAY') { } 0 8 8
elsif (ref $_) { } 8 0 8
317  
318 # magically call new_from_lol
319 0 unshift @$content, $self->new_from_lol($_);
320 0 $content->[0]->{'_parent'} = $self;
321 }
322 elsif ( ref $_ ) { # insert an element
323 8 ▶ $_->detach if $_->{'_parent'};
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"_parent"} 2 6 8
324 8 $_->{'_parent'} = $self;
325 8 unshift( @$content, $_ );
326 }
327 else { # insert text segment
328 0 ▶ if ( @$content && !ref $content->[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$content and not ref $content->[0]) { } 0 0 0
Condition0%0/3
@$content and not ref $content->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@$content and not ref $content->[0]
@$content not ref $content->[0]
Truth table0%0/3
A and not(B)
A= @$contentB= not ref $content->[0]
ABresult
0X0
100
111
329  
330 # last content element is also text segment -- prepend
331 0 $content->[0] = $_ . $content->[0];
332 }
333 else {
334 0 unshift( @$content, $_ );
335 }
336 }
337 }
338 8 return $self;
339 }
340  
341 # Cf. splice ARRAY,OFFSET,LENGTH,LIST
342  
343 515 ▶sub splice_content {
Subroutine splice_content: called CC=10 SCAR=24.6
Pod undocumented
344 515 my ( $self, $offset, $length, @to_add ) = @_;
345 515 ▶ Carp::croak "splice_content requires at least one argument"
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 0 515 515
346 if @_ < 2; # at least $h->splice_content($offset);
347 515 ▶ return $self unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 515 515
348  
349 515 ▶ my $content = ( $self->{'_content'} ||= [] );
Condition100%2/2
$self->{"_content"} ||= []
l!l
5132
MC/DC100%1/1
$self->{"_content"} ||= []
$self->{"_content"}
Truth table100%2/2
A
A= $self->{"_content"}
Aresult
11
00
350  
351 # prep the list
352  
353 515 my @out;
354 515 ▶ if ( @_ > 2 ) { # self, offset, length, ...
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 2) { } 515 0 515
355 515 foreach my $n (@to_add) {
356 517 ▶ if ( ref($n) eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $n eq 'ARRAY') { } 0 517 517
elsif (ref $n) { } 517 0 517
357 0 $n = $self->new_from_lol($n);
358 0 $n->{'_parent'} = $self;
359 }
360 elsif ( ref($n) ) {
361 517 $n->detach;
362 517 $n->{'_parent'} = $self;
363 }
364 }
365 515 @out = splice @$content, $offset, $length, @to_add;
366 }
367 else { # self, offset
368 0 @out = splice @$content, $offset;
369 }
370 515 foreach my $n (@out) {
371 502 ▶ $n->{'_parent'} = undef if ref $n;
Branch: 1 branch
BranchTrueFalseTotal
if ref $n 1 501 502
372 }
373 515 return @out;
374 }
375  
376 661 ▶sub detach {
Subroutine detach: called CC=4 SCAR=14.0
Pod undocumented
377 661 my $self = $_[0];
378 661 ▶ return unless ( my $parent = $self->{'_parent'} );
Branch: 1 branch
BranchTrueFalseTotal
unless my $parent = $self->{"_parent"} 545 116 661
379 116 $self->{'_parent'} = undef;
380 116 ▶ my $cohort = $parent->{'_content'} || return $parent;
Condition50%1/2
$parent->{'_content'} || (return $parent)
l!l
1160
MC/DC0%0/1
$parent->{'_content'} || (return $parent)
$parent->{'_content'}
Truth table50%1/2
A
A= $parent->{'_content'}
Aresult
11
00
381 116 ▶ @$cohort = grep { not( ref($_) and $_ eq $self ) } @$cohort;
Condition66%2/3
ref $_ && $_ eq $self
!ll&&!rl&&r
0224116
MC/DC50%1/2
ref $_ && $_ eq $self
ref $_ $_ eq $self
Truth table66%2/3
A && B
A= ref $_B= $_ eq $self
ABresult
0X0
100
111
382  
383 # filter $self out, if parent has any evident content
384  
385 116 return $parent;
386 }
387  
388 102 ▶sub detach_content {
Subroutine detach_content: called CC=4 SCAR=13.9
Pod undocumented
389 102 ▶ my $c = $_[0]->{'_content'} || return (); # in case of no content
Condition100%2/2
$_[0]{'_content'} || (return ())
l!l
5250
MC/DC100%1/1
$_[0]{'_content'} || (return ())
$_[0]{'_content'}
Truth table100%2/2
A
A= $_[0]{'_content'}
Aresult
11
00
390 52 for (@$c) {
391 51 ▶ $_->{'_parent'} = undef if ref $_;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ 51 0 51
392 }
393 52 return splice @$c;
394 }
395  
396 41 ▶sub replace_with {
Subroutine replace_with: called CC=13 SCAR=28.5
Pod undocumented
397 41 my ( $self, @replacers ) = @_;
398 Carp::croak "the target node has no parent"
399 41 ▶ unless my ($parent) = $self->{'_parent'};
Branch: 1 branch
BranchTrueFalseTotal
unless my($parent) = $self->{"_parent"} 0 41 41
400  
401 41 my $parent_content = $parent->{'_content'};
402 41 ▶ Carp::croak "the target node's parent has no content!?"
Branch: 1 branch
BranchTrueFalseTotal
unless $parent_content and @$parent_content 0 41 41
Condition33%1/3
$parent_content and @$parent_content
!ll&&!rl&&r
0041
MC/DC0%0/2
$parent_content and @$parent_content
$parent_content @$parent_content
Truth table33%1/3
A and B
A= $parent_contentB= @$parent_content
ABresult
0X0
100
111
403 unless $parent_content and @$parent_content;
404  
405 41 my $replacers_contains_self;
406 41 for (@replacers) {
407 65 ▶ if ( !ref $_ ) {
Branch: 4 branches
BranchTrueFalseTotal
if (not ref $_) { } 0 65 65
elsif ($_ eq $self) { } 23 42 65
elsif ($_ eq $parent) { } 0 42 42
elsif (ref $_ eq 'ARRAY') { } 0 42 42
408  
409 # noop
410 }
411 elsif ( $_ eq $self ) {
412  
413 # noop, but check that it's there just once.
414 23 ▶ Carp::croak "Replacement list contains several copies of target!"
Branch: 1 branch
BranchTrueFalseTotal
if $replacers_contains_self++ 0 23 23
415 if $replacers_contains_self++;
416 }
417 elsif ( $_ eq $parent ) {
418 0 Carp::croak "Can't replace an item with its parent!";
419 }
420 elsif ( ref($_) eq 'ARRAY' ) {
421 0 $_ = $self->new_from_lol($_);
422 0 $_->{'_parent'} = $parent;
423 }
424 else {
425 42 $_->detach;
426 42 $_->{'_parent'} = $parent;
427  
428 # each of these are necessary
429 }
430 } # for @replacers
431 41 ▶ @$parent_content = map { ( ref($_) and $_ eq $self ) ? @replacers : $_ }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ && $_ eq $self ? : 41 36 77
Condition66%2/3
ref $_ and $_ eq $self
!ll&&!rl&&r
03641
MC/DC50%1/2
ref $_ and $_ eq $self
ref $_ $_ eq $self
Truth table66%2/3
A and B
A= ref $_B= $_ eq $self
ABresult
0X0
100
111
432 @$parent_content;
433  
434 41 ▶ $self->{'_parent'} = undef unless $replacers_contains_self;
Branch: 1 branch
BranchTrueFalseTotal
unless $replacers_contains_self 18 23 41
435  
436 # if replacers does contain self, then the parent attribute is fine as-is
437  
438 41 return $self;
439 }
440  
441 13 ▶sub preinsert {
Subroutine preinsert: called CC=2 SCAR=7.1
Pod undocumented
442 13 my $self = shift;
443 13 ▶ return $self unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 13 13
444 13 return $self->replace_with( @_, $self );
445 }
446  
447 10 ▶sub postinsert {
Subroutine postinsert: called CC=2 SCAR=7.1
Pod undocumented
448 10 my $self = shift;
449 10 ▶ return $self unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 10 10
450 10 return $self->replace_with( $self, @_ );
451 }
452  
453 0 ▶sub replace_with_content {
Subroutine replace_with_content: not called CC=9 SCAR=45.0
Pod undocumented
454 0 my $self = $_[0];
455 Carp::croak "the target node has no parent"
456 0 ▶ unless my ($parent) = $self->{'_parent'};
Branch: 1 branch
BranchTrueFalseTotal
unless my($parent) = $self->{"_parent"} 0 0 0
457  
458 0 my $parent_content = $parent->{'_content'};
459 0 ▶ Carp::croak "the target node's parent has no content!?"
Branch: 1 branch
BranchTrueFalseTotal
unless $parent_content and @$parent_content 0 0 0
Condition0%0/3
$parent_content and @$parent_content
!ll&&!rl&&r
000
MC/DC0%0/2
$parent_content and @$parent_content
$parent_content @$parent_content
Truth table0%0/3
A and B
A= $parent_contentB= @$parent_content
ABresult
0X0
100
111
460 unless $parent_content and @$parent_content;
461  
462 0 ▶ my $content_r = $self->{'_content'} || [];
Condition0%0/2
$self->{'_content'} || []
l!l
00
MC/DC0%0/1
$self->{'_content'} || []
$self->{'_content'}
Truth table0%0/2
A
A= $self->{'_content'}
Aresult
11
00
463 0 ▶ @$parent_content = map { ( ref($_) and $_ eq $self ) ? @$content_r : $_ }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ && $_ eq $self ? : 0 0 0
Condition0%0/3
ref $_ and $_ eq $self
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ and $_ eq $self
ref $_ $_ eq $self
Truth table0%0/3
A and B
A= ref $_B= $_ eq $self
ABresult
0X0
100
111
464 @$parent_content;
465  
466 0 $self->{'_parent'} = undef; # detach $self from its parent
467  
468 # Update parentage link, removing from $self's content list
469 0 ▶ for ( splice @$content_r ) { $_->{'_parent'} = $parent if ref $_ }
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ 0 0 0
470  
471 0 return $self; # note: doesn't destroy it.
472 }
473  
474 45 ▶sub delete_content {
Subroutine delete_content: called CC=4 SCAR=13.9
Pod undocumented
475 45 for (
476 splice @{
477 45 ▶ delete( $_[0]->{'_content'} )
Condition100%2/2
delete $_[0]{'_content'} || (return $_[0])
l!l
387
MC/DC100%1/1
delete $_[0]{'_content'} || (return $_[0])
delete $_[0]{'_content'}
Truth table100%2/2
A
A= delete $_[0]{'_content'}
Aresult
11
00
478  
479 # Deleting it here (while holding its value, for the moment)
480 # will keep calls to detach() from trying to uselessly filter
481 # the list (as they won't be able to see it once it's been
482 # deleted)
483 || return ( $_[0] ) # in case of no content
484 },
485 0
486  
487 # the splice is so we can null the array too, just in case
488 # something somewhere holds a ref to it
489 )
490 {
491 61 ▶ $_->delete if ref $_;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ 61 0 61
492 }
493 38 $_[0];
494 }
495  
496 # two handy aliases
497 0 ▶sub destroy { shift->delete(@_) }
Subroutine destroy: not called CC=1 SCAR=6.9
Pod undocumented
498 0 ▶sub destroy_content { shift->delete_content(@_) }
Subroutine destroy_content: not called CC=1 SCAR=6.9
Pod undocumented
499  
500 154 ▶sub delete {
Subroutine delete: called CC=5 SCAR=16.1
Pod undocumented
501 154 my $self = $_[0];
502 $self->delete_content # recurse down
503 154 ▶ if $self->{'_content'} && @{ $self->{'_content'} };
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_content"} and @{$self->{"_content"};} 19 135 154
Condition100%3/3
$self->{"_content"} and @{$self->{"_content"};}
!ll&&!rl&&r
134119
MC/DC100%2/2
$self->{"_content"} and @{$self->{"_content"};}
$self->{"_content"} @{$self->{"_content"};}
Truth table100%3/3
A and B
A= $self->{"_content"}B= @{$self->{"_content"};}
ABresult
0X0
100
111
504  
505 154 ▶ $self->detach if $self->{'_parent'} and $self->{'_parent'}{'_content'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_parent"} and $self->{"_parent"}{"_content"} 6 148 154
Condition100%3/3
$self->{"_parent"} and $self->{"_parent"}{"_content"}
!ll&&!rl&&r
87616
MC/DC100%2/2
$self->{"_parent"} and $self->{"_parent"}{"_content"}
$self->{"_parent"} $self->{"_parent"}{"_content"}
Truth table100%3/3
A and B
A= $self->{"_parent"}B= $self->{"_parent"}{"_content"}
ABresult
0X0
100
111
506  
507 # not the typical case
508  
509 154 %$self = (); # null out the whole object on the way out
510 154 return;
511 }
512  
513 272 ▶sub clone {
Subroutine clone: called CC=7 SCAR=19.8
Pod undocumented
514  
515 #print "Cloning $_[0]\n";
516 272 my $it = shift;
517 272 ▶ Carp::croak "clone() can be called only as an object method"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $it 0 272 272
518 unless ref $it;
519 272 ▶ Carp::croak "clone() takes no arguments" if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 272 272
520  
521 272 my $new = bless {%$it}, ref($it); # COPY!!! HOOBOY!
522 272 delete @$new{ '_content', '_parent', '_pos', '_head', '_body' };
523  
524 # clone any contents
525 272 ▶ if ( $it->{'_content'} and @{ $it->{'_content'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($it->{"_content"} and @{$it->{"_content"};}) 114 158 272
Condition66%2/3
$it->{"_content"} and @{$it->{"_content"};}
!ll&&!rl&&r
1580114
MC/DC50%1/2
$it->{"_content"} and @{$it->{"_content"};}
$it->{"_content"} @{$it->{"_content"};}
Truth table66%2/3
A and B
A= $it->{"_content"}B= @{$it->{"_content"};}
ABresult
0X0
100
111
526 $new->{'_content'}
527 114 = [ ref($it)->clone_list( @{ $it->{'_content'} } ) ];
528 114 for ( @{ $new->{'_content'} } ) {
529 202 ▶ $_->{'_parent'} = $new if ref $_;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ 202 0 202
530 }
531 }
532  
533 272 return $new;
534 }
535  
536 114 ▶sub clone_list {
Subroutine clone_list: called CC=3 SCAR=11.7
Pod undocumented
537 114 ▶ Carp::croak "clone_list can be called only as a class method"
Branch: 1 branch
BranchTrueFalseTotal
if ref shift @_ 0 114 114
538 if ref shift @_;
539  
540 # all that does is get me here
541 return map {
542 114 ▶ ref($_)
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 202 0 202
543 ? $_->clone # copy by method
544 : $_ # copy by evaluation
545 } @_;
546 }
547  
548 0 ▶sub normalize_content {
Subroutine normalize_content: not called CC=14 SCAR=53.5
Pod undocumented
549 0 my $start = $_[0];
550 0 my $c;
551 return
552 0 ▶ unless $c = $start->{'_content'} and ref $c and @$c; # nothing to do
Branch: 1 branch
BranchTrueFalseTotal
unless $c = $start->{"_content"} and ref $c and @$c 0 0 0
Condition0%0/6
$c = $start->{"_content"} and ref $c and @$c
!ll&&!rl&&r
000
$c = $start->{"_content"} and ref $c
!ll&&!rl&&r
000
MC/DC0%0/3
$c = $start->{"_content"} and ref $c and @$c
$c = $start->{"_content"} ref $c @$c
Truth table0%0/4
A and B and C
A= $c = $start->{"_content"}B= ref $cC= @$c
ABCresult
0XX0
10X0
1100
1111
553 # TODO: if we start having text elements, deal with catenating those too?
554 0 my @stretches = (undef); # start with a barrier
555  
556 # I suppose this could be rewritten to treat stretches as it goes, instead
557 # of at the end. But feh.
558  
559 # Scan:
560 0 ▶ for ( my $i = 0; $i < @$c; ++$i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$c) 0 0 0
561 0 ▶ if ( defined $c->[$i] and ref $c->[$i] ) { # not a text segment
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c->[$i] and ref $c->[$i]) { } 0 0 0
Condition0%0/3
defined $c->[$i] and ref $c->[$i]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $c->[$i] and ref $c->[$i]
defined $c->[$i] ref $c->[$i]
Truth table0%0/3
A and B
A= defined $c->[$i]B= ref $c->[$i]
ABresult
0X0
100
111
562 0 ▶ if ( $stretches[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stretches[0]) 0 0 0
563  
564 # put in a barrier
565 0 ▶ if ( $stretches[0][1] == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stretches[0][1] == 1) { } 0 0 0
566  
567 #print "Nixing stretch at ", $i-1, "\n";
568 0 undef $stretches[0]; # nix the previous one-node "stretch"
569 }
570 else {
571  
572 #print "End of stretch at ", $i-1, "\n";
573 0 unshift @stretches, undef;
574 }
575 }
576  
577 # else no need for a barrier
578 }
579 else { # text segment
580 0 ▶ $c->[$i] = '' unless defined $c->[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c->[$i] 0 0 0
581 0 ▶ if ( $stretches[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stretches[0]) { } 0 0 0
582 0 ++$stretches[0][1]; # increase length
583 }
584 else {
585  
586 #print "New stretch at $i\n";
587 0 unshift @stretches, [ $i, 1 ]; # start and length
588 }
589 }
590 }
591  
592 # Now combine. Note that @stretches is in reverse order, so the indexes
593 # still make sense as we work our way thru (i.e., backwards thru $c).
594 0 foreach my $s (@stretches) {
595 0 ▶ if ( $s and $s->[1] > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s and $s->[1] > 1) 0 0 0
Condition0%0/3
$s and $s->[1] > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$s and $s->[1] > 1
$s $s->[1] > 1
Truth table0%0/3
A and B
A= $sB= $s->[1] > 1
ABresult
0X0
100
111
596  
597 #print "Stretch at ", $s->[0], " for ", $s->[1], "\n";
598 0 $c->[ $s->[0] ]
599 .= join( '', splice( @$c, $s->[0] + 1, $s->[1] - 1 ) )
600  
601 # append the subsequent ones onto the first one.
602 }
603 }
604 0 return;
605 }
606  
607 0 ▶sub delete_ignorable_whitespace {
Subroutine delete_ignorable_whitespace: not called CC=31 SCAR=69.0
Pod undocumented
608  
609 # This doesn't delete all sorts of whitespace that won't actually
610 # be used in rendering, tho -- that's up to the rendering application.
611 # For example:
612 # <input type='text' name='foo'>
613 # [some whitespace]
614 # <input type='text' name='bar'>
615 # The WS between the two elements /will/ get used by the renderer.
616 # But here:
617 # <input type='hidden' name='foo' value='1'>
618 # [some whitespace]
619 # <input type='text' name='bar' value='2'>
620 # the WS between them won't be rendered in any way, presumably.
621  
622 #my $Debug = 4;
623 0 ▶ die "delete_ignorable_whitespace can be called only as an object method"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 0 0 0
624 unless ref $_[0];
625  
626 0 ▶ print "About to tighten up...\n" if $Debug > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $HTML::DOM::_Element::Debug > 2 0 0 0
627 0 my (@to_do) = ( $_[0] ); # Start off.
628 0 my ( $i, $sibs, $ptag, $this ); # scratch for the loop...
629 0 ▶ while (@to_do) {
Branch: 1 branch
BranchTrueFalseTotal
if (@to_do) 0 0 0
630 0 ▶ if ( ( $ptag = ( $this = shift @to_do )->{'_tag'} ) eq 'pre'
Branch: 1 branch
BranchTrueFalseTotal
if (($ptag = +($this = shift @to_do)->{"_tag"}) eq "pre" or $ptag eq "textarea" or $HTML::Tagset::isCDATA_Parent{$ptag}) 0 0 0
Condition0%0/6
($ptag = +($this = shift @to_do)->{"_tag"}) eq "pre" or $ptag eq "textarea" or $HTML::Tagset::isCDATA_Parent{$ptag}
l!l&&r!l&&!r
000
($ptag = +($this = shift @to_do)->{"_tag"}) eq "pre" or $ptag eq "textarea"
l!l&&r!l&&!r
000
MC/DC0%0/3
($ptag = +($this = shift @to_do)->{"_tag"}) eq "pre" or $ptag eq "textarea" or $HTML::Tagset::isCDATA_Parent{$ptag}
($ptag = +($this = shift @to_do)->{"_tag"}) eq "pre" $ptag eq "textarea" $HTML::Tagset::isCDATA_Parent{$ptag}
Truth table0%0/4
A or B or C
A= ($ptag = +($this = shift @to_do)->{"_tag"}) eq "pre"B= $ptag eq "textarea"C= $HTML::Tagset::isCDATA_Parent{$ptag}
ABCresult
1XX1
01X1
0011
0000
631 or $ptag eq 'textarea'
632 or $HTML::Tagset::isCDATA_Parent{$ptag} )
633 {
634  
635 # block the traversal under those
636 0 ▶ print "Blocking traversal under $ptag\n" if $Debug;
Branch: 1 branch
BranchTrueFalseTotal
if $HTML::DOM::_Element::Debug 0 0 0
637 0 next;
638 }
639 0 ▶ next unless ( $sibs = $this->{'_content'} and @$sibs );
Branch: 1 branch
BranchTrueFalseTotal
unless $sibs = $this->{"_content"} and @$sibs 0 0 0
Condition0%0/3
$sibs = $this->{"_content"} and @$sibs
!ll&&!rl&&r
000
MC/DC0%0/2
$sibs = $this->{"_content"} and @$sibs
$sibs = $this->{"_content"} @$sibs
Truth table0%0/3
A and B
A= $sibs = $this->{"_content"}B= @$sibs
ABresult
0X0
100
111
640 0 ▶ for ( $i = $#$sibs; $i >= 0; --$i ) { # work backwards thru the list
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 0 0 0
641 0 ▶ if ( ref $sibs->[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sibs->[$i]) 0 0 0
642 0 unshift @to_do, $sibs->[$i];
643  
644 # yes, this happens in pre order -- we're going backwards
645 # thru this sibling list. I doubt it actually matters, tho.
646 0 next;
647 }
648 0 ▶ next if $sibs->[$i] =~ m<[^\n\r\f\t ]>s; # it's /all/ whitespace
Branch: 1 branch
BranchTrueFalseTotal
if $sibs->[$i] =~ /[^\n\r\f\t ]/s 0 0 0
649  
650 print "Under $ptag whose canTighten ",
651 0 ▶ "value is ", 0 + $HTML::DOM::_Element::canTighten{$ptag}, ".\n"
Branch: 1 branch
BranchTrueFalseTotal
if $HTML::DOM::_Element::Debug > 3 0 0 0
652 if $Debug > 3;
653  
654 # It's all whitespace...
655  
656 0 ▶ if ( $i == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i == 0) { } 0 0 0
elsif ($i == $sibs->$#*) { } 0 0 0
657 0 ▶ if ( @$sibs == 1 ) { # I'm an only child
Branch: 1 branch
BranchTrueFalseTotal
if (@$sibs == 1) { } 0 0 0
658 0 ▶ next unless $HTML::DOM::_Element::canTighten{$ptag}; # parent
Branch: 1 branch
BranchTrueFalseTotal
unless $HTML::DOM::_Element::canTighten{$ptag} 0 0 0
659 }
660 else { # I'm leftmost of many
661 # if either my parent or sib are eligible, I'm good.
662 next
663 unless $HTML::DOM::_Element::canTighten{$ptag} # parent
664 or (ref $sibs->[1]
665 and $HTML::DOM::_Element::canTighten{ $sibs->[1]
666 0 ▶ {'_tag'} } # right sib
Branch: 1 branch
BranchTrueFalseTotal
unless $HTML::DOM::_Element::canTighten{$ptag} or ref $sibs->[1] and $HTML::DOM::_Element::canTighten{$sibs->[1]{"_tag"}} 0 0 0
Condition0%0/6
$HTML::DOM::_Element::canTighten{$ptag} or ref $sibs->[1] and $HTML::DOM::_Element::canTighten{$sibs->[1]{"_tag"}}
l!l&&r!l&&!r
000
ref $sibs->[1] and $HTML::DOM::_Element::canTighten{$sibs->[1]{"_tag"}}
!ll&&!rl&&r
000
MC/DC0%0/3
$HTML::DOM::_Element::canTighten{$ptag} or ref $sibs->[1] and $HTML::DOM::_Element::canTighten{$sibs->[1]{"_tag"}}
$HTML::DOM::_Element::canTighten{$ptag} ref $sibs->[1] $HTML::DOM::_Element::canTighten{$sibs->[1]{"_tag"}}
Truth table0%0/4
A or B and C
A= $HTML::DOM::_Element::canTighten{$ptag}B= ref $sibs->[1]C= $HTML::DOM::_Element::canTighten{$sibs->[1]{"_tag"}}
ABCresult
1XX1
0111
00X0
0100
667 );
668 }
669 }
670 elsif ( $i == $#$sibs ) { # I'm rightmost of many
671 # if either my parent or sib are eligible, I'm good.
672 next
673 unless $HTML::DOM::_Element::canTighten{$ptag} # parent
674 or (ref $sibs->[ $i - 1 ]
675 and $HTML::DOM::_Element::canTighten{ $sibs->[ $i - 1 ]
676 0 ▶ {'_tag'} } # left sib
Branch: 1 branch
BranchTrueFalseTotal
unless $HTML::DOM::_Element::canTighten{$ptag} or ref $$sibs[$i - 1] and $HTML::DOM::_Element::canTighten{$$sibs[$i - 1]{"_tag"}} 0 0 0
Condition0%0/6
$HTML::DOM::_Element::canTighten{$ptag} or ref $$sibs[$i - 1] and $HTML::DOM::_Element::canTighten{$$sibs[$i - 1]{"_tag"}}
l!l&&r!l&&!r
000
ref $$sibs[$i - 1] and $HTML::DOM::_Element::canTighten{$$sibs[$i - 1]{"_tag"}}
!ll&&!rl&&r
000
MC/DC0%0/3
$HTML::DOM::_Element::canTighten{$ptag} or ref $$sibs[$i - 1] and $HTML::DOM::_Element::canTighten{$$sibs[$i - 1]{"_tag"}}
$HTML::DOM::_Element::canTighten{$ptag} ref $$sibs[$i - 1] $HTML::DOM::_Element::canTighten{$$sibs[$i - 1]{"_tag"}}
Truth table0%0/4
A or B and C
A= $HTML::DOM::_Element::canTighten{$ptag}B= ref $$sibs[$i - 1]C= $HTML::DOM::_Element::canTighten{$$sibs[$i - 1]{"_tag"}}
ABCresult
1XX1
0111
00X0
0100
677 );
678 }
679 else { # I'm the piggy in the middle
680 # My parent doesn't matter -- it all depends on my sibs
681 next
682 0 ▶ unless ref $sibs->[ $i - 1 ]
Branch: 1 branch
BranchTrueFalseTotal
unless ref $$sibs[$i - 1] or ref $$sibs[$i + 1] 0 0 0
Condition0%0/3
ref $$sibs[$i - 1] or ref $$sibs[$i + 1]
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $$sibs[$i - 1] or ref $$sibs[$i + 1]
ref $$sibs[$i - 1] ref $$sibs[$i + 1]
Truth table0%0/3
A or B
A= ref $$sibs[$i - 1]B= ref $$sibs[$i + 1]
ABresult
1X1
011
000
683 or ref $sibs->[ $i + 1 ];
684  
685 # if NEITHER sib is a node, quit
686  
687 next if
688  
689 # bailout condition: if BOTH are INeligible nodes
690 # (as opposed to being text, or being eligible nodes)
691 ref $sibs->[ $i - 1 ]
692 and ref $sibs->[ $i + 1 ]
693 and !$HTML::DOM::_Element::canTighten{ $sibs->[ $i - 1 ]
694 {'_tag'} } # left sib
695 and !$HTML::DOM::_Element::canTighten{ $sibs->[ $i + 1 ]
696 0 ▶ {'_tag'} } # right sib
Branch: 1 branch
BranchTrueFalseTotal
if ref $$sibs[$i - 1] and ref $$sibs[$i + 1] and not $HTML::DOM::_Element::canTighten{$$sibs[$i - 1]{"_tag"}} and not $HTML::DOM::_Element::canTighten{$$sibs[$i + 1]{"_tag"}} 0 0 0
Condition0%0/9
ref $$sibs[$i - 1] and ref $$sibs[$i + 1] and not $HTML::DOM::_Element::canTighten{$$sibs[$i - 1]{"_tag"}} and not $HTML::DOM::_Element::canTighten{$$sibs[$i + 1]{"_tag"}}
!ll&&!rl&&r
000
ref $$sibs[$i - 1] and ref $$sibs[$i + 1] and not $HTML::DOM::_Element::canTighten{$$sibs[$i - 1]{"_tag"}}
!ll&&!rl&&r
000
ref $$sibs[$i - 1] and ref $$sibs[$i + 1]
!ll&&!rl&&r
000
MC/DC0%0/4
ref $$sibs[$i - 1] and ref $$sibs[$i + 1] and not $HTML::DOM::_Element::canTighten{$$sibs[$i - 1]{"_tag"}} and not $HTML::DOM::_Element::canTighten{$$sibs[$i + 1]{"_tag"}}
ref $$sibs[$i - 1] ref $$sibs[$i + 1] not $HTML::DOM::_Element::canTighten{$$sibs[$i - 1]{"_tag"}} not $HTML::DOM::_Element::canTighten{$$sibs[$i + 1]{"_tag"}}
Truth table0%0/5
A and B and not(C) and not(D)
A= ref $$sibs[$i - 1]B= ref $$sibs[$i + 1]C= not $HTML::DOM::_Element::canTighten{$$sibs[$i - 1]{"_tag"}}D= not $HTML::DOM::_Element::canTighten{$$sibs[$i + 1]{"_tag"}}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
697 ;
698 }
699  
700 # Unknown tags aren't in canTighten and so AREN'T subject to tightening
701  
702 0 ▶ print " delendum: child $i of $ptag\n" if $Debug > 3;
Branch: 1 branch
BranchTrueFalseTotal
if $HTML::DOM::_Element::Debug > 3 0 0 0
703 0 splice @$sibs, $i, 1;
704 }
705  
706 # end of the loop-over-children
707 }
708  
709 # end of the while loop.
710  
711 0 return;
712 }
713  
714 786 ▶sub insert_element {
Subroutine insert_element: called CC=8 SCAR=20.9
Pod undocumented
715 786 my ( $self, $tag, $implicit ) = @_;
716 786 ▶ return $self->pos() unless $tag; # noop if nothing to insert
Branch: 1 branch
BranchTrueFalseTotal
unless $tag 0 786 786
717  
718 786 my $e;
719 786 ▶ if ( ref $tag ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tag) { } 510 276 786
720 510 $e = $tag;
721 510 $tag = $e->tag;
722 }
723 else { # just a tag name -- so make the element
724 276 $e = $self->element_class->new($tag);
725 276 ▶ ++( $self->{'_element_count'} ) if exists $self->{'_element_count'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_element_count"} 276 0 276
726  
727 # undocumented. see TreeBuilder.
728 }
729  
730 786 ▶ $e->{'_implicit'} = 1 if $implicit;
Branch: 1 branch
BranchTrueFalseTotal
if $implicit 276 510 786
731  
732 786 my $pos = $self->{'_pos'};
733 786 ▶ $pos = $self unless defined $pos;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 264 522 786
734  
735 786 $pos->push_content($e);
736  
737 $self->{'_pos'} = $pos = $e
738 786 ▶ unless $self->_empty_element_map->{$tag} || $e->{'_empty_element'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_empty_element_map->{$tag} or $e->{"_empty_element"} 687 99 786
Condition66%2/3
$self->_empty_element_map->{$tag} or $e->{"_empty_element"}
l!l&&r!l&&!r
990687
MC/DC50%1/2
$self->_empty_element_map->{$tag} or $e->{"_empty_element"}
$self->_empty_element_map->{$tag} $e->{"_empty_element"}
Truth table66%2/3
A or B
A= $self->_empty_element_map->{$tag}B= $e->{"_empty_element"}
ABresult
1X1
011
000
739  
740 786 $pos;
741 }
742  
743 #==========================================================================
744 # Some things to override in XML::Element
745  
746 1397 ▶sub _empty_element_map {
Subroutine _empty_element_map: called CC=1 SCAR=0.0
747 1397 \%HTML::DOM::_Element::emptyElement;
748 }
749  
750 13612 ▶sub _fold_case_LC {
Subroutine _fold_case_LC: called CC=2 SCAR=6.9
751 13612 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 161 13451 13612
752 161 shift;
753 161 map lc($_), @_;
754 }
755 else {
756 13451 return lc( $_[1] );
757 }
758 }
759  
760 0 ▶sub _fold_case_NOT {
Subroutine _fold_case_NOT: not called CC=2 SCAR=17.9
761 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
762 0 shift;
763 0 @_;
764 }
765 else {
766 0 return $_[1];
767 }
768 }
769  
770 28 *_fold_case = \&_fold_case_LC;
771  
772 #==========================================================================
773  
774 0 ▶sub dump {
Subroutine dump: not called CC=9 SCAR=45.0
Pod undocumented
775 0 my ( $self, $fh, $depth ) = @_;
776 0 ▶ $fh = *STDOUT{IO} unless defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 0 0
777 0 ▶ $depth = 0 unless defined $depth;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $depth 0 0 0
778 print $fh " " x $depth, $self->starttag, " \@", $self->address,
779 0 ▶ $self->{'_implicit'} ? " (IMPLICIT)\n" : "\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_implicit'} ? : 0 0 0
780 0 for ( @{ $self->{'_content'} } ) {
781 0 ▶ if ( ref $_ ) { # element
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_) { } 0 0 0
782 0 $_->dump( $fh, $depth + 1 ); # recurse
783 }
784 else { # text node
785 0 print $fh " " x ( $depth + 1 );
786 0 ▶ if ( length($_) > 65 or m<[\x00-\x1F]> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_ > 65 or /[\x00-\x1F]/) { } 0 0 0
Condition0%0/3
length $_ > 65 or /[\x00-\x1F]/
l!l&&r!l&&!r
000
MC/DC0%0/2
length $_ > 65 or /[\x00-\x1F]/
length $_ > 65 /[\x00-\x1F]/
Truth table0%0/3
A or B
A= length $_ > 65B= /[\x00-\x1F]/
ABresult
1X1
011
000
787  
788 # it needs prettyin' up somehow or other
789 0 ▶ my $x
Branch: 1 branch
BranchTrueFalseTotal
length $_ <= 65 ? : 0 0 0
790 = ( length($_) <= 65 )
791 ? $_
792 : ( substr( $_, 0, 65 ) . '...' );
793 0 $x =~ s<([\x00-\x1F])>
794 0 <'\\x'.(unpack("H2",$1))>eg;
795 0 print $fh qq{"$x"\n};
796 }
797 else {
798 0 print $fh qq{"$_"\n};
799 }
800 }
801 }
802 }
803  
804 73 ▶sub as_HTML {
Subroutine as_HTML: called CC=6 SCAR=29.2
Pod undocumented
805 73 my ( $self, $entities, $indent, $omissible_map ) = @_;
806  
807 #my $indent_on = defined($indent) && length($indent);
808 73 my @html = ();
809  
810 73 ▶ $omissible_map ||= \%HTML::DOM::_Element::optionalEndTag;
Condition100%2/2
$omissible_map ||= \%HTML::DOM::_Element::optionalEndTag
l!l
4330
MC/DC100%1/1
$omissible_map ||= \%HTML::DOM::_Element::optionalEndTag
$omissible_map
Truth table100%2/2
A
A= $omissible_map
Aresult
11
00
811 73 my $empty_element_map = $self->_empty_element_map;
812  
813 73 my $last_tag_tightenable = 0;
814 73 my $this_tag_tightenable = 0;
815 73 my $nonindentable_ancestors = 0; # count of nonindentible tags over us.
816  
817 73 my ( $tag, $node, $start, $depth ); # per-iteration scratch
818  
819 73 ▶ if ( defined($indent) && length($indent) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $indent and length $indent) { } 0 73 73
Condition33%1/3
defined $indent and length $indent
!ll&&!rl&&r
7300
MC/DC0%0/2
defined $indent and length $indent
defined $indent length $indent
Truth table33%1/3
A and B
A= defined $indentB= length $indent
ABresult
0X0
100
111
820 $self->traverse(
821 0 ▶ sub {
Subroutine __ANON__: not called CC=22 SCAR=62.3
822 0 ( $node, $start, $depth ) = @_;
823 0 ▶ if ( ref $node ) { # it's an element
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node) { } 0 0 0
824  
825 # detect bogus classes. RT #35948, #61673
826 0 ▶ $node->can('starttag')
Branch: 1 branch
BranchTrueFalseTotal
$node->can("starttag") or Carp::confess('Object of class ' . ref($node) . ' cannot be processed by HTML::DOM::_Element') 0 0 0
827 or Carp::confess( "Object of class "
828 . ref($node)
829 . " cannot be processed by HTML::DOM::_Element" );
830  
831 0 $tag = $node->{'_tag'};
832  
833 0 ▶ if ($start) { # on the way in
Branch: 2 branches
BranchTrueFalseTotal
if ($start) { } 0 0 0
elsif (not $empty_element_map->{$tag} || $omissible_map->{$tag}) { } 0 0 0
834 0 ▶ if (( $this_tag_tightenable
Branch: 1 branch
BranchTrueFalseTotal
if ($this_tag_tightenable = $HTML::DOM::_Element::canTighten{$tag} and not $nonindentable_ancestors and $last_tag_tightenable) { } 0 0 0
Condition0%0/6
$this_tag_tightenable = $HTML::DOM::_Element::canTighten{$tag} and not $nonindentable_ancestors and $last_tag_tightenable
!ll&&!rl&&r
000
$this_tag_tightenable = $HTML::DOM::_Element::canTighten{$tag} and not $nonindentable_ancestors
!ll&&!rl&&r
000
MC/DC0%0/3
$this_tag_tightenable = $HTML::DOM::_Element::canTighten{$tag} and not $nonindentable_ancestors and $last_tag_tightenable
$this_tag_tightenable = $HTML::DOM::_Element::canTighten{$tag} not $nonindentable_ancestors $last_tag_tightenable
Truth table0%0/4
A and not(B) and C
A= $this_tag_tightenable = $HTML::DOM::_Element::canTighten{$tag}B= not $nonindentable_ancestorsC= $last_tag_tightenable
ABCresult
0XX0
10X0
1100
1111
835 = $HTML::DOM::_Element::canTighten{$tag}
836 )
837 and !$nonindentable_ancestors
838 and $last_tag_tightenable
839 )
840 {
841 0 push
842 @html,
843 "\n",
844 $indent x $depth,
845 $node->starttag($entities),
846 ;
847 }
848 else {
849 0 push( @html, $node->starttag($entities) );
850 }
851 0 $last_tag_tightenable = $this_tag_tightenable;
852  
853 ++$nonindentable_ancestors
854 if $tag eq 'pre'
855 0 ▶ or $HTML::Tagset::isCDATA_Parent{$tag};
Branch: 1 branch
BranchTrueFalseTotal
if $tag eq "pre" or $HTML::Tagset::isCDATA_Parent{$tag} 0 0 0
Condition0%0/3
$tag eq "pre" or $HTML::Tagset::isCDATA_Parent{$tag}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tag eq "pre" or $HTML::Tagset::isCDATA_Parent{$tag}
$tag eq "pre" $HTML::Tagset::isCDATA_Parent{$tag}
Truth table0%0/3
A or B
A= $tag eq "pre"B= $HTML::Tagset::isCDATA_Parent{$tag}
ABresult
1X1
011
000
856  
857 }
858 ▶ elsif (
Condition0%0/3
$empty_element_map->{$tag} || $omissible_map->{$tag}
l!l&&r!l&&!r
000
MC/DC0%0/2
$empty_element_map->{$tag} || $omissible_map->{$tag}
$empty_element_map->{$tag} $omissible_map->{$tag}
Truth table0%0/3
A || B
A= $empty_element_map->{$tag}B= $omissible_map->{$tag}
ABresult
1X1
011
000
859 not( $empty_element_map->{$tag}
860 or $omissible_map->{$tag} )
861 )
862 {
863  
864 # on the way out
865 0 ▶ if ( $tag eq 'pre'
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq 'pre' or $HTML::Tagset::isCDATA_Parent{$tag}) { } 0 0 0
Condition0%0/3
$tag eq "pre" or $HTML::Tagset::isCDATA_Parent{$tag}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tag eq "pre" or $HTML::Tagset::isCDATA_Parent{$tag}
$tag eq "pre" $HTML::Tagset::isCDATA_Parent{$tag}
Truth table0%0/3
A or B
A= $tag eq "pre"B= $HTML::Tagset::isCDATA_Parent{$tag}
ABresult
1X1
011
000
866 or $HTML::Tagset::isCDATA_Parent{$tag} )
867 {
868 0 --$nonindentable_ancestors;
869 $last_tag_tightenable
870 0 = $HTML::DOM::_Element::canTighten{$tag};
871 0 push @html, $node->endtag;
872  
873 }
874 else { # general case
875 0 ▶ if (( $this_tag_tightenable
Branch: 1 branch
BranchTrueFalseTotal
if ($this_tag_tightenable = $HTML::DOM::_Element::canTighten{$tag} and not $nonindentable_ancestors and $last_tag_tightenable) { } 0 0 0
Condition0%0/6
$this_tag_tightenable = $HTML::DOM::_Element::canTighten{$tag} and not $nonindentable_ancestors and $last_tag_tightenable
!ll&&!rl&&r
000
$this_tag_tightenable = $HTML::DOM::_Element::canTighten{$tag} and not $nonindentable_ancestors
!ll&&!rl&&r
000
MC/DC0%0/3
$this_tag_tightenable = $HTML::DOM::_Element::canTighten{$tag} and not $nonindentable_ancestors and $last_tag_tightenable
$this_tag_tightenable = $HTML::DOM::_Element::canTighten{$tag} not $nonindentable_ancestors $last_tag_tightenable
Truth table0%0/4
A and not(B) and C
A= $this_tag_tightenable = $HTML::DOM::_Element::canTighten{$tag}B= not $nonindentable_ancestorsC= $last_tag_tightenable
ABCresult
0XX0
10X0
1100
1111
876 = $HTML::DOM::_Element::canTighten{$tag}
877 )
878 and !$nonindentable_ancestors
879 and $last_tag_tightenable
880 )
881 {
882 0 push
883 @html,
884 "\n",
885 $indent x $depth,
886 $node->endtag,
887 ;
888 }
889 else {
890 0 push @html, $node->endtag;
891 }
892 0 $last_tag_tightenable = $this_tag_tightenable;
893  
894 #print "$tag tightenable: $this_tag_tightenable\n";
895 }
896 }
897 }
898 else { # it's a text segment
899  
900 0 $last_tag_tightenable = 0; # I guess this is right
901 HTML::Entities::encode_entities( $node, $entities )
902  
903 # That does magic things if $entities is undef.
904 unless (
905 ( defined($entities) && !length($entities) )
906  
907 # If there's no entity to encode, don't call it
908 0 ▶ || $HTML::Tagset::isCDATA_Parent{ $_[3]{'_tag'} }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entities and not length $entities or $HTML::Tagset::isCDATA_Parent{$_[3]{"_tag"}} or $HTML::DOM::_Element::encoded_content 0 0 0
Condition0%0/9
defined $entities and not length $entities or $HTML::Tagset::isCDATA_Parent{$_[3]{"_tag"}} or $HTML::DOM::_Element::encoded_content
l!l&&r!l&&!r
000
defined $entities and not length $entities or $HTML::Tagset::isCDATA_Parent{$_[3]{"_tag"}}
l!l&&r!l&&!r
000
defined $entities and not length $entities
!ll&&!rl&&r
000
MC/DC0%0/4
defined $entities and not length $entities or $HTML::Tagset::isCDATA_Parent{$_[3]{"_tag"}} or $HTML::DOM::_Element::encoded_content
defined $entities not length $entities $HTML::Tagset::isCDATA_Parent{$_[3]{"_tag"}} $HTML::DOM::_Element::encoded_content
Truth table0%0/7
A and not(B) or C or D
A= defined $entitiesB= not length $entitiesC= $HTML::Tagset::isCDATA_Parent{$_[3]{"_tag"}}D= $HTML::DOM::_Element::encoded_content
ABCDresult
11XX1
0X1X1
101X1
0X011
10011
0X000
10000
909  
910 # To keep from amp-escaping children of script et al.
911 # That doesn't deal with descendants; but then, CDATA
912 # parents shouldn't /have/ descendants other than a
913 # text children (or comments?)
914 || $encoded_content
915 );
916 0 ▶ if ($nonindentable_ancestors) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nonindentable_ancestors) { } 0 0 0
917 0 push @html, $node; # say no go
918 }
919 else {
920 0 ▶ if ($last_tag_tightenable) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_tag_tightenable) { } 0 0 0
921 0 $node =~ s<[\n\r\f\t ]+>< >s;
922  
923 #$node =~ s< $><>s;
924 0 $node =~ s<^ ><>s;
925 0 push
926 @html,
927 "\n",
928 $indent x $depth,
929 $node,
930  
931 #Text::Wrap::wrap($indent x $depth, $indent x $depth, "\n" . $node)
932 ;
933 }
934 else {
935 0 push
936 @html,
937 $node,
938  
939 #Text::Wrap::wrap('', $indent x $depth, $node)
940 ;
941 }
942 }
943 }
944 0 1; # keep traversing
945 }
946 0 ); # End of parms to traverse()
947 }
948 else { # no indenting -- much simpler code
949 $self->traverse(
950 330 ▶ sub {
Subroutine __ANON__: called CC=9 SCAR=23.7
951 330 ( $node, $start ) = @_;
952 330 ▶ if ( ref $node ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node) { } 289 41 330
953  
954  
955 289 $tag = $node->{'_tag'};
956 289 ▶ if ($start) { # on the way in
Branch: 2 branches
BranchTrueFalseTotal
if ($start) { } 150 139 289
elsif (not $empty_element_map->{$tag} || $omissible_map->{$tag}) { } 138 1 139
957 150 push( @html, $node->starttag($entities) );
958 }
959 ▶ elsif (
Condition66%2/3
$empty_element_map->{$tag} || $omissible_map->{$tag}
l!l&&r!l&&!r
01138
MC/DC50%1/2
$empty_element_map->{$tag} || $omissible_map->{$tag}
$empty_element_map->{$tag} $omissible_map->{$tag}
Truth table66%2/3
A || B
A= $empty_element_map->{$tag}B= $omissible_map->{$tag}
ABresult
1X1
011
000
960 not( $empty_element_map->{$tag}
961 or $omissible_map->{$tag} )
962 )
963 {
964  
965 # on the way out
966 138 push( @html, $node->endtag );
967 }
968 }
969 else {
970  
971 # simple text content
972 HTML::Entities::encode_entities( $node, $entities )
973  
974 # That does magic things if $entities is undef.
975 unless (
976 ( defined($entities) && !length($entities) )
977  
978 # If there's no entity to encode, don't call it
979 41 ▶ || $HTML::Tagset::isCDATA_Parent{ $_[3]{'_tag'} }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entities and not length $entities or $HTML::Tagset::isCDATA_Parent{$_[3]{"_tag"}} or $HTML::DOM::_Element::encoded_content 41 0 41
Condition33%3/9
defined $entities and not length $entities or $HTML::Tagset::isCDATA_Parent{$_[3]{"_tag"}} or $HTML::DOM::_Element::encoded_content
l!l&&r!l&&!r
0041
defined $entities and not length $entities or $HTML::Tagset::isCDATA_Parent{$_[3]{"_tag"}}
l!l&&r!l&&!r
0041
defined $entities and not length $entities
!ll&&!rl&&r
4100
MC/DC0%0/4
defined $entities and not length $entities or $HTML::Tagset::isCDATA_Parent{$_[3]{"_tag"}} or $HTML::DOM::_Element::encoded_content
defined $entities not length $entities $HTML::Tagset::isCDATA_Parent{$_[3]{"_tag"}} $HTML::DOM::_Element::encoded_content
Truth table14%1/7
A and not(B) or C or D
A= defined $entitiesB= not length $entitiesC= $HTML::Tagset::isCDATA_Parent{$_[3]{"_tag"}}D= $HTML::DOM::_Element::encoded_content
ABCDresult
11XX1
0X1X1
101X1
0X011
10011
0X000
10000
980  
981 # To keep from amp-escaping children of script et al.
982 # That doesn't deal with descendants; but then, CDATA
983 # parents shouldn't /have/ descendants other than a
984 # text children (or comments?)
985 || $encoded_content
986 );
987 41 push( @html, $node );
988 }
989 330 1; # keep traversing
990 }
991 73 ); # End of parms to traverse()
992 }
993  
994 73 ▶ if ( $self->{_store_declarations} && defined $self->{_decl} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_store_declarations"} and defined $self->{"_decl"}) 0 73 73
Condition66%2/3
$self->{"_store_declarations"} and defined $self->{"_decl"}
!ll&&!rl&&r
7210
MC/DC0%0/2
$self->{"_store_declarations"} and defined $self->{"_decl"}
$self->{"_store_declarations"} defined $self->{"_decl"}
Truth table66%2/3
A and B
A= $self->{"_store_declarations"}B= defined $self->{"_decl"}
ABresult
0X0
100
111
995 0 unshift @html, sprintf "<!%s>\n", $self->{_decl}->{text};
996 }
997  
998 73 return join( '', @html );
999 }
1000  
1001 15 ▶sub as_text {
Subroutine as_text: called CC=10 SCAR=23.6
Pod undocumented
1002  
1003 # Yet another iteratively implemented traverser
1004 15 my ( $this, %options ) = @_;
1005 15 ▶ my $skip_dels = $options{'skip_dels'} || 0;
Condition100%2/2
$options{'skip_dels'} || 0
l!l
114
MC/DC100%1/1
$options{'skip_dels'} || 0
$options{'skip_dels'}
Truth table100%2/2
A
A= $options{'skip_dels'}
Aresult
11
00
1006 15 my (@pile) = ($this);
1007 15 my $tag;
1008 15 my $text = '';
1009 15 ▶ while (@pile) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pile) 92 15 107
1010 92 ▶ if ( !defined( $pile[0] ) ) { # undef!
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $pile[0]) { } 0 92 92
elsif (not ref $pile[0]) { } 42 50 92
1011 # no-op
1012 }
1013 elsif ( !ref( $pile[0] ) ) { # text bit! save it!
1014 42 $text .= shift @pile;
1015 }
1016 else { # it's a ref -- traverse under it
1017 49 ▶ unshift @pile, @{ $this->{'_content'} || $nillio }
Condition33%1/3
$this->{'_content'} || $nillio
l!l&&r!l&&!r
4900
MC/DC0%0/2
$this->{'_content'} || $nillio
$this->{'_content'} $nillio
Truth table33%1/3
A || B
A= $this->{'_content'}B= $nillio
ABresult
1X1
011
000
1018 50 ▶ unless ( $tag = ( $this = shift @pile )->{'_tag'} ) eq 'style'
Branch: 1 branch
BranchTrueFalseTotal
unless ($tag = +($this = shift @pile)->{"_tag"}) eq "style" or $tag eq "script" or $skip_dels and $tag eq "del" 49 1 50
Condition66%6/9
($tag = +($this = shift @pile)->{"_tag"}) eq "style" or $tag eq "script" or $skip_dels and $tag eq "del"
l!l&&r!l&&!r
0149
($tag = +($this = shift @pile)->{"_tag"}) eq "style" or $tag eq "script"
l!l&&r!l&&!r
0050
$skip_dels and $tag eq "del"
!ll&&!rl&&r
4721
MC/DC50%2/4
($tag = +($this = shift @pile)->{"_tag"}) eq "style" or $tag eq "script" or $skip_dels and $tag eq "del"
($tag = +($this = shift @pile)->{"_tag"}) eq "style" $tag eq "script" $skip_dels $tag eq "del"
Truth table60%3/5
A or B or C and D
A= ($tag = +($this = shift @pile)->{"_tag"}) eq "style"B= $tag eq "script"C= $skip_delsD= $tag eq "del"
ABCDresult
1XXX1
01XX1
00111
000X0
00100
1019 or $tag eq 'script'
1020 or ( $skip_dels and $tag eq 'del' );
1021 }
1022 }
1023 15 return $text;
1024 }
1025  
1026 # extra_chars added for RT #26436
1027 0 ▶sub as_trimmed_text {
Subroutine as_trimmed_text: not called CC=2 SCAR=17.9
Pod undocumented
1028 0 my ( $this, %options ) = @_;
1029 0 my $text = $this->as_text(%options);
1030 0 ▶ my $extra_chars = $options{'extra_chars'} || '';
Condition0%0/2
$options{'extra_chars'} || ''
l!l
00
MC/DC0%0/1
$options{'extra_chars'} || ''
$options{'extra_chars'}
Truth table0%0/2
A
A= $options{'extra_chars'}
Aresult
11
00
1031  
1032 0 $text =~ s/[\n\r\f\t$extra_chars ]+$//s;
1033 0 $text =~ s/^[\n\r\f\t$extra_chars ]+//s;
1034 0 $text =~ s/[\n\r\f\t$extra_chars ]+/ /g;
1035 0 return $text;
1036 }
1037  
1038 0 ▶sub as_text_trimmed { shift->as_trimmed_text(@_) } # alias, because I forget
Subroutine as_text_trimmed: not called CC=1 SCAR=6.9
Pod undocumented
1039  
1040 # TODO: make it wrap, if not indent?
1041  
1042 0 ▶sub as_XML {
Subroutine as_XML: not called CC=1 SCAR=6.9
Pod undocumented
1043  
1044 # based an as_HTML
1045 0 my ($self) = @_;
1046  
1047 #my $indent_on = defined($indent) && length($indent);
1048 0 my @xml = ();
1049 0 my $empty_element_map = $self->_empty_element_map;
1050  
1051 0 my ( $tag, $node, $start ); # per-iteration scratch
1052 $self->traverse(
1053 0 ▶ sub {
Subroutine __ANON__: not called CC=12 SCAR=50.5
1054 0 ( $node, $start ) = @_;
1055 0 ▶ if ( ref $node ) { # it's an element
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node) { } 0 0 0
1056 0 $tag = $node->{'_tag'};
1057 0 ▶ if ($start) { # on the way in
Branch: 1 branch
BranchTrueFalseTotal
if ($start) { } 0 0 0
1058  
1059 0 foreach my $attr ( $node->all_attr_names() ) {
1060 0 ▶ Carp::croak(
Branch: 1 branch
BranchTrueFalseTotal
unless $attr eq "/" or $self->_valid_name($attr) 0 0 0
Condition0%0/3
$attr eq "/" or $self->_valid_name($attr)
l!l&&r!l&&!r
000
MC/DC0%0/2
$attr eq "/" or $self->_valid_name($attr)
$attr eq "/" $self->_valid_name($attr)
Truth table0%0/3
A or B
A= $attr eq "/"B= $self->_valid_name($attr)
ABresult
1X1
011
000
1061 "$tag has an invalid attribute name '$attr'")
1062 unless ( $attr eq '/' || $self->_valid_name($attr) );
1063 }
1064  
1065 0 ▶ if ( $empty_element_map->{$tag}
Branch: 1 branch
BranchTrueFalseTotal
if ($empty_element_map->{$tag} and not @{$node->{'_content'} or $nillio;}) { } 0 0 0
Condition0%0/3
$empty_element_map->{$tag} and not @{$node->{"_content"} or $nillio;}
!ll&&!rl&&r
000
MC/DC0%0/2
$empty_element_map->{$tag} and not @{$node->{"_content"} or $nillio;}
$empty_element_map->{$tag} not @{$node->{"_content"} or $nillio;}
Truth table0%0/3
A and not(B)
A= $empty_element_map->{$tag}B= not @{$node->{"_content"} or $nillio;}
ABresult
0X0
100
111
1066 0 ▶ and !@{ $node->{'_content'} || $nillio } )
Condition0%0/3
$node->{'_content'} || $nillio
l!l&&r!l&&!r
000
MC/DC0%0/2
$node->{'_content'} || $nillio
$node->{'_content'} $nillio
Truth table0%0/3
A || B
A= $node->{'_content'}B= $nillio
ABresult
1X1
011
000
1067 {
1068 0 push( @xml, $node->starttag_XML( undef, 1 ) );
1069 }
1070 else {
1071 0 push( @xml, $node->starttag_XML(undef) );
1072 }
1073 }
1074 else { # on the way out
1075 0 ▶ unless ( $empty_element_map->{$tag}
Branch: 1 branch
BranchTrueFalseTotal
unless ($empty_element_map->{$tag} and not @{$node->{"_content"} or $nillio;}) 0 0 0
Condition0%0/3
$empty_element_map->{$tag} and not @{$node->{"_content"} or $nillio;}
!ll&&!rl&&r
000
MC/DC0%0/2
$empty_element_map->{$tag} and not @{$node->{"_content"} or $nillio;}
$empty_element_map->{$tag} not @{$node->{"_content"} or $nillio;}
Truth table0%0/3
A and not(B)
A= $empty_element_map->{$tag}B= not @{$node->{"_content"} or $nillio;}
ABresult
0X0
100
111
1076 0 ▶ and !@{ $node->{'_content'} || $nillio } )
Condition0%0/3
$node->{'_content'} || $nillio
l!l&&r!l&&!r
000
MC/DC0%0/2
$node->{'_content'} || $nillio
$node->{'_content'} $nillio
Truth table0%0/3
A || B
A= $node->{'_content'}B= $nillio
ABresult
1X1
011
000
1077 {
1078 0 push( @xml, $node->endtag_XML() );
1079 } # otherwise it will have been an <... /> tag.
1080 }
1081 }
1082 else { # it's just text
1083 0 _xml_escape($node);
1084 0 push( @xml, $node );
1085 }
1086 0 1; # keep traversing
1087 }
1088 0 );
1089  
1090 0 join( '', @xml, "\n" );
1091 }
1092  
1093 0 ▶sub _xml_escape {
Subroutine _xml_escape: not called CC=3 SCAR=24.8
1094  
1095 # DESTRUCTIVE (a.k.a. "in-place")
1096 # Five required escapes: http://www.w3.org/TR/2006/REC-xml11-20060816/#syntax
1097 # We allow & if it's part of a valid escape already: http://www.w3.org/TR/2006/REC-xml11-20060816/#sec-references
1098 0 foreach my $x (@_) {
1099  
1100 # In strings with no encoded entities all & should be encoded.
1101 0 ▶ if ($encoded_content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($HTML::DOM::_Element::encoded_content) { } 0 0 0
1102 0 $x
1103 =~ s/&(?! # An ampersand that isn't followed by...
1104 (\#\d+; | # A hash mark, digits and semicolon, or
1105 \#x[\da-f]+; | # A hash mark, "x", hex digits and semicolon, or
1106 $START_CHAR$NAME_CHAR+; ) # A valid unicode entity name and semicolon
1107 )/&amp;/gx; # Needs to be escaped to amp
1108 }
1109 else {
1110 0 $x =~ s/&/&amp;/g;
1111 }
1112  
1113 # simple character escapes
1114 0 $x =~ s/</&lt;/g;
1115 0 $x =~ s/>/&gt;/g;
1116 0 $x =~ s/"/&quot;/g;
1117 0 $x =~ s/'/&apos;/g;
1118 }
1119 0 return;
1120 }
1121  
1122 # NOTES:
1123 #
1124 # It's been suggested that attribute names be made :-keywords:
1125 # (:_tag "img" :border 0 :src "pie.png" :usemap "#main.map")
1126 # However, it seems that Scheme has no such data type as :-keywords.
1127 # So, for the moment at least, I tend toward simplicity, uniformity,
1128 # and universality, where everything a string or a list.
1129  
1130 0 ▶sub as_Lisp_form {
Subroutine as_Lisp_form: not called CC=1 SCAR=6.9
Pod undocumented
1131 0 my @out;
1132  
1133 my $sub;
1134 0 my $depth = 0;
1135 0 my ( @list, $val );
1136 0 ▶ $sub = sub { # Recursor
Subroutine __ANON__: not called CC=13 SCAR=52.0
1137 0 my $self = $_[0];
1138 0 @list = ( '_tag', $self->{'_tag'} );
1139 0 ▶ @list = () unless defined $list[-1]; # unlikely
Branch: 1 branch
BranchTrueFalseTotal
unless defined $list[-1] 0 0 0
1140  
1141 0 for ( sort keys %$self ) { # predictable ordering
1142 next
1143 0 ▶ if $_ eq '_content'
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "_content" or $_ eq "_tag" or $_ eq "_parent" or $_ eq "/" 0 0 0
Condition0%0/9
$_ eq "_content" or $_ eq "_tag" or $_ eq "_parent" or $_ eq "/"
l!l&&r!l&&!r
000
$_ eq "_content" or $_ eq "_tag" or $_ eq "_parent"
l!l&&r!l&&!r
000
$_ eq "_content" or $_ eq "_tag"
l!l&&r!l&&!r
000
MC/DC0%0/4
$_ eq "_content" or $_ eq "_tag" or $_ eq "_parent" or $_ eq "/"
$_ eq "_content" $_ eq "_tag" $_ eq "_parent" $_ eq "/"
Truth table0%0/5
A or B or C or D
A= $_ eq "_content"B= $_ eq "_tag"C= $_ eq "_parent"D= $_ eq "/"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1144 or $_ eq '_tag'
1145 or $_ eq '_parent'
1146 or $_ eq '/';
1147  
1148 # Leave the other private attributes, I guess.
1149 push @list, $_, $val
1150 0 ▶ if defined( $val = $self->{$_} ); # and !ref $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined($val = $self->{$_}) 0 0 0
1151 }
1152  
1153 0 for (@list) {
1154  
1155 # octal-escape it
1156 0 s<([^\x20\x21\x23\x27-\x5B\x5D-\x7E])>
1157 0 <sprintf('\\%03o',ord($1))>eg;
1158 0 $_ = qq{"$_"};
1159 }
1160 0 push @out, ( ' ' x $depth ) . '(' . join ' ', splice @list;
1161 0 ▶ if ( @{ $self->{'_content'} || $nillio } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'_content'} or $nillio;}) { } 0 0 0
Condition0%0/3
$self->{'_content'} || $nillio
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_content'} || $nillio
$self->{'_content'} $nillio
Truth table0%0/3
A || B
A= $self->{'_content'}B= $nillio
ABresult
1X1
011
000
1162 0 $out[-1] .= " \"_content\" (\n";
1163 0 ++$depth;
1164 0 foreach my $c ( @{ $self->{'_content'} } ) {
1165 0 ▶ if ( ref($c) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $c) { } 0 0 0
1166  
1167 # an element -- recurse
1168 0 $sub->($c);
1169 }
1170 else {
1171  
1172 # a text segment -- stick it in and octal-escape it
1173 0 push @out, $c;
1174 0 $out[-1] =~ s<([^\x20\x21\x23\x27-\x5B\x5D-\x7E])>
1175 0 <sprintf('\\%03o',ord($1))>eg;
1176  
1177 # And quote and indent it.
1178 0 $out[-1] .= "\"\n";
1179 0 $out[-1] = ( ' ' x $depth ) . '"' . $out[-1];
1180 }
1181 }
1182 0 --$depth;
1183 0 substr( $out[-1], -1 )
1184 = "))\n"; # end of _content and of the element
1185 }
1186 else {
1187 0 $out[-1] .= ")\n";
1188 }
1189 0 return;
1190 0 };
1191  
1192 0 $sub->( $_[0] );
1193 0 undef $sub;
1194 0 return join '', @out;
1195 }
1196  
1197 0 ▶sub format {
Subroutine format: not called CC=2 SCAR=17.9
Pod undocumented
1198 0 my ( $self, $formatter ) = @_;
1199 0 ▶ unless ( defined $formatter ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $formatter) 0 0 0
1200 0 require HTML::FormatText;
1201 0 $formatter = HTML::FormatText->new();
1202 }
1203 0 $formatter->format($self);
1204 }
1205  
1206 146 ▶sub starttag {
Subroutine starttag: called CC=26 SCAR=44.2
Pod undocumented
1207 146 my ( $self, $entities ) = @_;
1208  
1209 146 my $name = $self->{'_tag'};
1210  
1211 146 ▶ return $self->{'text'} if $name eq '~literal';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "~literal" 0 146 146
1212 146 ▶ return "<!" . $self->{'text'} . ">" if $name eq '~declaration';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "~declaration" 0 146 146
1213 146 ▶ return "<?" . $self->{'text'} . ">" if $name eq '~pi';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "~pi" 0 146 146
1214  
1215 146 ▶ if ( $name eq '~comment' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "~comment") 0 146 146
1216 0 ▶ if ( ref( $self->{'text'} || '' ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($self->{'text'} || '') eq 'ARRAY') { } 0 0 0
Condition0%0/2
$self->{'text'} || ''
l!l
00
MC/DC0%0/1
$self->{'text'} || ''
$self->{'text'}
Truth table0%0/2
A
A= $self->{'text'}
Aresult
11
00
1217  
1218 # Does this ever get used? And is this right?
1219 return
1220 "<!"
1221 0 . join( ' ', map( "--$_--", @{ $self->{'text'} } ) ) . ">";
1222 }
1223 else {
1224 0 return "<!--" . $self->{'text'} . "-->";
1225 }
1226 }
1227  
1228 146 ▶ my $tag = $html_uc ? "<\U$name" : "<\L$name";
Branch: 1 branch
BranchTrueFalseTotal
$HTML::DOM::_Element::html_uc ? : 0 146 146
1229 146 my $val;
1230 146 for ( sort keys %$self ) { # predictable ordering
1231 535 ▶ next if !length $_ or m/^_/s or $_ eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if not length $_ or /^_/s or $_ eq "/" 529 6 535
Condition66%4/6
not length $_ or /^_/s or $_ eq "/"
l!l&&r!l&&!r
52906
not length $_ or /^_/s
l!l&&r!l&&!r
05296
MC/DC33%1/3
not length $_ or /^_/s or $_ eq "/"
not length $_ /^_/s $_ eq "/"
Truth table50%2/4
not(A) or B or C
A= not length $_B= /^_/sC= $_ eq "/"
ABCresult
1XX1
01X1
0011
0000
1232 6 $val = $self->{$_};
1233 6 ▶ next if !defined $val; # or ref $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 6 6
1234 6 ▶ if ($_ eq $val && # if attribute is boolean, for this element
Branch: 2 branches
BranchTrueFalseTotal
if ($_ eq $val and exists $HTML::DOM::_Element::boolean_attr{$name} and ref $HTML::DOM::_Element::boolean_attr{$name} ? $HTML::DOM::_Element::boolean_attr{$name}{$_} : $HTML::DOM::_Element::boolean_attr{$name} eq $_) { } 0 6 6
ref $HTML::DOM::_Element::boolean_attr{$name} ? : 0 0 0
Condition33%2/6
$_ eq $val and exists $HTML::DOM::_Element::boolean_attr{$name} and ref $HTML::DOM::_Element::boolean_attr{$name} ? $HTML::DOM::_Element::boolean_attr{$name}{$_} : $HTML::DOM::_Element::boolean_attr{$name} eq $_
!ll&&!rl&&r
600
$_ eq $val and exists $HTML::DOM::_Element::boolean_attr{$name}
!ll&&!rl&&r
600
MC/DC0%0/3
$_ eq $val and exists $HTML::DOM::_Element::boolean_attr{$name} and ref $HTML::DOM::_Element::boolean_attr{$name} ? $HTML::DOM::_Element::boolean_attr{$name}{$_} : $HTML::DOM::_Element::boolean_attr{$name} eq $_
$_ eq $val exists $HTML::DOM::_Element::boolean_attr{$name} ref $HTML::DOM::_Element::boolean_attr{$name} ? $HTML::DOM::_Element::boolean_attr{$name}{$_} : $HTML::DOM::_Element::boolean_attr{$name} eq $_
Truth table25%1/4
A and B and C
A= $_ eq $valB= exists $HTML::DOM::_Element::boolean_attr{$name}C= ref $HTML::DOM::_Element::boolean_attr{$name} ? $HTML::DOM::_Element::boolean_attr{$name}{$_} : $HTML::DOM::_Element::boolean_attr{$name} eq $_
ABCresult
0XX0
10X0
1100
1111
1235 exists( $HTML::DOM::_Element::boolean_attr{$name} )
1236 && (ref( $HTML::DOM::_Element::boolean_attr{$name} )
1237 ? $HTML::DOM::_Element::boolean_attr{$name}{$_}
1238 : $HTML::DOM::_Element::boolean_attr{$name} eq $_
1239 )
1240 )
1241 {
1242 0 ▶ $tag .= $html_uc ? " \U$_" : " \L$_";
Branch: 1 branch
BranchTrueFalseTotal
$HTML::DOM::_Element::html_uc ? : 0 0 0
1243 }
1244 else { # non-boolean attribute
1245  
1246 6 ▶ if ( ref $val eq 'HTML::DOM::_Element'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq 'HTML::DOM::_Element' and $val->{'_tag'} eq '~literal') { } 0 6 6
Condition33%1/3
ref $val eq "HTML::DOM::_Element" and $val->{"_tag"} eq "~literal"
!ll&&!rl&&r
600
MC/DC0%0/2
ref $val eq "HTML::DOM::_Element" and $val->{"_tag"} eq "~literal"
ref $val eq "HTML::DOM::_Element" $val->{"_tag"} eq "~literal"
Truth table33%1/3
A and B
A= ref $val eq "HTML::DOM::_Element"B= $val->{"_tag"} eq "~literal"
ABresult
0X0
100
111
1247 and $val->{_tag} eq '~literal' )
1248 {
1249 0 $val = $val->{text};
1250 }
1251 else {
1252 6 ▶ HTML::Entities::encode_entities( $val, $entities )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entities and not length $entities or $HTML::DOM::_Element::encoded_content 6 0 6
Condition33%2/6
defined $entities and not length $entities or $HTML::DOM::_Element::encoded_content
l!l&&r!l&&!r
006
defined $entities and not length $entities
!ll&&!rl&&r
600
MC/DC0%0/3
defined $entities and not length $entities or $HTML::DOM::_Element::encoded_content
defined $entities not length $entities $HTML::DOM::_Element::encoded_content
Truth table20%1/5
A and not(B) or C
A= defined $entitiesB= not length $entitiesC= $HTML::DOM::_Element::encoded_content
ABCresult
11X1
0X11
1011
0X00
1000
1253 unless (
1254 defined($entities) && !length($entities)
1255 || $encoded_content
1256  
1257 );
1258 }
1259  
1260 6 $val = qq{"$val"};
1261 6 ▶ $tag .= $html_uc ? qq{ \U$_\E=$val} : qq{ \L$_\E=$val};
Branch: 1 branch
BranchTrueFalseTotal
$HTML::DOM::_Element::html_uc ? : 0 6 6
1262 }
1263 } # for keys
1264 146 ▶ if ( scalar $self->content_list == 0
Branch: 1 branch
BranchTrueFalseTotal
if (scalar $self->content_list == 0 and $self->_empty_element_map->{$self->tag}) { } 7 139 146
Condition100%3/3
scalar $self->content_list == 0 and $self->_empty_element_map->{$self->tag}
!ll&&!rl&&r
72677
MC/DC100%2/2
scalar $self->content_list == 0 and $self->_empty_element_map->{$self->tag}
scalar $self->content_list == 0 $self->_empty_element_map->{$self->tag}
Truth table100%3/3
A and B
A= scalar $self->content_list == 0B= $self->_empty_element_map->{$self->tag}
ABresult
0X0
100
111
1265 && $self->_empty_element_map->{ $self->tag } )
1266 {
1267 7 return $tag . " />";
1268 }
1269 else {
1270 139 return $tag . ">";
1271 }
1272 }
1273  
1274 0 ▶sub starttag_XML {
Subroutine starttag_XML: not called CC=13 SCAR=52.0
Pod undocumented
1275 0 my ($self) = @_;
1276  
1277 # and a third parameter to signal emptiness?
1278  
1279 0 my $name = $self->{'_tag'};
1280  
1281 0 ▶ return $self->{'text'} if $name eq '~literal';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "~literal" 0 0 0
1282 0 ▶ return '<!' . $self->{'text'} . '>' if $name eq '~declaration';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "~declaration" 0 0 0
1283 0 ▶ return "<?" . $self->{'text'} . "?>" if $name eq '~pi';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "~pi" 0 0 0
1284  
1285 0 ▶ if ( $name eq '~comment' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "~comment") 0 0 0
1286 0 ▶ if ( ref( $self->{'text'} || '' ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($self->{'text'} || '') eq 'ARRAY') { } 0 0 0
Condition0%0/2
$self->{'text'} || ''
l!l
00
MC/DC0%0/1
$self->{'text'} || ''
$self->{'text'}
Truth table0%0/2
A
A= $self->{'text'}
Aresult
11
00
1287  
1288 # Does this ever get used? And is this right?
1289 0 $name = join( ' ', @{ $self->{'text'} } );
1290 }
1291 else {
1292 0 $name = $self->{'text'};
1293 }
1294 0 $name =~ s/--/-&#45;/g; # can't have double --'s in XML comments
1295 0 return "<!-- $name -->";
1296 }
1297  
1298 0 my $tag = "<$name";
1299 0 my $val;
1300 0 for ( sort keys %$self ) { # predictable ordering
1301 0 ▶ next if !length $_ or m/^_/s or $_ eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if not length $_ or /^_/s or $_ eq "/" 0 0 0
Condition0%0/6
not length $_ or /^_/s or $_ eq "/"
l!l&&r!l&&!r
000
not length $_ or /^_/s
l!l&&r!l&&!r
000
MC/DC0%0/3
not length $_ or /^_/s or $_ eq "/"
not length $_ /^_/s $_ eq "/"
Truth table0%0/4
not(A) or B or C
A= not length $_B= /^_/sC= $_ eq "/"
ABCresult
1XX1
01X1
0011
0000
1302  
1303 # Hm -- what to do if val is undef?
1304 # I suppose that shouldn't ever happen.
1305 0 ▶ next if !defined( $val = $self->{$_} ); # or ref $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined($val = $self->{$_}) 0 0 0
1306 0 _xml_escape($val);
1307 0 $tag .= qq{ $_="$val"};
1308 }
1309 0 ▶ @_ == 3 ? "$tag />" : "$tag>";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 ? : 0 0 0
1310 }
1311  
1312 138 ▶sub endtag {
Subroutine endtag: called CC=2 SCAR=7.6
Pod undocumented
1313 138 ▶ $html_uc ? "</\U$_[0]->{'_tag'}>" : "</\L$_[0]->{'_tag'}>";
Branch: 1 branch
BranchTrueFalseTotal
$HTML::DOM::_Element::html_uc ? : 0 138 138
1314 }
1315  
1316 # TODO: document?
1317 0 ▶sub endtag_XML {
Subroutine endtag_XML: not called CC=1 SCAR=6.9
Pod undocumented
1318 0 "</$_[0]->{'_tag'}>";
1319 }
1320  
1321 #==========================================================================
1322 # This, ladies and germs, is an iterative implementation of a
1323 # recursive algorithm. DON'T TRY THIS AT HOME.
1324 # Basically, the algorithm says:
1325 #
1326 # To traverse:
1327 # 1: pre-order visit this node
1328 # 2: traverse any children of this node
1329 # 3: post-order visit this node, unless it's a text segment,
1330 # or a prototypically empty node (like "br", etc.)
1331 # Add to that the consideration of the callbacks' return values,
1332 # so you can block visitation of the children, or siblings, or
1333 # abort the whole excursion, etc.
1334 #
1335 # So, why all this hassle with making the code iterative?
1336 # It makes for real speed, because it eliminates the whole
1337 # hassle of Perl having to allocate scratch space for each
1338 # instance of the recursive sub. Since the algorithm
1339 # is basically simple (and not all recursive ones are!) and
1340 # has few necessary lexicals (basically just the current node's
1341 # content list, and the current position in it), it was relatively
1342 # straightforward to store that information not as the frame
1343 # of a sub, but as a stack, i.e., a simple Perl array (well, two
1344 # of them, actually: one for content-listrefs, one for indexes of
1345 # current position in each of those).
1346  
1347 28 my $NIL = [];
1348  
1349 464 ▶sub traverse {
Subroutine traverse: called CC=54 SCAR=58.9
Pod undocumented
1350 464 my ( $start, $callback, $ignore_text ) = @_;
1351  
1352 464 ▶ Carp::croak "traverse can be called only as an object method"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $start 0 464 464
1353 unless ref $start;
1354  
1355 464 ▶ Carp::croak('must provide a callback for traverse()!')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $callback and ref $callback 0 464 464
Condition33%1/3
defined $callback and ref $callback
!ll&&!rl&&r
00464
MC/DC0%0/2
defined $callback and ref $callback
defined $callback ref $callback
Truth table33%1/3
A and B
A= defined $callbackB= ref $callback
ABresult
0X0
100
111
1356 unless defined $callback and ref $callback;
1357  
1358 # Elementary type-checking:
1359 464 my ( $c_pre, $c_post );
1360 464 ▶ if ( UNIVERSAL::isa( $callback, 'CODE' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($callback, 'CODE')) { } 73 391 464
elsif (UNIVERSAL::isa($callback, 'ARRAY')) { } 391 0 391
1361 73 $c_pre = $c_post = $callback;
1362 }
1363 elsif ( UNIVERSAL::isa( $callback, 'ARRAY' ) ) {
1364 391 ( $c_pre, $c_post ) = @$callback;
1365 391 ▶ Carp::croak(
Branch: 1 branch
BranchTrueFalseTotal
if $c_pre and not UNIVERSAL::isa($c_pre, "CODE") 0 391 391
Condition33%1/3
$c_pre and not UNIVERSAL::isa($c_pre, "CODE")
!ll&&!rl&&r
03910
MC/DC0%0/2
$c_pre and not UNIVERSAL::isa($c_pre, "CODE")
$c_pre not UNIVERSAL::isa($c_pre, "CODE")
Truth table33%1/3
A and not(B)
A= $c_preB= not UNIVERSAL::isa($c_pre, "CODE")
ABresult
0X0
100
111
1366 "pre-order callback \"$c_pre\" is true but not a coderef!")
1367 if $c_pre and not UNIVERSAL::isa( $c_pre, 'CODE' );
1368 391 ▶ Carp::croak(
Branch: 1 branch
BranchTrueFalseTotal
if $c_post and not UNIVERSAL::isa($c_post, "CODE") 0 391 391
Condition33%1/3
$c_post and not UNIVERSAL::isa($c_post, "CODE")
!ll&&!rl&&r
39100
MC/DC0%0/2
$c_post and not UNIVERSAL::isa($c_post, "CODE")
$c_post not UNIVERSAL::isa($c_post, "CODE")
Truth table33%1/3
A and not(B)
A= $c_postB= not UNIVERSAL::isa($c_post, "CODE")
ABresult
0X0
100
111
1369 "pre-order callback \"$c_post\" is true but not a coderef!")
1370 if $c_post and not UNIVERSAL::isa( $c_post, 'CODE' );
1371 391 ▶ return $start unless $c_pre or $c_post;
Branch: 1 branch
BranchTrueFalseTotal
unless $c_pre or $c_post 0 391 391
Condition33%1/3
$c_pre or $c_post
l!l&&r!l&&!r
39100
MC/DC0%0/2
$c_pre or $c_post
$c_pre $c_post
Truth table33%1/3
A or B
A= $c_preB= $c_post
ABresult
1X1
011
000
1372  
1373 # otherwise there'd be nothing to actually do!
1374 }
1375 else {
1376 0 ▶ Carp::croak("$callback is not a known kind of reference")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $callback 0 0 0
1377 unless ref($callback);
1378 }
1379  
1380 464 my $empty_element_map = $start->_empty_element_map;
1381  
1382 464 my (@C) = [$start]; # a stack containing lists of children
1383 464 my (@I) = (-1); # initial value must be -1 for each list
1384 # a stack of indexes to current position in corresponding lists in @C
1385 # In each of these, 0 is the active point
1386  
1387 # scratch:
1388 464 my ($rv, # return value of callback
1389 $this, # current node
1390 $content_r, # child list of $this
1391 );
1392  
1393 # THE BIG LOOP
1394 464 ▶ while (@C) {
Branch: 1 branch
BranchTrueFalseTotal
if (@C) 9145 464 9609
1395  
1396 # Move to next item in this frame
1397 9145 ▶ if ( !defined( $I[0] ) or ++$I[0] >= @{ $C[0] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $I[0] or ++$I[0] >= @{$C[0];}) 4521 4624 9145
Condition66%2/3
not defined $I[0] or ++$I[0] >= @{$C[0];}
l!l&&r!l&&!r
045214624
MC/DC50%1/2
not defined $I[0] or ++$I[0] >= @{$C[0];}
not defined $I[0] ++$I[0] >= @{$C[0];}
Truth table66%2/3
not(A) or B
A= not defined $I[0]B= ++$I[0] >= @{$C[0];}
ABresult
1X1
011
000
1398  
1399 # We either went off the end of this list, or aborted the list
1400 # So call the post-order callback:
1401 4521 ▶ if ( $c_post
Branch: 1 branch
BranchTrueFalseTotal
if ($c_post and defined $I[0] and @C > 1 and defined($this = $C[1][$I[1]]) and ref $this and not $this->{'_empty_element'} || $$empty_element_map{$this->{'_tag'} or ''} && !@{$this->{'_content'};}) { } 139 4382 4521
Condition60%14/23
$c_post and defined $I[0] and @C > 1 and defined($this = $C[1][$I[1]]) and ref $this and not $this->{"_empty_element"} || $$empty_element_map{$this->{"_tag"} or ""} && !@{$this->{"_content"};}
!ll&&!rl&&r
43820139
$c_post and defined $I[0] and @C > 1 and defined($this = $C[1][$I[1]]) and ref $this
!ll&&!rl&&r
43820139
$c_post and defined $I[0] and @C > 1 and defined($this = $C[1][$I[1]])
!ll&&!rl&&r
43820139
$c_post and defined $I[0] and @C > 1
!ll&&!rl&&r
430973139
$c_post and defined $I[0]
!ll&&!rl&&r
43090212
$this->{'_empty_element'} || $$empty_element_map{$this->{'_tag'} or ''} && !@{$this->{'_content'};}
l!l&&r!l&&!r
00139
$$empty_element_map{$this->{"_tag"} or ""} and not @{$this->{"_content"};}
!ll&&!rl&&r
13900
$this->{'_tag'} || ''
l!l
1390
MC/DC25%2/8
$c_post and defined $I[0] and @C > 1 and defined($this = $C[1][$I[1]]) and ref $this and not $this->{"_empty_element"} || $$empty_element_map{$this->{"_tag"} or ""} && !@{$this->{"_content"};}
$c_post defined $I[0] @C > 1 defined($this = $C[1][$I[1]]) ref $this $this->{'_empty_element'} $$empty_element_map{$this->{"_tag"} or ""} not @{$this->{"_content"};}
MC/DC0%0/1
$this->{'_tag'} || ''
$this->{'_tag'}
Truth table33%3/9
A and B and C and D and E and not(F || G and not(H))
A= $c_postB= defined $I[0]C= @C > 1D= defined($this = $C[1][$I[1]])E= ref $thisF= $this->{'_empty_element'}G= $$empty_element_map{$this->{"_tag"} or ""}H= not @{$this->{"_content"};}
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
111111XX0
111110110
1111100X1
111110101
Truth table50%1/2
A
A= $this->{'_tag'}
Aresult
11
00
1402 and defined $I[0]
1403 and @C > 1
1404  
1405 # to keep the next line from autovivifying
1406 and defined( $this = $C[1][ $I[1] ] ) # sanity, and
1407 # suppress callbacks on exiting the fictional top frame
1408 and ref($this) # sanity
1409 and not(
1410 $this->{'_empty_element'}
1411 || ( $empty_element_map->{ $this->{'_tag'} || '' }
1412 0 && !@{ $this->{'_content'} } ) # RT #49932
1413 ) # things that don't get post-order callbacks
1414 )
1415 {
1416 139 shift @I;
1417 139 shift @C;
1418  
1419 #print "Post! at depth", scalar(@I), "\n";
1420 139 $rv = $c_post->(
1421  
1422 #map $_, # copy to avoid any messiness
1423 $this, # 0: this
1424 0, # 1: startflag (0 for post-order call)
1425 @I - 1, # 2: depth
1426 );
1427  
1428 139 ▶ if ( defined($rv) and ref($rv) eq $travsignal_package ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rv and ref $rv eq $travsignal_package) 0 139 139
Condition33%1/3
defined $rv and ref $rv eq $travsignal_package
!ll&&!rl&&r
01390
MC/DC0%0/2
defined $rv and ref $rv eq $travsignal_package
defined $rv ref $rv eq $travsignal_package
Truth table33%1/3
A and B
A= defined $rvB= ref $rv eq $travsignal_package
ABresult
0X0
100
111
1429 0 $rv = $$rv; #deref
1430 0 ▶ if ( $rv eq 'ABORT' ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($rv eq 'ABORT') { } 0 0 0
elsif ($rv eq 'PRUNE') { } 0 0 0
elsif ($rv eq 'PRUNE_SOFTLY') { } 0 0 0
elsif ($rv eq 'OK') { } 0 0 0
elsif ($rv eq 'PRUNE_UP') { } 0 0 0
1431 0 last; # end of this excursion!
1432 }
1433 elsif ( $rv eq 'PRUNE' ) {
1434  
1435 # NOOP on post!!
1436 }
1437 elsif ( $rv eq 'PRUNE_SOFTLY' ) {
1438  
1439 # NOOP on post!!
1440 }
1441 elsif ( $rv eq 'OK' ) {
1442  
1443 # noop
1444 }
1445 elsif ( $rv eq 'PRUNE_UP' ) {
1446 0 $I[0] = undef;
1447 }
1448 else {
1449 0 die "Unknown travsignal $rv\n";
1450  
1451 # should never happen
1452 }
1453 }
1454 }
1455 else {
1456 4382 shift @I;
1457 4382 shift @C;
1458 }
1459 4521 next;
1460 }
1461  
1462 4624 $this = $C[0][ $I[0] ];
1463  
1464 4624 ▶ if ($c_pre) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c_pre) 4624 0 4624
1465 4624 ▶ if ( defined $this and ref $this ) { # element
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this and ref $this) { } 4583 41 4624
Condition66%2/3
defined $this and ref $this
!ll&&!rl&&r
0414583
MC/DC50%1/2
defined $this and ref $this
defined $this ref $this
Truth table66%2/3
A and B
A= defined $thisB= ref $this
ABresult
0X0
100
111
1466 4583 $rv = $c_pre->(
1467  
1468 #map $_, # copy to avoid any messiness
1469 $this, # 0: this
1470 1, # 1: startflag (1 for pre-order call)
1471 @I - 1, # 2: depth
1472 );
1473 }
1474 else { # text segment
1475 41 ▶ next if $ignore_text;
Branch: 1 branch
BranchTrueFalseTotal
if $ignore_text 0 41 41
1476 41 $rv = $c_pre->(
1477  
1478 #map $_, # copy to avoid any messiness
1479 $this, # 0: this
1480 1, # 1: startflag (1 for pre-order call)
1481 @I - 1, # 2: depth
1482 $C[1][ $I[1] ], # 3: parent
1483 # And there will always be a $C[1], since
1484 # we can't start traversing at a text node
1485 $I[0] # 4: index of self in parent's content list
1486 );
1487 }
1488 4624 ▶ if ( not $rv ) { # returned false. Same as PRUNE.
Branch: 2 branches
BranchTrueFalseTotal
if (not $rv) { } 0 4624 4624
elsif (ref $rv eq $travsignal_package) { } 0 4624 4624
1489 0 next; # prune
1490 }
1491 elsif ( ref($rv) eq $travsignal_package ) {
1492 0 $rv = $$rv; # deref
1493 0 ▶ if ( $rv eq 'ABORT' ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($rv eq 'ABORT') { } 0 0 0
elsif ($rv eq 'PRUNE') { } 0 0 0
elsif ($rv eq 'PRUNE_SOFTLY') { } 0 0 0
elsif ($rv eq 'OK') { } 0 0 0
elsif ($rv eq 'PRUNE_UP') { } 0 0 0
1494 0 last; # end of this excursion!
1495 }
1496 elsif ( $rv eq 'PRUNE' ) {
1497 0 next;
1498 }
1499 elsif ( $rv eq 'PRUNE_SOFTLY' ) {
1500 0 ▶ if (ref($this)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this and not $this->{"_empty_element"} || $$empty_element_map{$this->{"_tag"} or ""}) 0 0 0
Condition0%0/8
ref $this and not $this->{"_empty_element"} || $$empty_element_map{$this->{"_tag"} or ""}
!ll&&!rl&&r
000
$this->{'_empty_element'} || $$empty_element_map{$this->{'_tag'} or ''}
l!l&&r!l&&!r
000
$this->{'_tag'} || ''
l!l
00
MC/DC0%0/3
ref $this and not $this->{"_empty_element"} || $$empty_element_map{$this->{"_tag"} or ""}
ref $this $this->{'_empty_element'} $$empty_element_map{$this->{'_tag'} or ''}
MC/DC0%0/1
$this->{'_tag'} || ''
$this->{'_tag'}
Truth table0%0/4
A and not(B || C)
A= ref $thisB= $this->{'_empty_element'}C= $$empty_element_map{$this->{'_tag'} or ''}
ABCresult
0XX0
11X0
1010
1001
Truth table0%0/2
A
A= $this->{'_tag'}
Aresult
11
00
1501 and not( $this->{'_empty_element'}
1502 || $empty_element_map->{ $this->{'_tag'} || '' } )
1503 )
1504 {
1505  
1506 # push a dummy empty content list just to trigger a post callback
1507 0 unshift @I, -1;
1508 0 unshift @C, $NIL;
1509 }
1510 0 next;
1511 }
1512 elsif ( $rv eq 'OK' ) {
1513  
1514 # noop
1515 }
1516 elsif ( $rv eq 'PRUNE_UP' ) {
1517 0 $I[0] = undef;
1518 0 next;
1519  
1520 # equivalent of last'ing out of the current child list.
1521  
1522 # Used to have PRUNE_UP_SOFTLY and ABORT_SOFTLY here, but the code
1523 # for these was seriously upsetting, served no particularly clear
1524 # purpose, and could not, I think, be easily implemented with a
1525 # recursive routine. All bad things!
1526 }
1527 else {
1528 0 die "Unknown travsignal $rv\n";
1529  
1530 # should never happen
1531 }
1532 }
1533  
1534 # else fall thru to meaning same as \'OK'.
1535 }
1536  
1537 # end of pre-order calling
1538  
1539 # Now queue up content list for the current element...
1540 4624 ▶ if (ref $this
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this and not !(($content_r = $this->{"_content"}) && @$content_r) && ($this->{"_empty_element"} || $$empty_element_map{$this->{"_tag"} or ""})) 4057 567 4624
Condition85%12/14
ref $this and not !(($content_r = $this->{"_content"}) && @$content_r) && ($this->{"_empty_element"} || $$empty_element_map{$this->{"_tag"} or ""})
!ll&&!rl&&r
415264057
!(($content_r = $this->{'_content'}) && @$content_r) && ($this->{'_empty_element'} || $$empty_element_map{$this->{'_tag'} or ''})
!ll&&!rl&&r
16212436526
($content_r = $this->{'_content'}) && @$content_r
!ll&&!rl&&r
2907551621
$this->{"_empty_element"} or $$empty_element_map{$this->{"_tag"} or ""}
l!l&&r!l&&!r
05262436
$this->{'_tag'} || ''
l!l
29620
MC/DC80%4/5
ref $this and not !(($content_r = $this->{"_content"}) && @$content_r) && ($this->{"_empty_element"} || $$empty_element_map{$this->{"_tag"} or ""})
ref $this ($content_r = $this->{'_content'}) @$content_r $this->{"_empty_element"} $$empty_element_map{$this->{"_tag"} or ""}
MC/DC0%0/1
$this->{'_tag'} || ''
$this->{'_tag'}
Truth table75%6/8
A and not(not(B && C) && D or E)
A= ref $thisB= ($content_r = $this->{'_content'})C= @$content_rD= $this->{"_empty_element"}E= $$empty_element_map{$this->{"_tag"} or ""}
ABCDEresult
0XXXX0
10X1X0
10X010
1101X0
110010
111XX1
10X001
110001
Truth table50%1/2
A
A= $this->{'_tag'}
Aresult
11
00
1541 and not( # ...except for those which...
1542 not( $content_r = $this->{'_content'} and @$content_r )
1543  
1544 # ...have empty content lists...
1545 and $this->{'_empty_element'}
1546 || $empty_element_map->{ $this->{'_tag'} || '' }
1547  
1548 # ...and that don't get post-order callbacks
1549 )
1550 )
1551 {
1552 4057 unshift @I, -1;
1553 4057 ▶ unshift @C, $content_r || $NIL;
Condition66%2/3
$content_r || $NIL
l!l&&r!l&&!r
166523920
MC/DC0%0/2
$content_r || $NIL
$content_r $NIL
Truth table66%2/3
A || B
A= $content_rB= $NIL
ABresult
1X1
011
000
1554  
1555 #print $this->{'_tag'}, " ($this) adds content_r ", $C[0], "\n";
1556 }
1557 }
1558 464 return $start;
1559 }
1560  
1561 1332 ▶sub is_inside {
Subroutine is_inside: called CC=8 SCAR=20.8
Pod undocumented
1562 1332 my $self = shift;
1563 1332 ▶ return unless @_; # if no items specified, I guess this is right.
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 1332 1332
1564  
1565 1332 my $current = $self;
1566  
1567 # the loop starts by looking at the given element
1568 1332 ▶ while ( defined $current and ref $current ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $current and ref $current) 3704 1163 4867
Condition66%2/3
defined $current and ref $current
!ll&&!rl&&r
116303704
MC/DC50%1/2
defined $current and ref $current
defined $current ref $current
Truth table66%2/3
A and B
A= defined $currentB= ref $current
ABresult
0X0
100
111
1569 3704 for (@_) {
1570 5817 ▶ if (ref) { # element
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_) { } 995 4822 5817
1571 995 ▶ return 1 if $_ eq $current;
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $current 81 914 995
1572 }
1573 else { # tag name
1574 4822 ▶ return 1 if $_ eq $current->{'_tag'};
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $current->{"_tag"} 88 4734 4822
1575 }
1576 }
1577 3535 $current = $current->{'_parent'};
1578 }
1579 1163 0;
1580 }
1581  
1582 0 ▶sub is_empty {
Subroutine is_empty: not called CC=2 SCAR=17.9
Pod undocumented
1583 0 my $self = shift;
1584 0 ▶ !$self->{'_content'} || !@{ $self->{'_content'} };
Condition0%0/3
$self->{'_content'} && @{$self->{'_content'};}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{'_content'} && @{$self->{'_content'};}
$self->{'_content'} @{$self->{'_content'};}
Truth table0%0/3
A && B
A= $self->{'_content'}B= @{$self->{'_content'};}
ABresult
0X0
100
111
1585 }
1586  
1587 65 ▶sub pindex {
Subroutine pindex: called CC=6 SCAR=18.7
Pod undocumented
1588 65 my $self = shift;
1589  
1590 65 ▶ my $parent = $self->{'_parent'} || return;
Condition100%2/2
$self->{'_parent'} || (return)
l!l
4322
MC/DC100%1/1
$self->{'_parent'} || (return)
$self->{'_parent'}
Truth table100%2/2
A
A= $self->{'_parent'}
Aresult
11
00
1591 43 ▶ my $pc = $parent->{'_content'} || return;
Condition50%1/2
$parent->{'_content'} || (return)
l!l
430
MC/DC0%0/1
$parent->{'_content'} || (return)
$parent->{'_content'}
Truth table50%1/2
A
A= $parent->{'_content'}
Aresult
11
00
1592 43 ▶ for ( my $i = 0; $i < @$pc; ++$i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$pc) 69 0 69
1593 69 ▶ return $i if ref $pc->[$i] and $pc->[$i] eq $self;
Branch: 1 branch
BranchTrueFalseTotal
if ref $pc->[$i] and $pc->[$i] eq $self 43 26 69
Condition66%2/3
ref $pc->[$i] and $pc->[$i] eq $self
!ll&&!rl&&r
02643
MC/DC50%1/2
ref $pc->[$i] and $pc->[$i] eq $self
ref $pc->[$i] $pc->[$i] eq $self
Truth table66%2/3
A and B
A= ref $pc->[$i]B= $pc->[$i] eq $self
ABresult
0X0
100
111
1594 }
1595 0 return; # we shouldn't ever get here
1596 }
1597  
1598 #--------------------------------------------------------------------------
1599  
1600 2 ▶sub left {
Subroutine left: called CC=14 SCAR=36.0
Pod undocumented
1601 2 ▶ Carp::croak "left() is supposed to be an object method"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 0 2 2
1602 unless ref $_[0];
1603 2 ▶ my $pc = ( $_[0]->{'_parent'} || return )->{'_content'}
Condition75%3/4
+($_[0]{'_parent'} || (return))->{'_content'} || die('parent is childless?')
l!l
10
$_[0]{'_parent'} || (return)
l!l
11
MC/DC0%0/1
+($_[0]{'_parent'} || (return))->{'_content'} || die('parent is childless?')
$_[0]{'_parent'}
Truth table50%1/2
A
A= $_[0]{'_parent'}
Aresult
11
00
1604 || die "parent is childless?";
1605  
1606 1 ▶ die "parent is childless" unless @$pc;
Branch: 1 branch
BranchTrueFalseTotal
unless @$pc 0 1 1
1607 1 ▶ return if @$pc == 1; # I'm an only child
Branch: 1 branch
BranchTrueFalseTotal
if @$pc == 1 0 1 1
1608  
1609 1 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 1 1
1610 0 my @out;
1611 0 foreach my $j (@$pc) {
1612 0 ▶ return @out if ref $j and $j eq $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $j and $j eq $_[0] 0 0 0
Condition0%0/3
ref $j and $j eq $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
ref $j and $j eq $_[0]
ref $j $j eq $_[0]
Truth table0%0/3
A and B
A= ref $jB= $j eq $_[0]
ABresult
0X0
100
111
1613 0 push @out, $j;
1614 }
1615 }
1616 else {
1617 1 ▶ for ( my $i = 0; $i < @$pc; ++$i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$pc) 2 0 2
1618 2 ▶ return $i ? $pc->[ $i - 1 ] : undef
Branch: 2 branches
BranchTrueFalseTotal
if ref $pc->[$i] and $pc->[$i] eq $_[0] 1 1 2
$i ? : 1 0 1
Condition66%2/3
ref $pc->[$i] and $pc->[$i] eq $_[0]
!ll&&!rl&&r
011
MC/DC50%1/2
ref $pc->[$i] and $pc->[$i] eq $_[0]
ref $pc->[$i] $pc->[$i] eq $_[0]
Truth table66%2/3
A and B
A= ref $pc->[$i]B= $pc->[$i] eq $_[0]
ABresult
0X0
100
111
1619 if ref $pc->[$i] and $pc->[$i] eq $_[0];
1620 }
1621 }
1622  
1623 0 die "I'm not in my parent's content list?";
1624 0 return;
1625 }
1626  
1627 14 ▶sub right {
Subroutine right: called CC=16 SCAR=42.2
Pod undocumented
1628 14 ▶ Carp::croak "right() is supposed to be an object method"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 0 14 14
1629 unless ref $_[0];
1630 14 ▶ my $pc = ( $_[0]->{'_parent'} || return )->{'_content'}
Condition75%3/4
+($_[0]{'_parent'} || (return))->{'_content'} || die('parent is childless?')
l!l
80
$_[0]{'_parent'} || (return)
l!l
86
MC/DC0%0/1
+($_[0]{'_parent'} || (return))->{'_content'} || die('parent is childless?')
$_[0]{'_parent'}
Truth table50%1/2
A
A= $_[0]{'_parent'}
Aresult
11
00
1631 || die "parent is childless?";
1632  
1633 8 ▶ die "parent is childless" unless @$pc;
Branch: 1 branch
BranchTrueFalseTotal
unless @$pc 0 8 8
1634 8 ▶ return if @$pc == 1; # I'm an only child
Branch: 1 branch
BranchTrueFalseTotal
if @$pc == 1 1 7 8
1635  
1636 7 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 7 7
1637 0 my ( @out, $seen );
1638 0 foreach my $j (@$pc) {
1639 0 ▶ if ($seen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seen) { } 0 0 0
1640 0 push @out, $j;
1641 }
1642 else {
1643 0 ▶ $seen = 1 if ref $j and $j eq $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $j and $j eq $_[0] 0 0 0
Condition0%0/3
ref $j and $j eq $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
ref $j and $j eq $_[0]
ref $j $j eq $_[0]
Truth table0%0/3
A and B
A= ref $jB= $j eq $_[0]
ABresult
0X0
100
111
1644 }
1645 }
1646 0 ▶ die "I'm not in my parent's content list?" unless $seen;
Branch: 1 branch
BranchTrueFalseTotal
unless $seen 0 0 0
1647 0 return @out;
1648 }
1649 else {
1650 7 ▶ for ( my $i = 0; $i < @$pc; ++$i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$pc) 7 0 7
1651 7 ▶ return +( $i == $#$pc ) ? undef : $pc->[ $i + 1 ]
Branch: 2 branches
BranchTrueFalseTotal
if ref $pc->[$i] and $pc->[$i] eq $_[0] 7 0 7
$i == $pc->$#* ? : 0 7 7
Condition33%1/3
ref $pc->[$i] and $pc->[$i] eq $_[0]
!ll&&!rl&&r
007
MC/DC0%0/2
ref $pc->[$i] and $pc->[$i] eq $_[0]
ref $pc->[$i] $pc->[$i] eq $_[0]
Truth table33%1/3
A and B
A= ref $pc->[$i]B= $pc->[$i] eq $_[0]
ABresult
0X0
100
111
1652 if ref $pc->[$i] and $pc->[$i] eq $_[0];
1653 }
1654 0 die "I'm not in my parent's content list?";
1655 0 return;
1656 }
1657 }
1658  
1659 #--------------------------------------------------------------------------
1660  
1661 33 ▶sub address {
Subroutine address: called CC=11 SCAR=26.3
Pod undocumented
1662 33 ▶ if ( @_ == 1 ) { # report-address form
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 22 11 33
1663 22 ▶ return join(
Condition100%2/2
$_->pindex || '0'
l!l
2342
MC/DC100%1/1
$_->pindex || '0'
$_->pindex
Truth table100%2/2
A
A= $_->pindex
Aresult
11
00
1664 '.',
1665 reverse( # so it starts at the top
1666 map( $_->pindex() || '0', # so that root's undef -> '0'
1667 $_[0], # self and...
1668 $_[0]->lineage )
1669 )
1670 );
1671 }
1672 else { # get-node-at-address
1673 11 my @stack = split( /\./, $_[1] );
1674 11 my $here;
1675  
1676 11 ▶ if ( @stack and !length $stack[0] ) { # relative addressing
Branch: 1 branch
BranchTrueFalseTotal
if (@stack and not length $stack[0]) { } 0 11 11
Condition33%1/3
@stack and not length $stack[0]
!ll&&!rl&&r
0110
MC/DC0%0/2
@stack and not length $stack[0]
@stack not length $stack[0]
Truth table33%1/3
A and not(B)
A= @stackB= not length $stack[0]
ABresult
0X0
100
111
1677 0 $here = $_[0];
1678 0 shift @stack;
1679 }
1680 else { # absolute addressing
1681 11 ▶ return unless 0 == shift @stack; # to pop the initial 0-for-root
Branch: 1 branch
BranchTrueFalseTotal
unless 0 == shift @stack 0 11 11
1682 11 $here = $_[0]->root;
1683 }
1684  
1685 11 ▶ while (@stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stack) 16 11 27
1686 return
1687 unless $here->{'_content'}
1688 16 ▶ and @{ $here->{'_content'} } > $stack[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $here->{"_content"} and @{$here->{"_content"};} > $stack[0] 0 16 16
Condition33%1/3
$here->{"_content"} and @{$here->{"_content"};} > $stack[0]
!ll&&!rl&&r
0016
MC/DC0%0/2
$here->{"_content"} and @{$here->{"_content"};} > $stack[0]
$here->{"_content"} @{$here->{"_content"};} > $stack[0]
Truth table33%1/3
A and B
A= $here->{"_content"}B= @{$here->{"_content"};} > $stack[0]
ABresult
0X0
100
111
1689  
1690 # make sure the index isn't too high
1691 16 $here = $here->{'_content'}[ shift @stack ];
1692 16 ▶ return if @stack and not ref $here;
Branch: 1 branch
BranchTrueFalseTotal
if @stack and not ref $here 0 16 16
Condition66%2/3
@stack and not ref $here
!ll&&!rl&&r
880
MC/DC0%0/2
@stack and not ref $here
@stack not ref $here
Truth table66%2/3
A and not(B)
A= @stackB= not ref $here
ABresult
0X0
100
111
1693  
1694 # we hit a text node when we expected a non-terminal element node
1695 }
1696  
1697 11 return $here;
1698 }
1699 }
1700  
1701 0 ▶sub depth {
Subroutine depth: not called CC=3 SCAR=24.8
Pod undocumented
1702 0 my $here = $_[0];
1703 0 my $depth = 0;
1704 0 ▶ while ( defined( $here = $here->{'_parent'} ) and ref($here) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($here = $here->{"_parent"}) and ref $here) 0 0 0
Condition0%0/3
defined($here = $here->{"_parent"}) and ref $here
!ll&&!rl&&r
000
MC/DC0%0/2
defined($here = $here->{"_parent"}) and ref $here
defined($here = $here->{"_parent"}) ref $here
Truth table0%0/3
A and B
A= defined($here = $here->{"_parent"})B= ref $here
ABresult
0X0
100
111
1705 0 ++$depth;
1706 }
1707 0 return $depth;
1708 }
1709  
1710 474 ▶sub root {
Subroutine root: called CC=3 SCAR=11.0
Pod undocumented
1711 474 my $here = my $root = shift;
1712 474 ▶ while ( defined( $here = $here->{'_parent'} ) and ref($here) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($here = $here->{"_parent"}) and ref $here) 1570 474 2044
Condition66%2/3
defined($here = $here->{"_parent"}) and ref $here
!ll&&!rl&&r
47401570
MC/DC50%1/2
defined($here = $here->{"_parent"}) and ref $here
defined($here = $here->{"_parent"}) ref $here
Truth table66%2/3
A and B
A= defined($here = $here->{"_parent"})B= ref $here
ABresult
0X0
100
111
1713 1570 $root = $here;
1714 }
1715 474 return $root;
1716 }
1717  
1718 22 ▶sub lineage {
Subroutine lineage: called CC=3 SCAR=11.0
Pod undocumented
1719 22 my $here = shift;
1720 22 my @lineage;
1721 22 ▶ while ( defined( $here = $here->{'_parent'} ) and ref($here) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($here = $here->{"_parent"}) and ref $here) 43 22 65
Condition66%2/3
defined($here = $here->{"_parent"}) and ref $here
!ll&&!rl&&r
22043
MC/DC50%1/2
defined($here = $here->{"_parent"}) and ref $here
defined($here = $here->{"_parent"}) ref $here
Truth table66%2/3
A and B
A= defined($here = $here->{"_parent"})B= ref $here
ABresult
0X0
100
111
1722 43 push @lineage, $here;
1723 }
1724 22 return @lineage;
1725 }
1726  
1727 0 ▶sub lineage_tag_names {
Subroutine lineage_tag_names: not called CC=3 SCAR=24.8
Pod undocumented
1728 0 my $here = my $start = shift;
1729 0 my @lineage_names;
1730 0 ▶ while ( defined( $here = $here->{'_parent'} ) and ref($here) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($here = $here->{"_parent"}) and ref $here) 0 0 0
Condition0%0/3
defined($here = $here->{"_parent"}) and ref $here
!ll&&!rl&&r
000
MC/DC0%0/2
defined($here = $here->{"_parent"}) and ref $here
defined($here = $here->{"_parent"}) ref $here
Truth table0%0/3
A and B
A= defined($here = $here->{"_parent"})B= ref $here
ABresult
0X0
100
111
1731 0 push @lineage_names, $here->{'_tag'};
1732 }
1733 0 return @lineage_names;
1734 }
1735  
1736 0 ▶sub descendents { shift->descendants(@_) }
Subroutine descendents: not called CC=1 SCAR=6.9
Pod undocumented
1737  
1738 391 ▶sub descendants {
Subroutine descendants: called CC=2 SCAR=8.1
Pod undocumented
1739 391 my $start = shift;
1740 391 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 391 0 391
1741 391 my @descendants;
1742 $start->traverse(
1743 [ # pre-order sub only
1744 4433 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1745 4433 push( @descendants, $_[0] );
1746 4433 return 1;
1747 },
1748 undef # no post
1749 391 ],
1750 1, # ignore text
1751 );
1752 391 shift @descendants; # so $self doesn't appear in the list
1753 391 return @descendants;
1754 }
1755 else { # just returns a scalar
1756 0 my $descendants = -1; # to offset $self being counted
1757 $start->traverse(
1758 [ # pre-order sub only
1759 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1760 0 ++$descendants;
1761 0 return 1;
1762 },
1763 undef # no post
1764 0 ],
1765 1, # ignore text
1766 );
1767 0 return $descendants;
1768 }
1769 }
1770  
1771 161 ▶sub find { shift->find_by_tag_name(@_) }
Subroutine find: called CC=1 SCAR=0.0
Pod undocumented
1772  
1773 # yup, a handy alias
1774  
1775 161 ▶sub find_by_tag_name {
Subroutine find_by_tag_name: called CC=9 SCAR=22.0
Pod undocumented
1776 161 my (@pile) = shift(@_); # start out the to-do stack for the traverser
1777 161 ▶ Carp::croak "find_by_tag_name can be called only as an object method"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pile[0] 0 161 161
1778 unless ref $pile[0];
1779 161 ▶ return () unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 161 161
1780 161 my (@tags) = $pile[0]->_fold_case(@_);
1781 161 my ( @matching, $this, $this_tag );
1782 161 ▶ while (@pile) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pile) 1293 127 1420
1783 1293 $this_tag = ( $this = shift @pile )->{'_tag'};
1784 1293 foreach my $t (@tags) {
1785 1377 ▶ if ( $t eq $this_tag ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq $this_tag) 271 1106 1377
1786 271 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 237 34 271
1787 237 push @matching, $this;
1788 237 last;
1789 }
1790 else {
1791 34 return $this;
1792 }
1793 }
1794 }
1795 1259 ▶ unshift @pile, grep ref($_), @{ $this->{'_content'} || next };
Condition100%2/2
$this->{'_content'} || (next)
l!l
643616
MC/DC100%1/1
$this->{'_content'} || (next)
$this->{'_content'}
Truth table100%2/2
A
A= $this->{'_content'}
Aresult
11
00
1796 }
1797 127 ▶ return @matching if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 98 29 127
1798 29 return;
1799 }
1800  
1801 0 ▶sub find_by_attribute {
Subroutine find_by_attribute: not called CC=4 SCAR=30.0
Pod undocumented
1802  
1803 # We could limit this to non-internal attributes, but hey.
1804 0 my ( $self, $attribute, $value ) = @_;
1805 0 ▶ Carp::croak "Attribute must be a defined value!"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attribute 0 0 0
1806 unless defined $attribute;
1807 0 $attribute = $self->_fold_case($attribute);
1808  
1809 0 my @matching;
1810 0 my $wantarray = wantarray;
1811 0 my $quit;
1812 $self->traverse(
1813 [ # pre-order only
1814 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
1815 0 ▶ if ( exists $_[0]{$attribute}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_[0]{$attribute} and $_[0]{$attribute} eq $value) 0 0 0
Condition0%0/3
exists $_[0]{$attribute} and $_[0]{$attribute} eq $value
!ll&&!rl&&r
000
MC/DC0%0/2
exists $_[0]{$attribute} and $_[0]{$attribute} eq $value
exists $_[0]{$attribute} $_[0]{$attribute} eq $value
Truth table0%0/3
A and B
A= exists $_[0]{$attribute}B= $_[0]{$attribute} eq $value
ABresult
0X0
100
111
1816 and $_[0]{$attribute} eq $value )
1817 {
1818 0 push @matching, $_[0];
1819 0 ▶ return HTML::DOM::_Element::ABORT
Branch: 1 branch
BranchTrueFalseTotal
unless $wantarray 0 0 0
1820 unless $wantarray; # only take the first
1821 }
1822 0 1; # keep traversing
1823 },
1824 undef # no post
1825 0 ],
1826 1, # yes, ignore text nodes.
1827 );
1828  
1829 0 ▶ if ($wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wantarray) { } 0 0 0
1830 0 return @matching;
1831 }
1832 else {
1833 0 ▶ return unless @matching;
Branch: 1 branch
BranchTrueFalseTotal
unless @matching 0 0 0
1834 0 return $matching[0];
1835 }
1836 }
1837  
1838 #--------------------------------------------------------------------------
1839  
1840 186 ▶sub look_down {
Subroutine look_down: called CC=22 SCAR=31.4
Pod undocumented
1841 186 ▶ ref( $_[0] ) or Carp::croak "look_down works only as an object method";
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] or Carp::croak("look_down works only as an object method") 186 0 186
1842  
1843 186 my @criteria;
1844 186 ▶ for ( my $i = 1; $i < @_; ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @_) 339 186 525
1845 339 ▶ Carp::croak "Can't use undef as an attribute name"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[$i] 0 339 339
1846 unless defined $_[$i];
1847 339 ▶ if ( ref $_[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[$i]) { } 18 321 339
1848 18 ▶ Carp::croak "A " . ref( $_[$i] ) . " value is not a criterion"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[$i] eq "CODE" 0 18 18
1849 unless ref $_[$i] eq 'CODE';
1850 18 push @criteria, $_[ $i++ ];
1851 }
1852 else {
1853 321 ▶ Carp::croak "param list to look_down ends in a key!" if $i == $#_;
Branch: 1 branch
BranchTrueFalseTotal
if $i == $#_ 0 321 321
1854 321 ▶ push @criteria, [
Branch: 2 branches
BranchTrueFalseTotal
defined $_[$i + 1] ? : 321 0 321
ref $_[$i + 1] ? : 165 156 321
1855 scalar( $_[0]->_fold_case( $_[$i] ) ),
1856 defined( $_[ $i + 1 ] )
1857 ? ( ( ref $_[ $i + 1 ] ? $_[ $i + 1 ] : lc( $_[ $i + 1 ] ) ),
1858 ref( $_[ $i + 1 ] )
1859 )
1860  
1861 # yes, leave that LC!
1862 : undef
1863 ];
1864 321 $i += 2;
1865 }
1866 }
1867 186 ▶ Carp::croak "No criteria?" unless @criteria;
Branch: 1 branch
BranchTrueFalseTotal
unless @criteria 0 186 186
1868  
1869 186 my (@pile) = ( $_[0] );
1870 186 my ( @matching, $val, $this );
1871 Node:
1872 186 ▶ while ( defined( $this = shift @pile ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($this = shift @pile)) 1586 180 1766
1873  
1874 # Yet another traverser implemented with merely iterative code.
1875 1586 foreach my $c (@criteria) {
1876 1592 ▶ if ( ref($c) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $c eq 'CODE') { } 177 1415 1592
1877 177 ▶ next Node unless $c->($this); # jump to the continue block
Branch: 1 branch
BranchTrueFalseTotal
unless &$c($this) 157 20 177
1878 }
1879 else { # it's an attr-value pair
1880 next Node # jump to the continue block
1881 if # two values are unequal if:
1882 1415 ▶ ( defined( $val = $this->{ $c->[0] } ) )
Branch: 3 branches
BranchTrueFalseTotal
if defined($val = $$this{$c->[0]}) ? !defined($c->[1]) || ($c->[2] eq "Regexp" ? !($val =~ /$c->[1]/) : ref $val ne $c->[2] || lc $val ne lc $c->[1]) : defined $c->[1] 1356 59 1415
defined($val = $$this{$c->[0]}) ? : 1391 24 1415
$c->[2] eq 'Regexp' ? : 267 1124 1391
Condition66%4/6
not defined $c->[1] or $c->[2] eq "Regexp" ? !($val =~ /$c->[1]/) : ref $val ne $c->[2] || lc $val ne lc $c->[1]
l!l&&r!l&&!r
0133259
ref $val ne $c->[2] or lc $val ne lc $c->[1]
l!l&&r!l&&!r
0111212
MC/DC50%1/2
not defined $c->[1] or $c->[2] eq "Regexp" ? !($val =~ /$c->[1]/) : ref $val ne $c->[2] || lc $val ne lc $c->[1]
not defined $c->[1] $c->[2] eq "Regexp" ? !($val =~ /$c->[1]/) : ref $val ne $c->[2] || lc $val ne lc $c->[1]
MC/DC50%1/2
ref $val ne $c->[2] or lc $val ne lc $c->[1]
ref $val ne $c->[2] lc $val ne lc $c->[1]
Truth table66%2/3
not(A) or B
A= not defined $c->[1]B= $c->[2] eq "Regexp" ? !($val =~ /$c->[1]/) : ref $val ne $c->[2] || lc $val ne lc $c->[1]
ABresult
1X1
011
000
Truth table66%2/3
A or B
A= ref $val ne $c->[2]B= lc $val ne lc $c->[1]
ABresult
1X1
011
000
1883 ? ( !defined $c->[ 1
1884 ] # actual is def, critval is undef => fail
1885 # allow regex matching
1886 # allow regex matching
1887 or (
1888 $c->[2] eq 'Regexp'
1889 ? $val !~ $c->[1]
1890 : ( ref $val ne $c->[2]
1891  
1892 # have unequal ref values => fail
1893 or lc($val) ne lc( $c->[1] )
1894  
1895 # have unequal lc string values => fail
1896 )
1897 )
1898 )
1899 : ( defined $c->[1]
1900 ) # actual is undef, critval is def => fail
1901 }
1902 }
1903  
1904 # We make it this far only if all the criteria passed.
1905 73 ▶ return $this unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 6 67 73
1906 67 push @matching, $this;
1907 }
1908 continue {
1909 1580 ▶ unshift @pile, grep ref($_), @{ $this->{'_content'} || $nillio };
Condition66%2/3
$this->{'_content'} || $nillio
l!l&&r!l&&!r
6299510
MC/DC0%0/2
$this->{'_content'} || $nillio
$this->{'_content'} $nillio
Truth table66%2/3
A || B
A= $this->{'_content'}B= $nillio
ABresult
1X1
011
000
1910 }
1911 180 ▶ return @matching if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 33 147 180
1912 147 return;
1913 }
1914  
1915 169 ▶sub look_up {
Subroutine look_up: called CC=22 SCAR=35.7
Pod undocumented
1916 169 ▶ ref( $_[0] ) or Carp::croak "look_up works only as an object method";
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] or Carp::croak("look_up works only as an object method") 169 0 169
1917  
1918 169 my @criteria;
1919 169 ▶ for ( my $i = 1; $i < @_; ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @_) 169 169 338
1920 169 ▶ Carp::croak "Can't use undef as an attribute name"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[$i] 0 169 169
1921 unless defined $_[$i];
1922 169 ▶ if ( ref $_[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[$i]) { } 0 169 169
1923 0 ▶ Carp::croak "A " . ref( $_[$i] ) . " value is not a criterion"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[$i] eq "CODE" 0 0 0
1924 unless ref $_[$i] eq 'CODE';
1925 0 push @criteria, $_[ $i++ ];
1926 }
1927 else {
1928 169 ▶ Carp::croak "param list to look_up ends in a key!" if $i == $#_;
Branch: 1 branch
BranchTrueFalseTotal
if $i == $#_ 0 169 169
1929 169 ▶ push @criteria, [
Branch: 2 branches
BranchTrueFalseTotal
defined $_[$i + 1] ? : 169 0 169
ref $_[$i + 1] ? : 0 169 169
1930 scalar( $_[0]->_fold_case( $_[$i] ) ),
1931 defined( $_[ $i + 1 ] )
1932 ? ( ( ref $_[ $i + 1 ] ? $_[ $i + 1 ] : lc( $_[ $i + 1 ] ) ),
1933 ref( $_[ $i + 1 ] )
1934 )
1935 : undef # Yes, leave that LC!
1936 ];
1937 169 $i += 2;
1938 }
1939 }
1940 169 ▶ Carp::croak "No criteria?" unless @criteria;
Branch: 1 branch
BranchTrueFalseTotal
unless @criteria 0 169 169
1941  
1942 169 my ( @matching, $val );
1943 169 my $this = $_[0];
1944 Node:
1945 169 while (1) {
1946  
1947 # You'll notice that the code here is almost the same as for look_down.
1948 472 foreach my $c (@criteria) {
1949 472 ▶ if ( ref($c) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $c eq 'CODE') { } 0 472 472
1950 0 ▶ next Node unless $c->($this); # jump to the continue block
Branch: 1 branch
BranchTrueFalseTotal
unless &$c($this) 0 0 0
1951 }
1952 else { # it's an attr-value pair
1953 next Node # jump to the continue block
1954 if # two values are unequal if:
1955 472 ▶ ( defined( $val = $this->{ $c->[0] } ) )
Branch: 3 branches
BranchTrueFalseTotal
if defined($val = $$this{$c->[0]}) ? !defined($c->[1]) || ($c->[2] eq "Regexp" ? !($val =~ /$c->[1]/) : ref $val ne $c->[2] || lc $val ne $c->[1]) : defined $c->[1] 337 135 472
defined($val = $$this{$c->[0]}) ? : 472 0 472
$c->[2] eq 'Regexp' ? : 0 472 472
Condition66%4/6
not defined $c->[1] or $c->[2] eq "Regexp" ? !($val =~ /$c->[1]/) : ref $val ne $c->[2] || lc $val ne $c->[1]
l!l&&r!l&&!r
0337135
ref $val ne $c->[2] or lc $val ne $c->[1]
l!l&&r!l&&!r
0337135
MC/DC50%1/2
not defined $c->[1] or $c->[2] eq "Regexp" ? !($val =~ /$c->[1]/) : ref $val ne $c->[2] || lc $val ne $c->[1]
not defined $c->[1] $c->[2] eq "Regexp" ? !($val =~ /$c->[1]/) : ref $val ne $c->[2] || lc $val ne $c->[1]
MC/DC50%1/2
ref $val ne $c->[2] or lc $val ne $c->[1]
ref $val ne $c->[2] lc $val ne $c->[1]
Truth table66%2/3
not(A) or B
A= not defined $c->[1]B= $c->[2] eq "Regexp" ? !($val =~ /$c->[1]/) : ref $val ne $c->[2] || lc $val ne $c->[1]
ABresult
1X1
011
000
Truth table66%2/3
A or B
A= ref $val ne $c->[2]B= lc $val ne $c->[1]
ABresult
1X1
011
000
1956 ? ( !defined $c->[ 1
1957 ] # actual is def, critval is undef => fail
1958 or (
1959 $c->[2] eq 'Regexp'
1960 ? $val !~ $c->[1]
1961 : ( ref $val ne $c->[2]
1962  
1963 # have unequal ref values => fail
1964 or lc($val) ne $c->[1]
1965  
1966 # have unequal lc string values => fail
1967 )
1968 )
1969 )
1970 : ( defined $c->[1]
1971 ) # actual is undef, critval is def => fail
1972 }
1973 }
1974  
1975 # We make it this far only if all the criteria passed.
1976 135 ▶ return $this unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 105 30 135
1977 30 push @matching, $this;
1978 }
1979 continue {
1980 367 ▶ last unless defined( $this = $this->{'_parent'} ) and ref $this;
Branch: 1 branch
BranchTrueFalseTotal
unless defined($this = $this->{"_parent"}) and ref $this 64 303 367
Condition66%2/3
defined($this = $this->{"_parent"}) and ref $this
!ll&&!rl&&r
640303
MC/DC50%1/2
defined($this = $this->{"_parent"}) and ref $this
defined($this = $this->{"_parent"}) ref $this
Truth table66%2/3
A and B
A= defined($this = $this->{"_parent"})B= ref $this
ABresult
0X0
100
111
1981 }
1982  
1983 64 ▶ return @matching if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 63 1 64
1984 1 return;
1985 }
1986  
1987 #--------------------------------------------------------------------------
1988  
1989 0 ▶sub attr_get_i {
Subroutine attr_get_i: not called CC=14 SCAR=53.5
Pod undocumented
1990 0 ▶ if ( @_ > 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 2) { } 0 0 0
1991 0 my $self = shift;
1992 0 ▶ Carp::croak "No attribute names can be undef!"
Branch: 1 branch
BranchTrueFalseTotal
if grep((!defined($_)), @_) 0 0 0
1993 if grep !defined($_), @_;
1994 0 my @attributes = $self->_fold_case(@_);
1995 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
1996 0 my @out;
1997 0 foreach my $x ( $self, $self->lineage ) {
1998 push @out,
1999 0 ▶ map { exists( $x->{$_} ) ? $x->{$_} : () } @attributes;
Branch: 1 branch
BranchTrueFalseTotal
exists $x->{$_} ? : 0 0 0
2000 }
2001 0 return @out;
2002 }
2003 else {
2004 0 foreach my $x ( $self, $self->lineage ) {
2005 0 foreach my $attribute (@attributes) {
2006 return $x->{$attribute}
2007 0 ▶ if exists $x->{$attribute}; # found
Branch: 1 branch
BranchTrueFalseTotal
if exists $x->{$attribute} 0 0 0
2008 }
2009 }
2010 0 return; # never found
2011 }
2012 }
2013 else {
2014  
2015 # Single-attribute search. Simpler, most common, so optimize
2016 # for the most common case
2017 0 ▶ Carp::croak "Attribute name must be a defined value!"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 0 0
2018 unless defined $_[1];
2019 0 my $self = $_[0];
2020 0 my $attribute = $self->_fold_case( $_[1] );
2021 0 ▶ if (wantarray) { # list context
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
2022 return
2023 0 ▶ map { exists( $_->{$attribute} ) ? $_->{$attribute} : () }
Branch: 1 branch
BranchTrueFalseTotal
exists $_->{$attribute} ? : 0 0 0
2024 $self, $self->lineage;
2025 }
2026 else { # scalar context
2027 0 foreach my $x ( $self, $self->lineage ) {
2028 0 ▶ return $x->{$attribute} if exists $x->{$attribute}; # found
Branch: 1 branch
BranchTrueFalseTotal
if exists $x->{$attribute} 0 0 0
2029 }
2030 0 return; # never found
2031 }
2032 }
2033 }
2034  
2035 0 ▶sub tagname_map {
Subroutine tagname_map: not called CC=6 SCAR=37.4
Pod undocumented
2036 0 my (@pile) = $_[0]; # start out the to-do stack for the traverser
2037 0 ▶ Carp::croak "find_by_tag_name can be called only as an object method"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pile[0] 0 0 0
2038 unless ref $pile[0];
2039 0 my ( %map, $this_tag, $this );
2040 0 ▶ while (@pile) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pile) 0 0 0
2041 $this_tag = ''
2042 0 ▶ unless defined( $this_tag = ( $this = shift @pile )->{'_tag'} )
Branch: 1 branch
BranchTrueFalseTotal
unless defined($this_tag = +($this = shift @pile)->{"_tag"}) 0 0 0
2043 ; # dance around the strange case of having an undef tagname.
2044 0 ▶ push @{ $map{$this_tag} ||= [] }, $this; # add to map
Condition0%0/2
$map{$this_tag} ||= []
l!l
00
MC/DC0%0/1
$map{$this_tag} ||= []
$map{$this_tag}
Truth table0%0/2
A
A= $map{$this_tag}
Aresult
11
00
2045 unshift @pile, grep ref($_),
2046 0 ▶ @{ $this->{'_content'} || next }; # traverse
Condition0%0/2
$this->{'_content'} || (next)
l!l
00
MC/DC0%0/1
$this->{'_content'} || (next)
$this->{'_content'}
Truth table0%0/2
A
A= $this->{'_content'}
Aresult
11
00
2047 }
2048 0 return \%map;
2049 }
2050  
2051 0 ▶sub extract_links {
Subroutine extract_links: not called CC=1 SCAR=6.9
Pod undocumented
2052 0 my $start = shift;
2053  
2054 0 my %wantType;
2055 0 @wantType{ $start->_fold_case(@_) } = (1) x @_; # if there were any
2056 0 my $wantType = scalar(@_);
2057  
2058 0 my @links;
2059  
2060 # TODO: add xml:link?
2061  
2062 0 my ( $link_attrs, $tag, $self, $val ); # scratch for each iteration
2063 $start->traverse(
2064 0 ▶ [ sub { # pre-order call only
Subroutine __ANON__: not called CC=7 SCAR=40.3
2065 0 $self = $_[0];
2066  
2067 0 $tag = $self->{'_tag'};
2068 return 1
2069 0 ▶ if $wantType && !$wantType{$tag}; # if we're selective
Branch: 1 branch
BranchTrueFalseTotal
if $wantType and not $wantType{$tag} 0 0 0
Condition0%0/3
$wantType and not $wantType{$tag}
!ll&&!rl&&r
000
MC/DC0%0/2
$wantType and not $wantType{$tag}
$wantType not $wantType{$tag}
Truth table0%0/3
A and not(B)
A= $wantTypeB= not $wantType{$tag}
ABresult
0X0
100
111
2070  
2071 0 ▶ if (defined(
Branch: 1 branch
BranchTrueFalseTotal
if (defined($link_attrs = $HTML::DOM::_Element::linkElements{$tag})) 0 0 0
2072 $link_attrs = $HTML::DOM::_Element::linkElements{$tag}
2073 )
2074 )
2075 {
2076  
2077 # If this is a tag that has any link attributes,
2078 # look over possibly present link attributes,
2079 # saving the value, if found.
2080 0 ▶ for ( ref($link_attrs) ? @$link_attrs : $link_attrs ) {
Branch: 1 branch
BranchTrueFalseTotal
ref $link_attrs ? : 0 0 0
2081 0 ▶ if ( defined( $val = $self->attr($_) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($val = $self->attr($_))) 0 0 0
2082 0 push( @links, [ $val, $self, $_, $tag ] );
2083 }
2084 }
2085 }
2086 0 1; # return true, so we keep recursing
2087 },
2088 undef
2089 0 ],
2090 1, # ignore text nodes
2091 );
2092 0 \@links;
2093 }
2094  
2095 0 ▶sub simplify_pres {
Subroutine simplify_pres: not called CC=1 SCAR=6.9
Pod undocumented
2096 0 my $pre = 0;
2097  
2098 0 my $sub;
2099 my $line;
2100 0 ▶ $sub = sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
2101 0 ▶ ++$pre if $_[0]->{'_tag'} eq 'pre';
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"_tag"} eq "pre" 0 0 0
2102 0 ▶ foreach my $it ( @{ $_[0]->{'_content'} || return } ) {
Condition0%0/2
$_[0]{'_content'} || (return)
l!l
00
MC/DC0%0/1
$_[0]{'_content'} || (return)
$_[0]{'_content'}
Truth table0%0/2
A
A= $_[0]{'_content'}
Aresult
11
00
2103 0 ▶ if ( ref $it ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $it) { } 0 0 0
elsif ($pre) { } 0 0 0
2104 0 $sub->($it); # recurse!
2105 }
2106 elsif ($pre) {
2107  
2108 #$it =~ s/(?:(?:\cm\cj*)|(?:\cj))/\n/g;
2109  
2110 $it = join "\n", map {
2111 0 ;
2112 0 $line = $_;
2113 0 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s/^([^\t]*)(\t+)/$1 . " " x ((length($2) << 3) - (length $1 & 7));/e) 0 0 0
2114 $line
2115 0 =~ s/^([^\t]*)(\t+)/$1.(" " x ((length($2)<<3)-(length($1)&7)))/e
2116  
2117 # Sort of adapted from Text::Tabs -- yes, it's hardwired-in that
2118 # tabs are at every EIGHTH column.
2119 )
2120 {
2121 }
2122 0 $line;
2123 }
2124 split /(?:(?:\cm\cj*)|(?:\cj))/, $it, -1;
2125 }
2126 }
2127 0 ▶ --$pre if $_[0]->{'_tag'} eq 'pre';
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"_tag"} eq "pre" 0 0 0
2128 0 return;
2129 0 };
2130 0 $sub->( $_[0] );
2131  
2132 0 undef $sub;
2133 0 return;
2134  
2135 }
2136  
2137 0 ▶sub same_as {
Subroutine same_as: not called CC=23 SCAR=63.1
Pod undocumented
2138 0 ▶ die 'same_as() takes only one argument: $h->same_as($i)' unless @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
2139 0 my ( $h, $i ) = @_[ 0, 1 ];
2140 0 ▶ die "same_as() can be called only as an object method" unless ref $h;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $h 0 0 0
2141  
2142 0 ▶ return 0 unless defined $i and ref $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i and ref $i 0 0 0
Condition0%0/3
defined $i and ref $i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $i and ref $i
defined $i ref $i
Truth table0%0/3
A and B
A= defined $iB= ref $i
ABresult
0X0
100
111
2143  
2144 # An element can't be same_as anything but another element!
2145 # They needn't be of the same class, tho.
2146  
2147 0 ▶ return 1 if $h eq $i;
Branch: 1 branch
BranchTrueFalseTotal
if $h eq $i 0 0 0
2148  
2149 # special (if rare) case: anything is the same as... itself!
2150  
2151 # assumes that no content lists in/under $h or $i contain subsequent
2152 # text segments, like: ['foo', ' bar']
2153  
2154 # compare attributes now.
2155 #print "Comparing tags of $h and $i...\n";
2156  
2157 0 ▶ return 0 unless $h->{'_tag'} eq $i->{'_tag'};
Branch: 1 branch
BranchTrueFalseTotal
unless $h->{"_tag"} eq $i->{"_tag"} 0 0 0
2158  
2159 # only significant attribute whose name starts with "_"
2160  
2161 #print "Comparing attributes of $h and $i...\n";
2162 # Compare attributes, but only the real ones.
2163 {
2164  
2165 # Bear in mind that the average element has very few attributes,
2166 # and that element names are rather short.
2167 # (Values are a different story.)
2168  
2169 # XXX I would think that /^[^_]/ would be faster, at least easier to read.
2170 0 my @keys_h
2171 0 ▶ = sort grep { length $_ and substr( $_, 0, 1 ) ne '_' } keys %$h;
Condition0%0/3
length $_ && substr($_, 0, 1) ne '_'
!ll&&!rl&&r
000
MC/DC0%0/2
length $_ && substr($_, 0, 1) ne '_'
length $_ substr($_, 0, 1) ne '_'
Truth table0%0/3
A && B
A= length $_B= substr($_, 0, 1) ne '_'
ABresult
0X0
100
111
2172 my @keys_i
2173 0 ▶ = sort grep { length $_ and substr( $_, 0, 1 ) ne '_' } keys %$i;
Condition0%0/3
length $_ && substr($_, 0, 1) ne '_'
!ll&&!rl&&r
000
MC/DC0%0/2
length $_ && substr($_, 0, 1) ne '_'
length $_ substr($_, 0, 1) ne '_'
Truth table0%0/3
A && B
A= length $_B= substr($_, 0, 1) ne '_'
ABresult
0X0
100
111
2174  
2175 0 ▶ return 0 unless @keys_h == @keys_i;
Branch: 1 branch
BranchTrueFalseTotal
unless @keys_h == @keys_i 0 0 0
2176  
2177 # different number of real attributes? they're different.
2178 0 ▶ for ( my $x = 0; $x < @keys_h; ++$x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < @keys_h) 0 0 0
2179 return 0
2180 unless $keys_h[$x] eq $keys_i[$x] and # same key name
2181 0 ▶ $h->{ $keys_h[$x] } eq $i->{ $keys_h[$x] }; # same value
Branch: 1 branch
BranchTrueFalseTotal
unless $keys_h[$x] eq $keys_i[$x] and $$h{$keys_h[$x]} eq $$i{$keys_h[$x]} 0 0 0
Condition0%0/3
$keys_h[$x] eq $keys_i[$x] and $$h{$keys_h[$x]} eq $$i{$keys_h[$x]}
!ll&&!rl&&r
000
MC/DC0%0/2
$keys_h[$x] eq $keys_i[$x] and $$h{$keys_h[$x]} eq $$i{$keys_h[$x]}
$keys_h[$x] eq $keys_i[$x] $$h{$keys_h[$x]} eq $$i{$keys_h[$x]}
Truth table0%0/3
A and B
A= $keys_h[$x] eq $keys_i[$x]B= $$h{$keys_h[$x]} eq $$i{$keys_h[$x]}
ABresult
0X0
100
111
2182 # Should this test for definedness on values?
2183 # People shouldn't be putting undef in attribute values, I think.
2184 }
2185 }
2186  
2187 #print "Comparing children of $h and $i...\n";
2188 0 ▶ my $hcl = $h->{'_content'} || [];
Condition0%0/2
$h->{'_content'} || []
l!l
00
MC/DC0%0/1
$h->{'_content'} || []
$h->{'_content'}
Truth table0%0/2
A
A= $h->{'_content'}
Aresult
11
00
2189 0 ▶ my $icl = $i->{'_content'} || [];
Condition0%0/2
$i->{'_content'} || []
l!l
00
MC/DC0%0/1
$i->{'_content'} || []
$i->{'_content'}
Truth table0%0/2
A
A= $i->{'_content'}
Aresult
11
00
2190  
2191 0 ▶ return 0 unless @$hcl == @$icl;
Branch: 1 branch
BranchTrueFalseTotal
unless @$hcl == @$icl 0 0 0
2192  
2193 # different numbers of children? they're different.
2194  
2195 0 ▶ if (@$hcl) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$hcl) 0 0 0
2196  
2197 # compare each of the children:
2198 0 ▶ for ( my $x = 0; $x < @$hcl; ++$x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < @$hcl) 0 0 0
2199 0 ▶ if ( ref $hcl->[$x] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hcl->[$x]) { } 0 0 0
2200 0 ▶ return 0 unless ref( $icl->[$x] );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $icl->[$x] 0 0 0
2201  
2202 # an element can't be the same as a text segment
2203 # Both elements:
2204 0 ▶ return 0 unless $hcl->[$x]->same_as( $icl->[$x] ); # RECURSE!
Branch: 1 branch
BranchTrueFalseTotal
unless $hcl->[$x]->same_as($icl->[$x]) 0 0 0
2205 }
2206 else {
2207 0 ▶ return 0 if ref( $icl->[$x] );
Branch: 1 branch
BranchTrueFalseTotal
if ref $icl->[$x] 0 0 0
2208  
2209 # a text segment can't be the same as an element
2210 # Both text segments:
2211 0 ▶ return 0 unless $hcl->[$x] eq $icl->[$x];
Branch: 1 branch
BranchTrueFalseTotal
unless $hcl->[$x] eq $icl->[$x] 0 0 0
2212 }
2213 }
2214 }
2215  
2216 0 return 1; # passed all the tests!
2217 }
2218  
2219 0 ▶sub new_from_lol {
Subroutine new_from_lol: not called CC=6 SCAR=37.4
Pod undocumented
2220 0 my $class = shift;
2221 0 ▶ $class = ref($class) || $class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
2222  
2223 # calling as an object method is just the same as ref($h)->new_from_lol(...)
2224 0 my $lol = $_[1];
2225  
2226 0 my @ancestor_lols;
2227  
2228 # So we can make sure there's no cyclicities in this lol.
2229 # That would be perverse, but one never knows.
2230 0 my ( $sub, $k, $v, $node ); # last three are scratch values
2231 0 ▶ $sub = sub {
Subroutine __ANON__: not called CC=24 SCAR=64.0
2232  
2233 #print "Building for $_[0]\n";
2234 0 my $lol = $_[0];
2235 0 ▶ return unless @$lol;
Branch: 1 branch
BranchTrueFalseTotal
unless @$lol 0 0 0
2236 0 my ( @attributes, @children );
2237 0 ▶ Carp::croak "Cyclicity detected in source LOL tree, around $lol?!?"
Branch: 1 branch
BranchTrueFalseTotal
if grep(($_ eq $lol), @ancestor_lols) 0 0 0
2238 if grep( $_ eq $lol, @ancestor_lols );
2239 0 push @ancestor_lols, $lol;
2240  
2241 0 my $tag_name = 'null';
2242  
2243 # Recursion in in here:
2244 0 ▶ for ( my $i = 0; $i < @$lol; ++$i ) { # Iterate over children
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$lol) 0 0 0
2245 0 ▶ if ( ref( $lol->[$i] ) eq 'ARRAY' )
Branch: 4 branches
BranchTrueFalseTotal
if (ref $lol->[$i] eq 'ARRAY') { } 0 0 0
elsif (not ref $lol->[$i]) { } 0 0 0
elsif (ref $lol->[$i] eq 'HASH') { } 0 0 0
elsif (UNIVERSAL::isa($lol->[$i], __PACKAGE__)) { } 0 0 0
2246 { # subtree: most common thing in loltree
2247 0 push @children, $sub->( $lol->[$i] );
2248 }
2249 elsif ( !ref( $lol->[$i] ) ) {
2250 0 ▶ if ( $i == 0 ) { # name
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0) { } 0 0 0
2251 0 $tag_name = $lol->[$i];
2252 0 ▶ Carp::croak "\"$tag_name\" isn't a good tag name!"
Branch: 1 branch
BranchTrueFalseTotal
if $tag_name =~ m[[<>/\x00-\x20]] 0 0 0
2253 if $tag_name =~ m/[<>\/\x00-\x20]/
2254 ; # minimal sanity, certainly!
2255 }
2256 else { # text segment child
2257 0 push @children, $lol->[$i];
2258 }
2259 }
2260 elsif ( ref( $lol->[$i] ) eq 'HASH' ) { # attribute hashref
2261 0 keys %{ $lol->[$i] }; # reset the each-counter, just in case
2262 0 ▶ while ( ( $k, $v ) = each %{ $lol->[$i] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$lol[$i];}) 0 0 0
2263 0 ▶ push @attributes, $class->_fold_case($k), $v
Branch: 1 branch
BranchTrueFalseTotal
if defined $v and $k ne "_name" and $k ne "_content" and $k ne "_parent" 0 0 0
Condition0%0/9
defined $v and $k ne "_name" and $k ne "_content" and $k ne "_parent"
!ll&&!rl&&r
000
defined $v and $k ne "_name" and $k ne "_content"
!ll&&!rl&&r
000
defined $v and $k ne "_name"
!ll&&!rl&&r
000
MC/DC0%0/4
defined $v and $k ne "_name" and $k ne "_content" and $k ne "_parent"
defined $v $k ne "_name" $k ne "_content" $k ne "_parent"
Truth table0%0/5
A and B and C and D
A= defined $vB= $k ne "_name"C= $k ne "_content"D= $k ne "_parent"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2264 if defined $v
2265 and $k ne '_name'
2266 and $k ne '_content'
2267 and $k ne '_parent';
2268  
2269 # enforce /some/ sanity!
2270 }
2271 }
2272 elsif ( UNIVERSAL::isa( $lol->[$i], __PACKAGE__ ) ) {
2273 0 ▶ if ( $lol->[$i]->{'_parent'} ) { # if claimed
Branch: 1 branch
BranchTrueFalseTotal
if ($lol->[$i]{'_parent'}) { } 0 0 0
2274 #print "About to clone ", $lol->[$i], "\n";
2275 0 push @children, $lol->[$i]->clone();
2276 }
2277 else {
2278 0 push @children, $lol->[$i]; # if unclaimed...
2279 #print "Claiming ", $lol->[$i], "\n";
2280 0 $lol->[$i]->{'_parent'} = 1; # claim it NOW
2281 # This WILL be replaced by the correct value once we actually
2282 # construct the parent, just after the end of this loop...
2283 }
2284 }
2285 else {
2286 0 Carp::croak "new_from_lol doesn't handle references of type "
2287 . ref( $lol->[$i] );
2288 }
2289 }
2290  
2291 0 pop @ancestor_lols;
2292 0 $node = $class->new($tag_name);
2293  
2294 #print "Children: @children\n";
2295  
2296 0 ▶ if ( $class eq __PACKAGE__ ) { # Special-case it, for speed:
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) { } 0 0 0
2297 0 ▶ %$node = ( %$node, @attributes ) if @attributes;
Branch: 1 branch
BranchTrueFalseTotal
if @attributes 0 0 0
2298  
2299 #print join(' ', $node, ' ' , map("<$_>", %$node), "\n");
2300 0 ▶ if (@children) {
Branch: 1 branch
BranchTrueFalseTotal
if (@children) 0 0 0
2301 0 $node->{'_content'} = \@children;
2302 0 foreach my $c (@children) {
2303 0 ▶ $c->{'_parent'} = $node
Branch: 1 branch
BranchTrueFalseTotal
if ref $c 0 0 0
2304 if ref $c;
2305 }
2306 }
2307 }
2308 else { # Do it the clean way...
2309 #print "Done neatly\n";
2310 0 ▶ while (@attributes) { $node->attr( splice @attributes, 0, 2 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (@attributes) 0 0 0
2311 0 ▶ $node->push_content( map { $_->{'_parent'} = $node if ref $_; $_ }
Branch: 2 branches
BranchTrueFalseTotal
if @children 0 0 0
if ref $_ 0 0 0
2312 @children )
2313 if @children;
2314 }
2315  
2316 0 return $node;
2317 0 };
2318  
2319 # End of sub definition.
2320  
2321 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
2322 0 ▶ my (@nodes) = map { ; ( ref($_) eq 'ARRAY' ) ? $sub->($_) : $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 0 0 0
2323  
2324 # Let text bits pass thru, I guess. This makes this act more like
2325 # unshift_content et al. Undocumented.
2326 0 undef $sub;
2327  
2328 # so it won't be in its own frame, so its refcount can hit 0
2329 0 return @nodes;
2330 }
2331 else {
2332 0 ▶ Carp::croak "new_from_lol in scalar context needs exactly one lol"
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
2333 unless @_ == 1;
2334 0 ▶ return $_[0] unless ref( $_[0] ) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 0 0
2335  
2336 # used to be a fatal error. still undocumented tho.
2337 0 $node = $sub->( $_[0] );
2338 0 undef $sub;
2339  
2340 # so it won't be in its own frame, so its refcount can hit 0
2341 0 return $node;
2342 }
2343 }
2344  
2345 0 ▶sub objectify_text {
Subroutine objectify_text: not called CC=4 SCAR=30.0
Pod undocumented
2346 0 my (@stack) = ( $_[0] );
2347  
2348 0 my ($this);
2349 0 ▶ while (@stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stack) 0 0 0
2350 0 foreach my $c ( @{ ( $this = shift @stack )->{'_content'} } ) {
2351 0 ▶ if ( ref($c) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $c) { } 0 0 0
2352 0 unshift @stack, $c; # visit it later.
2353 }
2354 else {
2355 0 $c = $this->element_class->new(
2356 '~text',
2357 'text' => $c,
2358 '_parent' => $this
2359 );
2360 }
2361 }
2362 }
2363 0 return;
2364 }
2365  
2366 63 ▶sub deobjectify_text {
Subroutine deobjectify_text: called CC=10 SCAR=30.7
Pod undocumented
2367 63 my (@stack) = ( $_[0] );
2368 63 my ($old_node);
2369  
2370 63 ▶ if ( $_[0]{'_tag'} eq '~text' ) { # special case
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"_tag"} eq "~text") 0 63 63
2371 # Puts the $old_node variable to a different purpose
2372 0 ▶ if ( $_[0]{'_parent'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{'_parent'}) { } 0 0 0
2373 0 $_[0]->replace_with( $old_node = delete $_[0]{'text'} )->delete;
2374 }
2375 else { # well, that's that, then!
2376 0 $old_node = delete $_[0]{'text'};
2377 }
2378  
2379 0 ▶ if ( ref( $_[0] ) eq __PACKAGE__ ) { # common case
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq __PACKAGE__) { } 0 0 0
2380 0 %{ $_[0] } = (); # poof!
2381 }
2382 else {
2383  
2384 # play nice:
2385 0 delete $_[0]{'_parent'};
2386 0 $_[0]->delete;
2387 }
2388 0 ▶ return '' unless defined $old_node; # sanity!
Branch: 1 branch
BranchTrueFalseTotal
unless defined $old_node 0 0 0
2389 0 return $old_node;
2390 }
2391  
2392 63 ▶ while (@stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stack) 175 63 238
2393 175 foreach my $c ( @{ ( shift @stack )->{'_content'} } ) {
2394 196 ▶ if ( ref($c) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $c) 196 0 196
2395 196 ▶ if ( $c->{'_tag'} eq '~text' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{'_tag'} eq '~text') { } 84 112 196
2396 84 $c = ( $old_node = $c )->{'text'};
2397 84 ▶ if ( ref($old_node) eq __PACKAGE__ ) { # common case
Branch: 1 branch
BranchTrueFalseTotal
if (ref $old_node eq __PACKAGE__) { } 0 84 84
2398 0 %$old_node = (); # poof!
2399 }
2400 else {
2401  
2402 # play nice:
2403 84 delete $old_node->{'_parent'};
2404 84 $old_node->delete;
2405 }
2406 }
2407 else {
2408 112 unshift @stack, $c; # visit it later.
2409 }
2410 }
2411 }
2412 }
2413  
2414 63 return;
2415 }
2416  
2417 {
2418  
2419 # The next three subs are basically copied from Number::Latin,
2420 # based on a one-liner by Abigail. Yes, I could simply require that
2421 # module, and a Roman numeral module too, but really, HTML-Tree already
2422 # has enough dependecies as it is; and anyhow, I don't need the functions
2423 # that do latin2int or roman2int.
2424 28 ▶ no integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
2425  
2426 0 ▶ sub _int2latin {
Subroutine _int2latin: not called CC=5 SCAR=34.0
2427 0 ▶ return unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
2428 0 ▶ return '0' if $_[0] < 1 and $_[0] > -1;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] < 1 and $_[0] > -1 0 0 0
Condition0%0/3
$_[0] < 1 and $_[0] > -1
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] < 1 and $_[0] > -1
$_[0] < 1 $_[0] > -1
Truth table0%0/3
A and B
A= $_[0] < 1B= $_[0] > -1
ABresult
0X0
100
111
2429 0 ▶ return '-' . _i2l( abs int $_[0] )
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] <= -1 0 0 0
2430 if $_[0] <= -1; # tolerate negatives
2431 0 return _i2l( int $_[0] );
2432 }
2433  
2434 0 ▶ sub _int2LATIN {
Subroutine _int2LATIN: not called CC=5 SCAR=34.0
2435  
2436 # just the above plus uc
2437 0 ▶ return unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
2438 0 ▶ return '0' if $_[0] < 1 and $_[0] > -1;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] < 1 and $_[0] > -1 0 0 0
Condition0%0/3
$_[0] < 1 and $_[0] > -1
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] < 1 and $_[0] > -1
$_[0] < 1 $_[0] > -1
Truth table0%0/3
A and B
A= $_[0] < 1B= $_[0] > -1
ABresult
0X0
100
111
2439 0 ▶ return '-' . uc( _i2l( abs int $_[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] <= -1 0 0 0
2440 if $_[0] <= -1; # tolerate negs
2441 0 return uc( _i2l( int $_[0] ) );
2442 }
2443  
2444 28 my @alpha = ( 'a' .. 'z' );
2445  
2446 0 ▶ sub _i2l { # the real work
Subroutine _i2l: not called CC=2 SCAR=17.9
2447 0 ▶ my $int = $_[0] || return "";
Condition0%0/2
$_[0] || (return '')
l!l
00
MC/DC0%0/1
$_[0] || (return '')
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
2448 0 _i2l( int( ( $int - 1 ) / 26 ) )
2449 . $alpha[ $int % 26 - 1 ]; # yes, recursive
2450 # Yes, 26 => is (26 % 26 - 1), which is -1 => Z!
2451 }
2452 }
2453  
2454 {
2455  
2456 # And now, some much less impressive Roman numerals code:
2457  
2458 28 my (@i) = ( '', qw(I II III IV V VI VII VIII IX) );
2459 28 my (@x) = ( '', qw(X XX XXX XL L LX LXX LXXX XC) );
2460 28 my (@c) = ( '', qw(C CC CCC CD D DC DCC DCCC CM) );
2461 28 my (@m) = ( '', qw(M MM MMM) );
2462  
2463 0 ▶ sub _int2ROMAN {
Subroutine _int2ROMAN: not called CC=9 SCAR=45.0
2464 0 my ( $i, $pref );
2465 0 ▶ return '0'
Branch: 1 branch
BranchTrueFalseTotal
if 0 == ($i = int($_[0] || 0)) 0 0 0
Condition0%0/2
$_[0] || 0
l!l
00
MC/DC0%0/1
$_[0] || 0
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
2466 if 0 == ( $i = int( $_[0] || 0 ) ); # zero is a special case
2467 0 ▶ return $i + 0 if $i <= -4000 or $i >= 4000;
Branch: 1 branch
BranchTrueFalseTotal
if $i <= -4000 or $i >= 4000 0 0 0
Condition0%0/3
$i <= -4000 or $i >= 4000
l!l&&r!l&&!r
000
MC/DC0%0/2
$i <= -4000 or $i >= 4000
$i <= -4000 $i >= 4000
Truth table0%0/3
A or B
A= $i <= -4000B= $i >= 4000
ABresult
1X1
011
000
2468  
2469 # Because over 3999 would require non-ASCII chars, like D-with-)-inside
2470 0 ▶ if ( $i < 0 ) { # grumble grumble tolerate negatives grumble
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 0) { } 0 0 0
2471 0 $pref = '-';
2472 0 $i = abs($i);
2473 }
2474 else {
2475 0 $pref = ''; # normal case
2476 }
2477  
2478 0 my ( $x, $c, $m ) = ( 0, 0, 0 );
2479 0 ▶ if ( $i >= 10 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 10) 0 0 0
2480 0 $x = $i / 10;
2481 0 $i %= 10;
2482 0 ▶ if ( $x >= 10 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x >= 10) 0 0 0
2483 0 $c = $x / 10;
2484 0 $x %= 10;
2485 0 ▶ if ( $c >= 10 ) { $m = $c / 10; $c %= 10; }
Branch: 1 branch
BranchTrueFalseTotal
if ($c >= 10) 0 0 0
2486 }
2487 }
2488  
2489 #print "m$m c$c x$x i$i\n";
2490  
2491 0 return join( '', $pref, $m[$m], $c[$c], $x[$x], $i[$i] );
2492 }
2493  
2494 0 ▶ sub _int2roman { lc( _int2ROMAN( $_[0] ) ) }
Subroutine _int2roman: not called CC=1 SCAR=6.9
2495 }
2496  
2497 0 ▶sub _int2int { $_[0] } # dummy
Subroutine _int2int: not called CC=1 SCAR=1.2
2498  
2499 28 %list_type_to_sub = (
2500 'I' => \&_int2ROMAN,
2501 'i' => \&_int2roman,
2502 'A' => \&_int2LATIN,
2503 'a' => \&_int2latin,
2504 '1' => \&_int2int,
2505 );
2506  
2507 0 ▶sub number_lists {
Subroutine number_lists: not called CC=23 SCAR=63.1
Pod undocumented
2508 0 my (@stack) = ( $_[0] );
2509 0 my ( $this, $tag, $counter, $numberer ); # scratch
2510 0 ▶ while (@stack) { # yup, pre-order-traverser idiom
Branch: 1 branch
BranchTrueFalseTotal
if (@stack) 0 0 0
2511 0 ▶ if ( ( $tag = ( $this = shift @stack )->{'_tag'} ) eq 'ol' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (($tag = +($this = shift @stack)->{'_tag'}) eq 'ol') { } 0 0 0
elsif ($tag eq 'ul' or $tag eq 'dir' or $tag eq 'menu') { } 0 0 0
2512  
2513 # Prep some things:
2514 $counter
2515 0 ▶ = ( ( $this->{'start'} || '' ) =~ m<^\s*(\d{1,7})\s*$>s )
Branch: 1 branch
BranchTrueFalseTotal
($this->{'start'} || '') =~ /^\s*(\d{1,7})\s*$/s ? : 0 0 0
Condition0%0/2
$this->{'start'} || ''
l!l
00
MC/DC0%0/1
$this->{'start'} || ''
$this->{'start'}
Truth table0%0/2
A
A= $this->{'start'}
Aresult
11
00
2516 ? $1
2517 : 1;
2518 $numberer = $list_type_to_sub{ $this->{'type'} || '' }
2519 0 ▶ || $list_type_to_sub{'1'};
Condition0%0/5
$HTML::DOM::_Element::list_type_to_sub{$this->{'type'} or ''} || $HTML::DOM::_Element::list_type_to_sub{'1'}
l!l&&r!l&&!r
000
$this->{'type'} || ''
l!l
00
MC/DC0%0/2
$HTML::DOM::_Element::list_type_to_sub{$this->{'type'} or ''} || $HTML::DOM::_Element::list_type_to_sub{'1'}
$HTML::DOM::_Element::list_type_to_sub{$this->{'type'} or ''} $HTML::DOM::_Element::list_type_to_sub{'1'}
MC/DC0%0/1
$this->{'type'} || ''
$this->{'type'}
Truth table0%0/3
A || B
A= $HTML::DOM::_Element::list_type_to_sub{$this->{'type'} or ''}B= $HTML::DOM::_Element::list_type_to_sub{'1'}
ABresult
1X1
011
000
Truth table0%0/2
A
A= $this->{'type'}
Aresult
11
00
2520  
2521 # Immeditately iterate over all children
2522 0 ▶ foreach my $c ( @{ $this->{'_content'} || next } ) {
Condition0%0/2
$this->{'_content'} || (next)
l!l
00
MC/DC0%0/1
$this->{'_content'} || (next)
$this->{'_content'}
Truth table0%0/2
A
A= $this->{'_content'}
Aresult
11
00
2523 0 ▶ next unless ref $c;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $c 0 0 0
2524 0 unshift @stack, $c;
2525 0 ▶ if ( $c->{'_tag'} eq 'li' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"_tag"} eq "li") 0 0 0
2526 $counter = $1
2527 if (
2528 0 ▶ ( $c->{'value'} || '' ) =~ m<^\s*(\d{1,7})\s*$>s );
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"value"} || "") =~ /^\s*(\d{1,7})\s*$/s 0 0 0
Condition0%0/2
$c->{'value'} || ''
l!l
00
MC/DC0%0/1
$c->{'value'} || ''
$c->{'value'}
Truth table0%0/2
A
A= $c->{'value'}
Aresult
11
00
2529 0 $c->{'_bullet'} = $numberer->($counter) . '.';
2530 0 ++$counter;
2531 }
2532 }
2533  
2534 }
2535 ▶ elsif ( $tag eq 'ul' or $tag eq 'dir' or $tag eq 'menu' ) {
Condition0%0/6
$tag eq "ul" or $tag eq "dir" or $tag eq "menu"
l!l&&r!l&&!r
000
$tag eq "ul" or $tag eq "dir"
l!l&&r!l&&!r
000
MC/DC0%0/3
$tag eq "ul" or $tag eq "dir" or $tag eq "menu"
$tag eq "ul" $tag eq "dir" $tag eq "menu"
Truth table0%0/4
A or B or C
A= $tag eq "ul"B= $tag eq "dir"C= $tag eq "menu"
ABCresult
1XX1
01X1
0011
0000
2536  
2537 # Immeditately iterate over all children
2538 0 ▶ foreach my $c ( @{ $this->{'_content'} || next } ) {
Condition0%0/2
$this->{'_content'} || (next)
l!l
00
MC/DC0%0/1
$this->{'_content'} || (next)
$this->{'_content'}
Truth table0%0/2
A
A= $this->{'_content'}
Aresult
11
00
2539 0 ▶ next unless ref $c;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $c 0 0 0
2540 0 unshift @stack, $c;
2541 0 ▶ $c->{'_bullet'} = '*' if $c->{'_tag'} eq 'li';
Branch: 1 branch
BranchTrueFalseTotal
if $c->{"_tag"} eq "li" 0 0 0
2542 }
2543  
2544 }
2545 else {
2546 0 ▶ foreach my $c ( @{ $this->{'_content'} || next } ) {
Condition0%0/2
$this->{'_content'} || (next)
l!l
00
MC/DC0%0/1
$this->{'_content'} || (next)
$this->{'_content'}
Truth table0%0/2
A
A= $this->{'_content'}
Aresult
11
00
2547 0 ▶ unshift @stack, $c if ref $c;
Branch: 1 branch
BranchTrueFalseTotal
if ref $c 0 0 0
2548 }
2549 }
2550 }
2551 0 return;
2552 }
2553  
2554 0 ▶sub has_insane_linkage {
Subroutine has_insane_linkage: not called CC=13 SCAR=52.0
Pod undocumented
2555 0 my @pile = ( $_[0] );
2556 0 my ( $c, $i, $p, $this ); # scratch
2557  
2558 # Another iterative traverser; this time much simpler because
2559 # only in pre-order:
2560 0 my %parent_of = ( $_[0], 'TOP-OF-SCAN' );
2561 0 ▶ while (@pile) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pile) 0 0 0
2562 0 $this = shift @pile;
2563 0 ▶ $c = $this->{'_content'} || next;
Condition0%0/2
$this->{'_content'} || (next)
l!l
00
MC/DC0%0/1
$this->{'_content'} || (next)
$this->{'_content'}
Truth table0%0/2
A
A= $this->{'_content'}
Aresult
11
00
2564 0 ▶ return ( $this, "_content attribute is true but nonref." )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $c eq "ARRAY" 0 0 0
2565 unless ref($c) eq 'ARRAY';
2566 0 ▶ next unless @$c;
Branch: 1 branch
BranchTrueFalseTotal
unless @$c 0 0 0
2567 0 ▶ for ( $i = 0; $i < @$c; ++$i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$c) 0 0 0
2568 0 ▶ return ( $this, "Child $i is undef" )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c->[$i] 0 0 0
2569 unless defined $c->[$i];
2570 0 ▶ if ( ref( $c->[$i] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $c->[$i]) 0 0 0
2571 0 ▶ return ( $c->[$i], "appears in its own content list" )
Branch: 1 branch
BranchTrueFalseTotal
if $c->[$i] eq $this 0 0 0
2572 if $c->[$i] eq $this;
2573 return ( $c->[$i],
2574 "appears twice in the tree: once under $this, once under $parent_of{$c->[$i]}"
2575 0 ▶ ) if exists $parent_of{ $c->[$i] };
Branch: 1 branch
BranchTrueFalseTotal
if exists $parent_of{$c->[$i]} 0 0 0
2576 0 $parent_of{ $c->[$i] } = '' . $this;
2577  
2578 # might as well just use the stringification of it.
2579  
2580 return ( $c->[$i],
2581 "_parent attribute is wrong (not defined)" )
2582 0 ▶ unless defined( $p = $c->[$i]{'_parent'} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined($p = $c->[$i]{"_parent"}) 0 0 0
2583 0 ▶ return ( $c->[$i], "_parent attribute is wrong (nonref)" )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $p 0 0 0
2584 unless ref($p);
2585 0 ▶ return ( $c->[$i],
Branch: 1 branch
BranchTrueFalseTotal
unless $p eq $this 0 0 0
2586 "_parent attribute is wrong (is $p; should be $this)" )
2587 unless $p eq $this;
2588 }
2589 }
2590 0 unshift @pile, grep ref($_), @$c;
2591  
2592 # queue up more things on the pile stack
2593 }
2594 0 return; #okay
2595 }
2596  
2597 0 ▶sub _asserts_fail { # to be run on trusted documents only
Subroutine _asserts_fail: not called CC=11 SCAR=48.8
2598 0 my (@pile) = ( $_[0] );
2599 0 my ( @errors, $this, $id, $assert, $parent, $rv );
2600 0 ▶ while (@pile) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pile) 0 0 0
2601 0 $this = shift @pile;
2602 0 ▶ if ( defined( $assert = $this->{'assert'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($assert = $this->{"assert"})) 0 0 0
2603 0 ▶ $id = ( $this->{'id'} ||= $this->address )
Condition0%0/3
$this->{"id"} ||= $this->address
l!l&&r!l&&!r
000
MC/DC0%0/2
$this->{"id"} ||= $this->address
$this->{"id"} $this->address
Truth table0%0/3
A ||= B
A= $this->{"id"}B= $this->address
ABresult
1X1
011
000
2604 ; # don't use '0' as an ID, okay?
2605 0 ▶ unless ( ref($assert) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $assert) 0 0 0
2606  
2607 package main;
2608 ## no critic
2609 0 ▶ $assert = $this->{'assert'} = (
Branch: 1 branch
BranchTrueFalseTotal
$assert =~ /\bsub\b/ ? : 0 0 0
2610 $assert =~ m/\bsub\b/
2611 ? eval($assert)
2612 : eval("sub { $assert\n}")
2613 );
2614 ## use critic
2615 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2616 0 push @errors,
2617 [ $this, "assertion at $id broke in eval: $@" ];
2618 0 ▶ $assert = $this->{'assert'} = sub { };
Subroutine __ANON__: not called CC=1 SCAR=6.9
2619 }
2620 }
2621 0 $parent = $this->{'_parent'};
2622 0 $rv = undef;
2623 0 eval {
2624 $rv = $assert->(
2625 $this, $this->{'_tag'}, $this->{'_id'}, # 0,1,2
2626 $parent
2627 0 ▶ ? ( $parent, $parent->{'_tag'}, $parent->{'id'} )
Branch: 1 branch
BranchTrueFalseTotal
$parent ? : 0 0 0
2628 : () # 3,4,5
2629 );
2630 };
2631 0 ▶ if ($@) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not $rv) { } 0 0 0
2632 0 push @errors, [ $this, "assertion at $id died: $@" ];
2633 }
2634 elsif ( !$rv ) {
2635 0 push @errors, [ $this, "assertion at $id failed" ];
2636 }
2637  
2638 # else OK
2639 }
2640 0 ▶ push @pile, grep ref($_), @{ $this->{'_content'} || next };
Condition0%0/2
$this->{'_content'} || (next)
l!l
00
MC/DC0%0/1
$this->{'_content'} || (next)
$this->{'_content'}
Truth table0%0/2
A
A= $this->{'_content'}
Aresult
11
00
2641 }
2642 0 return @errors;
2643 }
2644  
2645 ## _valid_name
2646 # validate XML style attribute names
2647 # http://www.w3.org/TR/2006/REC-xml11-20060816/#NT-Name
2648  
2649 0 ▶sub _valid_name {
Subroutine _valid_name: not called CC=3 SCAR=24.8
2650 0 my $self = shift;
2651 0 ▶ my $attr = shift
Branch: 1 branch
BranchTrueFalseTotal
my $attr = shift() or Carp::croak("sub valid_name requires an attribute name") 0 0 0
2652 or Carp::croak("sub valid_name requires an attribute name");
2653  
2654 0 ▶ return (0) unless ( $attr =~ /^$START_CHAR$NAME_CHAR+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $attr =~ /^$START_CHAR$NAME_CHAR+$/ 0 0 0
2655  
2656 0 return (1);
2657 }
2658  
2659 0 ▶sub element_class {
Subroutine element_class: not called CC=2 SCAR=17.9
Pod undocumented
2660 0 ▶ $_[0]->{_element_class} || __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"_element_class"} or __PACKAGE__ 0 0 0
2661 }
2662  
2663 28 1;
2664  
2665 28 1;
« DOM/_TreeBuilder.pm ↑ Summary DOM/EventTarget.pm »