blib/lib/XML/LibXML/PrettyPrint.pm

filter: Statementstmt 90.2% 175 / 194 Branchbran 75.0% 96 / 128 Conditioncond 61.6% 37 / 60 MC/DCmcdc 33.3% 11 / 33 Subroutinesub 89.2% 25 / 28 Podpod 100% 10 / 10 totaltotal 78.1% 354 / 453 CC 86 SCAR 28.8
CC
86
Cov
81%
_run_checks
44.3
strip_whitespace
23.9
indent
22.0
CRAP 17.8
↑ Summary
1 5 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶no warnings qw( once void uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use IO::Handle 0 qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 package XML::LibXML::PrettyPrint;
11  
12 5 ▶use constant { FALSE => 0, TRUE => 1 };
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use constant { EL_BLOCK => 1, EL_COMPACT => 2, EL_INLINE => 3};
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 BEGIN
16 5 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 $XML::LibXML::PrettyPrint::AUTHORITY = 'cpan:TOBYINK';
18 5 $XML::LibXML::PrettyPrint::VERSION = '0.006';
19 }
20  
21 5 ▶use Carp 0 qw(croak carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use Scalar::Util 0 qw(blessed refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶use XML::LibXML 1.62 qw(:ns);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 5 ▶use Exporter::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 5 our @ISA = 'Exporter::Tiny';
28 5 our @EXPORT = qw();
29 5 our @EXPORT_OK = qw(print_xml EL_BLOCK EL_COMPACT EL_INLINE);
30 our %EXPORT_TAGS = (
31 constants => [qw(EL_BLOCK EL_COMPACT EL_INLINE)],
32 1 ▶ io => sub {
Subroutine __ANON__: called CC=1 SCAR=0.1
33 3 ▶ *IO::Handle::print_xml = sub ($$;$) {
Subroutine __ANON__: called CC=4 SCAR=14.2
34 3 my ($handle, $xml, $indent) = @_;
35 3 ▶ unless (blessed($xml)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($xml)) 3 0 3
36 3 local $@ = undef;
37 3 ▶ eval { $xml = XML::LibXML->new->parse_string($xml); 1; }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $xml = "XML::LibXML"->new->parse_string($xml); 1 } } or croak("Could not parse XML: $@") 3 0 3
38 or croak("Could not parse XML: $@");
39 }
40 3 ▶ $indent = 0 unless defined $indent;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $indent 3 0 3
41 3 $handle->print(__PACKAGE__->pretty_print($xml, $indent)->toString);
42 1 };
43 1 return;
44 },
45 5 );
46  
47 5 our $Whitespace = qr/[\x20\t\r\n]/; # @@TODO need to check XML spec
48  
49 sub new
50 30 ▶{
Subroutine new: called CC=4 SCAR=13.9
Pod documented
51 30 my ($class, %options) = @_;
52 30 ▶ $options{element} = delete $options{elements} unless defined $options{element};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options{"element"} 16 14 30
53 30 ▶ if (defined $options{indent_string})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options{"indent_string"}) 2 28 30
54 {
55 carp("Non-whitespace indent_string supplied")
56 2 ▶ unless $options{indent_string} =~ /^$Whitespace*$/
Branch: 1 branch
BranchTrueFalseTotal
unless $options{"indent_string"} =~ /^$XML::LibXML::PrettyPrint::Whitespace*$/ 1 1 2
57 }
58 30 bless \%options, $class;
59 }
60  
61 {
62 5 my @compact = qw[area audio base basefont bgsound br button canvas
63 caption col command dd details dt embed figcaption
64 frame h1 h2 h3 h4 h5 h6 hr iframe img input isindex
65 keygen legend li link meta option p param summary td
66 th title video];
67 5 my @inline = qw[a abbr b bdi bdo big cite code dfn em font i kbd label
68 mark meter nobr progress q rp rt ruby s samp small span
69 strike strong sub sup time tt u var wbr];
70 5 my @block = qw[address applet article aside blockquote body center
71 colgroup datalist del dir div fieldset figure footer
72 form frameset head header hgroup html ins listing map
73 marquee menu nav noembed noframes noscript object ol
74 optgroup select section source table tbody tfoot thead
75 tr track ul dl];
76 5 my @pre = qw[plaintext output pre script style textarea xmp];
77
78 my $rdfa_lit_content = sub
79 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
80 0 my ($el) = @_;
81 0 ▶ return TRUE
Branch: 1 branch
BranchTrueFalseTotal
if $el->hasAttribute("property") and not $el->hasAttribute("content") 0 0 0
Condition0%0/3
$el->hasAttribute("property") and not $el->hasAttribute("content")
!ll&&!rl&&r
000
MC/DC0%0/2
$el->hasAttribute("property") and not $el->hasAttribute("content")
$el->hasAttribute("property") not $el->hasAttribute("content")
Truth table0%0/3
A and not(B)
A= $el->hasAttribute("property")B= not $el->hasAttribute("content")
ABresult
0X0
100
111
82 if ($el->hasAttribute('property') and not $el->hasAttribute('content'));
83 0 return undef;
84 5 };
85
86 sub new_for_html
87 0 ▶ {
Subroutine new_for_html: not called CC=1 SCAR=6.9
Pod documented
88 0 my ($class, %options) = @_;
89
90 0 return $class->new(
91 %options,
92 element => {
93 block => [@block],
94 compact => [@compact],
95 inline => [@inline],
96 preserves_whitespace => [@pre, $rdfa_lit_content],
97 },
98 );
99 }
100 }
101  
102 sub _ensure_self
103 5 ▶{
Subroutine _ensure_self: called CC=2 SCAR=6.9
104 898 ▶ blessed($_[0]) ? $_[0] : $_[0]->new;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) ? : 895 3 898
105 }
106  
107 sub strip_whitespace
108 129 ▶{
Subroutine strip_whitespace: called CC=23 SCAR=31.7
Pod documented
109 129 my ($self, $node) = @_;
110 129 $self = $self->_ensure_self;
111
112 129 ▶ croak("First parameter must be an XML::LibXML::Node")
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($node) and $node->isa("XML::LibXML::Node") 0 129 129
Condition33%1/3
builtin::blessed($node) and $node->isa("XML::LibXML::Node")
!ll&&!rl&&r
00129
MC/DC0%0/2
builtin::blessed($node) and $node->isa("XML::LibXML::Node")
builtin::blessed($node) $node->isa("XML::LibXML::Node")
Truth table33%1/3
A and B
A= builtin::blessed($node)B= $node->isa("XML::LibXML::Node")
ABresult
0X0
100
111
113 unless blessed($node) && $node->isa('XML::LibXML::Node');
114
115 129 ▶ if ($node->nodeName eq '#document')
Branch: 2 branches
BranchTrueFalseTotal
if ($node->nodeName eq '#document') { } 29 100 129
elsif ($node->isa('XML::LibXML::Element')) { } 87 13 100
116 {
117 29 return $self->strip_whitespace($node->documentElement);
118 }
119 elsif ($node->isa('XML::LibXML::Element'))
120 {
121 87 ▶ if ($self->element_preserves_whitespace($node))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->element_preserves_whitespace($node)) 3 84 87
122 {
123 3 return 0;
124 }
125
126 84 my $node_category = $self->element_category($node);
127
128 84 $node->normalize;
129 84 my @kids = $node->childNodes;
130 84 my $activity = 0;
131
132 84 ▶ for (my $i = 0; exists $kids[$i]; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if (exists $kids[$i]) 180 84 264
133 {
134 180 my $kid = $kids[$i];
135
136 180 ▶ if ($kid->nodeName eq '#text')
Branch: 1 branch
BranchTrueFalseTotal
if ($kid->nodeName eq '#text') { } 109 71 180
137 {
138 109 ▶ my $prev = exists $kids[$i-1] ? $kids[$i-1] : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $kids[$i - 1] ? : 109 0 109
139 109 ▶ my $next = exists $kids[$i+1] ? $kids[$i+1] : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $kids[$i + 1] ? : 51 58 109
140 109 my $data = $kid->data;
141
142 109 ▶ if ((defined $prev and $self->element_category($prev)==EL_INLINE)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prev and $self->element_category($prev) == 3 or $node_category == 3 and not defined $prev) { } 17 92 109
Condition66%6/9
defined $prev and $self->element_category($prev) == 3 or $node_category == 3 and not defined $prev
l!l&&r!l&&!r
17092
defined $prev and $self->element_category($prev) == 3
!ll&&!rl&&r
09217
$node_category == 3 and not defined $prev
!ll&&!rl&&r
76160
MC/DC25%1/4
defined $prev and $self->element_category($prev) == 3 or $node_category == 3 and not defined $prev
defined $prev $self->element_category($prev) == 3 $node_category == 3 not defined $prev
Truth table42%3/7
A and B or C and not(D)
A= defined $prevB= $self->element_category($prev) == 3C= $node_category == 3D= not defined $prev
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
143 or ($node_category==EL_INLINE and not defined $prev))
144 17 { $data =~ s/^$Whitespace+/ /; }
145 else
146 92 { $data =~ s/^$Whitespace+//; }
147  
148 109 ▶ if ((defined $next and $self->element_category($next)==EL_INLINE)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $next and $self->element_category($next) == 3 or $node_category == 3 and not defined $next) { } 34 75 109
Condition88%8/9
defined $next and $self->element_category($next) == 3 or $node_category == 3 and not defined $next
l!l&&r!l&&!r
181675
defined $next and $self->element_category($next) == 3
!ll&&!rl&&r
583318
$node_category == 3 and not defined $next
!ll&&!rl&&r
75016
MC/DC75%3/4
defined $next and $self->element_category($next) == 3 or $node_category == 3 and not defined $next
defined $next $self->element_category($next) == 3 $node_category == 3 not defined $next
Truth table57%4/7
A and B or C and not(D)
A= defined $nextB= $self->element_category($next) == 3C= $node_category == 3D= not defined $next
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
149 or ($node_category==EL_INLINE and not defined $next))
150 34 { $data =~ s/$Whitespace+$/ /; }
151 else
152 75 { $data =~ s/$Whitespace+$//; }
153
154 109 $data =~ s/$Whitespace+/ /g;
155  
156 109 ▶ $activity++ if length $data ne length $kid->data;
Branch: 1 branch
BranchTrueFalseTotal
if length $data ne length $kid->data 54 55 109
157 109 ▶ $node->removeChild($kid) unless length $data;
Branch: 1 branch
BranchTrueFalseTotal
unless length $data 45 64 109
158 109 $kid->setData($data);
159 }
160 else
161 {
162 71 $activity += $self->strip_whitespace($kid);
163 }
164 }
165
166 84 return $activity;
167 }
168 else
169 {
170 13 ▶ carp(sprintf("Don't know how to handle %s object", ref $node))
Branch: 1 branch
BranchTrueFalseTotal
unless $node->nodeName eq "#comment" or $node->isa("XML::LibXML::CDATASection") or $node->isa("XML::LibXML::PI") 0 13 13
Condition83%5/6
$node->nodeName eq "#comment" or $node->isa("XML::LibXML::CDATASection") or $node->isa("XML::LibXML::PI")
l!l&&r!l&&!r
1030
$node->nodeName eq "#comment" or $node->isa("XML::LibXML::CDATASection")
l!l&&r!l&&!r
913
MC/DC0%0/3
$node->nodeName eq "#comment" or $node->isa("XML::LibXML::CDATASection") or $node->isa("XML::LibXML::PI")
$node->nodeName eq "#comment" $node->isa("XML::LibXML::CDATASection") $node->isa("XML::LibXML::PI")
Truth table75%3/4
A or B or C
A= $node->nodeName eq "#comment"B= $node->isa("XML::LibXML::CDATASection")C= $node->isa("XML::LibXML::PI")
ABCresult
1XX1
01X1
0011
0000
171 unless $node->nodeName eq '#comment'
172 || $node->isa('XML::LibXML::CDATASection')
173 || $node->isa('XML::LibXML::PI');
174 13 return 0;
175 }
176 }
177  
178 sub indent
179 103 ▶{
Subroutine indent: called CC=22 SCAR=30.9
Pod documented
180 103 my ($self, $node, $indent_level) = @_;
181 103 $self = $self->_ensure_self;
182
183 103 ▶ $indent_level = 0 unless defined $indent_level;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $indent_level 12 91 103
184  
185 103 ▶ $self->indent($node->documentElement, $indent_level)
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($node) and $node->nodeName eq "#document" 15 88 103
Condition66%2/3
builtin::blessed($node) and $node->nodeName eq "#document"
!ll&&!rl&&r
08815
MC/DC50%1/2
builtin::blessed($node) and $node->nodeName eq "#document"
builtin::blessed($node) $node->nodeName eq "#document"
Truth table66%2/3
A and B
A= builtin::blessed($node)B= $node->nodeName eq "#document"
ABresult
0X0
100
111
186 if blessed($node) && $node->nodeName eq '#document';
187  
188 103 ▶ return unless blessed($node) && $node->isa('XML::LibXML::Element');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($node) and $node->isa("XML::LibXML::Element") 44 59 103
Condition66%2/3
builtin::blessed($node) and $node->isa("XML::LibXML::Element")
!ll&&!rl&&r
04459
MC/DC50%1/2
builtin::blessed($node) and $node->isa("XML::LibXML::Element")
builtin::blessed($node) $node->isa("XML::LibXML::Element")
Truth table66%2/3
A and B
A= builtin::blessed($node)B= $node->isa("XML::LibXML::Element")
ABresult
0X0
100
111
189  
190 59 ▶ return if $self->element_preserves_whitespace($node);
Branch: 1 branch
BranchTrueFalseTotal
if $self->element_preserves_whitespace($node) 1 58 59
191  
192 58 my $node_category = $self->element_category($node);
193  
194 # EL_COMPACT nodes get treated as inline unless they contain a
195 # block descendent.
196 58 ▶ if ($node_category==EL_COMPACT)
Branch: 1 branch
BranchTrueFalseTotal
if ($node_category == 2) 14 44 58
197 {
198 14 $node_category = EL_INLINE;
199 14 my $descs = $node->getElementsByTagName('*');
200 14 ▶ DESC: while (my $desc = $descs->shift)
Branch: 1 branch
BranchTrueFalseTotal
if (my $desc = $descs->shift) 10 11 21
201 {
202 10 ▶ if ($self->element_category($desc) == EL_BLOCK)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->element_category($desc) == 1) 3 7 10
203 {
204 3 $node_category = EL_BLOCK;
205 3 last DESC;
206 }
207 }
208 }
209
210 58 ▶ if ($node_category==EL_BLOCK)
Branch: 1 branch
BranchTrueFalseTotal
if ($node_category == 1) 39 19 58
211 {
212 39 my $newline = $self->new_line;
213 39 my $indent_string = $self->indent_string($indent_level + 1);
214
215 39 my @kids = $node->childNodes;
216 39 $node->removeChildNodes;
217 39 ▶ for (my $i = 0; exists $kids[$i]; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if (exists $kids[$i]) 73 39 112
218 {
219 73 my $kid = $kids[$i];
220 73 my $did_indent = FALSE;
221
222 73 ▶ if ($i==0)
Branch: 4 branches
BranchTrueFalseTotal
if ($i == 0) { } 28 45 73
elsif ($self->element_category($kid) == 1) { } 13 32 45
elsif ($self->element_category($kid) == 2) { } 13 19 32
elsif (defined $kids[$i - 1]) { } 19 0 19
223 {
224 28 $node->appendText($newline . $indent_string);
225 28 $did_indent = TRUE;
226 }
227 elsif ($self->element_category($kid)==EL_BLOCK)
228 {
229 13 $node->appendText($newline . $indent_string);
230 13 $did_indent = TRUE;
231 }
232 elsif ($self->element_category($kid)==EL_COMPACT)
233 {
234 13 $node->appendText($newline . $indent_string);
235 13 $did_indent = TRUE;
236 }
237 elsif (defined $kids[$i-1])
238 {
239 19 my $prev_category = $self->element_category($kids[$i-1]);
240 19 ▶ if (defined $prev_category
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prev_category and $prev_category == 1 || $prev_category == 2) 4 15 19
Condition100%6/6
defined $prev_category and $prev_category == 1 || $prev_category == 2
!ll&&!rl&&r
874
$prev_category == 1 or $prev_category == 2
l!l&&r!l&&!r
317
MC/DC100%3/3
defined $prev_category and $prev_category == 1 || $prev_category == 2
defined $prev_category $prev_category == 1 $prev_category == 2
Truth table100%4/4
A and B or C
A= defined $prev_categoryB= $prev_category == 1C= $prev_category == 2
ABCresult
0XX0
1000
11X1
1011
241 and ($prev_category==EL_BLOCK or $prev_category==EL_COMPACT))
242 {
243 4 $node->appendText($newline . $indent_string);
244 4 $did_indent = TRUE;
245 }
246 }
247
248 73 ▶ if ($did_indent and $kid->nodeName eq '#text')
Branch: 1 branch
BranchTrueFalseTotal
if ($did_indent and $kid->nodeName eq "#text") 14 59 73
Condition100%3/3
$did_indent and $kid->nodeName eq "#text"
!ll&&!rl&&r
154414
MC/DC100%2/2
$did_indent and $kid->nodeName eq "#text"
$did_indent $kid->nodeName eq "#text"
Truth table100%3/3
A and B
A= $did_indentB= $kid->nodeName eq "#text"
ABresult
0X0
100
111
249 {
250 14 (my $data = $kid->data) =~ s/^ //;
251 14 $kid->setData($data);
252 }
253 73 $node->appendChild($kid);
254 73 $self->indent($kid, $indent_level + 1);
255 }
256 39 ▶ $node->appendText($newline . $self->indent_string($indent_level)) if @kids;
Branch: 1 branch
BranchTrueFalseTotal
if @kids 28 11 39
257 }
258 }
259  
260 sub pretty_print
261 4 ▶{
Subroutine pretty_print: called CC=1 SCAR=0.0
Pod documented
262 4 my ($self, $node, $indent_level) = @_;
263 4 $self = $self->_ensure_self;
264
265 4 $self->strip_whitespace($node);
266 4 $self->indent($node, $indent_level);
267 4 return $node;
268 }
269  
270 sub _run_checks
271 1294 ▶{
Subroutine _run_checks: called CC=14 SCAR=37.9
272 1294 my ($self, $category, $node) = @_;
273  
274 1294 ▶ return FALSE unless defined $self->{element}{$category};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"element"}{$category} 911 383 1294
275
276 383 ▶ if (ref $self->{element}{$category} eq 'CODE'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"element"}{$category} eq "CODE" or not ref $self->{"element"}{$category}) 0 383 383
Condition33%1/3
ref $self->{"element"}{$category} eq "CODE" or not ref $self->{"element"}{$category}
l!l&&r!l&&!r
00383
MC/DC0%0/2
ref $self->{"element"}{$category} eq "CODE" or not ref $self->{"element"}{$category}
ref $self->{"element"}{$category} eq "CODE" not ref $self->{"element"}{$category}
Truth table33%1/3
A or not(B)
A= ref $self->{"element"}{$category} eq "CODE"B= not ref $self->{"element"}{$category}
ABresult
1X1
011
000
277 or !ref $self->{element}{$category})
278 {
279 0 $self->{element}{$category} = [$self->{element}{$category}];
280 }
281
282 383 ▶ if (ref $self->{element}{$category} eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"element"}{$category} eq "ARRAY") 383 0 383
283 {
284 383 foreach my $check (@{$self->{element}{$category}})
285 {
286 902 ▶ if (!ref $check and $check =~ /^\{(.+)\}(.+)$/)
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $check and $check =~ /^\{(.+)\}(.+)$/) { } 0 902 902
elsif (not ref $check) { } 902 0 902
elsif (ref $check eq 'CODE') { } 0 0 0
Condition33%1/3
not ref $check and $check =~ /^\{(.+)\}(.+)$/
!ll&&!rl&&r
09020
MC/DC0%0/2
not ref $check and $check =~ /^\{(.+)\}(.+)$/
not ref $check $check =~ /^\{(.+)\}(.+)$/
Truth table33%1/3
not(A) and B
A= not ref $checkB= $check =~ /^\{(.+)\}(.+)$/
ABresult
0X0
100
111
287 {
288 0 ▶ return TRUE if $node->namespaceURI eq $1 && $node->localname eq $2;
Branch: 1 branch
BranchTrueFalseTotal
if $node->namespaceURI eq $1 and $node->localname eq $2 0 0 0
Condition0%0/3
$node->namespaceURI eq $1 and $node->localname eq $2
!ll&&!rl&&r
000
MC/DC0%0/2
$node->namespaceURI eq $1 and $node->localname eq $2
$node->namespaceURI eq $1 $node->localname eq $2
Truth table0%0/3
A and B
A= $node->namespaceURI eq $1B= $node->localname eq $2
ABresult
0X0
100
111
289 }
290 elsif (!ref $check)
291 {
292 902 ▶ return TRUE if $check eq $node->nodeName;
Branch: 1 branch
BranchTrueFalseTotal
if $check eq $node->nodeName 176 726 902
293 }
294 elsif (ref $check eq 'CODE')
295 {
296 0 my $return = $check->($node);
297 0 ▶ return $return if defined $return;
Branch: 1 branch
BranchTrueFalseTotal
if defined $return 0 0 0
298 }
299 else
300 {
301 0 carp(sprintf("Check for category '%s' ignored; is of type %s", $category, ref $check));
302 }
303 }
304 }
305
306 207 return FALSE;
307 }
308  
309 sub indent_string
310 67 ▶{
Subroutine indent_string: called CC=2 SCAR=6.9
Pod documented
311 67 my ($self, $level) = @_;
312 67 $self = $self->_ensure_self;
313
314 $self->{indent_string} = "\t"
315 67 ▶ unless defined $self->{indent_string};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"indent_string"} 13 54 67
316
317 67 $self->{indent_string} x $level;
318 }
319  
320 sub new_line
321 39 ▶{
Subroutine new_line: called CC=2 SCAR=6.9
Pod documented
322 39 my ($self, $level) = @_;
323 39 $self = $self->_ensure_self;
324
325 $self->{new_line} = "\n"
326 39 ▶ unless defined $self->{new_line};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"new_line"} 15 24 39
327
328 39 $self->{new_line};
329 }
330  
331 sub element_category
332 410 ▶{
Subroutine element_category: called CC=8 SCAR=20.8
Pod documented
333 410 my ($self, $node) = @_;
334 410 $self = $self->_ensure_self;
335  
336 410 ▶ return undef unless blessed($node);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($node) 0 410 410
337
338 410 ▶ return EL_BLOCK if $self->_run_checks(block => $node);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_run_checks("block", $node) 0 410 410
339 410 ▶ return EL_COMPACT if $self->_run_checks(compact => $node);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_run_checks("compact", $node) 82 328 410
340 328 ▶ return EL_INLINE if $self->_run_checks(inline => $node);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_run_checks("inline", $node) 90 238 328
341  
342 238 ▶ return EL_BLOCK if $node->isa('XML::LibXML::Element');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("XML::LibXML::Element") 136 102 238
343 102 ▶ return EL_COMPACT if $node->nodeName eq '#comment';
Branch: 1 branch
BranchTrueFalseTotal
if $node->nodeName eq "#comment" 12 90 102
344 90 ▶ return EL_COMPACT if $node->isa('XML::LibXML::PI');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("XML::LibXML::PI") 6 84 90
345
346 84 return undef;
347 }
348  
349 sub element_preserves_whitespace
350 146 ▶{
Subroutine element_preserves_whitespace: called CC=9 SCAR=25.7
Pod documented
351 146 my ($self, $node) = @_;
352 146 $self = $self->_ensure_self;
353  
354 146 ▶ return undef unless blessed($node);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($node) 0 146 146
355 146 ▶ return TRUE if $node->nodeName eq '#comment';
Branch: 1 branch
BranchTrueFalseTotal
if $node->nodeName eq "#comment" 0 146 146
356 146 ▶ return TRUE if $node->isa('XML::LibXML::PI');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("XML::LibXML::PI") 0 146 146
357
358 146 ▶ return TRUE if $self->_run_checks(preserves_whitespace => $node);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_run_checks("preserves_whitespace", $node) 4 142 146
359
360 142 ▶ return TRUE
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("XML::LibXML::Element") and $node->hasAttributeNS("http://www.w3.org/XML/1998/namespace", "space") and lc $node->getAttributeNS("http://www.w3.org/XML/1998/namespace", "space") eq "preserve" 0 142 142
Condition33%2/6
$node->isa("XML::LibXML::Element") and $node->hasAttributeNS("http://www.w3.org/XML/1998/namespace", "space") and lc $node->getAttributeNS("http://www.w3.org/XML/1998/namespace", "space") eq "preserve"
!ll&&!rl&&r
14200
$node->isa("XML::LibXML::Element") and $node->hasAttributeNS("http://www.w3.org/XML/1998/namespace", "space")
!ll&&!rl&&r
01420
MC/DC0%0/3
$node->isa("XML::LibXML::Element") and $node->hasAttributeNS("http://www.w3.org/XML/1998/namespace", "space") and lc $node->getAttributeNS("http://www.w3.org/XML/1998/namespace", "space") eq "preserve"
$node->isa("XML::LibXML::Element") $node->hasAttributeNS("http://www.w3.org/XML/1998/namespace", "space") lc $node->getAttributeNS("http://www.w3.org/XML/1998/namespace", "space") eq "preserve"
Truth table25%1/4
A and B and C
A= $node->isa("XML::LibXML::Element")B= $node->hasAttributeNS("http://www.w3.org/XML/1998/namespace", "space")C= lc $node->getAttributeNS("http://www.w3.org/XML/1998/namespace", "space") eq "preserve"
ABCresult
0XX0
10X0
1100
1111
361 if $node->isa('XML::LibXML::Element')
362 && $node->hasAttributeNS(XML_XML_NS, 'space')
363 && lc $node->getAttributeNS(XML_XML_NS, 'space') eq 'preserve';
364
365 142 ▶ return FALSE if $node->isa('XML::LibXML::Element');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("XML::LibXML::Element") 142 0 142
366 0 return undef;
367 }
368  
369 sub print_xml ($;$)
370 0 ▶{
Subroutine print_xml: not called CC=4 SCAR=30.0
Pod documented
371 0 my ($xml, $indent) = @_;
372 0 ▶ unless (blessed($xml))
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($xml)) 0 0 0
373 {
374 0 local $@ = undef;
375 0 ▶ eval { $xml = XML::LibXML->new->parse_string($xml); 1; }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $xml = "XML::LibXML"->new->parse_string($xml); 1 } } or croak("Could not parse XML: $@") 0 0 0
376 or croak("Could not parse XML: $@");
377 }
378 0 ▶ $indent = 0 unless defined $indent;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $indent 0 0 0
379 0 print __PACKAGE__->pretty_print($xml, $indent)->toString;
380 }
381  
382 5 TRUE;
383  
384 __END__
↑ Summary