blib/lib/XML/LibXML/Debugging.pm

filter: Statementstmt 65.7% 50 / 76 Branchbran 33.3% 10 / 30 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 77.7% 14 / 18 Podpod n/a totaltotal 55.2% 74 / 134 CC 22 SCAR 29.9
CC
22
Cov
54%
toClarkML
48.3
toDebuggingHash
25.9
toClarkML
4.4
CRAP 20.0
↑ Summary
1 package XML::LibXML::Debugging;
2  
3 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use parent qw(XML::LibXML);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use HTML::HTML5::Entities qw(encode_entities_numeric);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use XML::LibXML qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 $XML::LibXML::Debugging::AUTHORITY = 'cpan:TOBYINK';
12 1 $XML::LibXML::Debugging::VERSION = '0.103';
13 }
14  
15 sub XML::LibXML::Document::toDebuggingHash
16 1 ▶{
Subroutine toDebuggingHash: called CC=1 SCAR=0.0
17 1 my $n = shift;
18
19 return {
20 1 'type' => 'Document',
21 'root' => $n->documentElement->toDebuggingHash,
22 };
23 }
24  
25 sub XML::LibXML::Document::toClarkML
26 1 ▶{
Subroutine toClarkML: called CC=1 SCAR=0.0
27 1 my $n = shift;
28 1 $n->documentElement->toClarkML;
29 }
30  
31 sub XML::LibXML::Element::toDebuggingHash
32 1 ▶{
Subroutine toDebuggingHash: called CC=8 SCAR=32.5
33 1 my $n = shift;
34
35 1 my $rv = {
36 'type' => 'Element',
37 'qname' => $n->nodeName,
38 'prefix' => $n->prefix,
39 'suffix' => $n->localname,
40 'nsuri' => $n->namespaceURI,
41 'attributes' => [],
42 'children' => [],
43 };
44
45 1 foreach my $attr ($n->attributes)
46 {
47 2 my $x = $attr->toDebuggingHash;
48 2 ▶ push @{ $rv->{'attributes'} }, $x if $x;
Branch: 1 branch
BranchTrueFalseTotal
if $x 2 0 2
49 }
50
51 1 foreach my $kid ($n->childNodes)
52 {
53 0 ▶ if ($kid->nodeType == XML_TEXT_NODE
Branch: 3 branches
BranchTrueFalseTotal
if ($kid->nodeType == 3 or $kid->nodeType == 4) { } 0 0 0
elsif ($kid->nodeType == 8) { } 0 0 0
elsif ($kid->nodeType == 1) { } 0 0 0
Condition0%0/3
$kid->nodeType == 3 or $kid->nodeType == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$kid->nodeType == 3 or $kid->nodeType == 4
$kid->nodeType == 3 $kid->nodeType == 4
Truth table0%0/3
A or B
A= $kid->nodeType == 3B= $kid->nodeType == 4
ABresult
1X1
011
000
54 || $kid->nodeType == XML_CDATA_SECTION_NODE)
55 {
56 0 push @{ $rv->{'children'} }, $kid->nodeValue;
57 }
58 elsif ($kid->nodeType == XML_COMMENT_NODE)
59 {
60 0 push @{ $rv->{'children'} }, $kid->toDebuggingHash;
61 }
62 elsif ($kid->nodeType == XML_ELEMENT_NODE)
63 {
64 0 push @{ $rv->{'children'} }, $kid->toDebuggingHash;
65 }
66 }
67
68 1 return $rv;
69 }
70  
71 sub XML::LibXML::Element::toClarkML
72 1 ▶{
Subroutine toClarkML: called CC=11 SCAR=38.8
73 1 my $n = shift;
74
75 1 my $rv;
76
77 1 ▶ if (defined $n->namespaceURI)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n->namespaceURI) { } 1 0 1
78 {
79 1 $rv = sprintf("<{%s}%s", $n->namespaceURI, $n->localname);
80 }
81 else
82 {
83 0 $rv = sprintf("<%s", $n->localname);
84 }
85
86 1 foreach my $attr ($n->attributes)
87 {
88 2 my $x = $attr->toClarkML;
89 2 ▶ $rv .= " $x" if $x;
Branch: 1 branch
BranchTrueFalseTotal
if $x 2 0 2
90 }
91
92 1 ▶ if (! $n->childNodes)
Branch: 1 branch
BranchTrueFalseTotal
unless ($n->childNodes) 1 0 1
93 {
94 1 return $rv . "/>";
95 }
96
97 0 $rv .= ">";
98
99 0 foreach my $kid ($n->childNodes)
100 {
101 0 ▶ if ($kid->nodeType == XML_TEXT_NODE
Branch: 3 branches
BranchTrueFalseTotal
if ($kid->nodeType == 3 or $kid->nodeType == 4) { } 0 0 0
elsif ($kid->nodeType == 8) { } 0 0 0
elsif ($kid->nodeType == 1) { } 0 0 0
Condition0%0/3
$kid->nodeType == 3 or $kid->nodeType == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$kid->nodeType == 3 or $kid->nodeType == 4
$kid->nodeType == 3 $kid->nodeType == 4
Truth table0%0/3
A or B
A= $kid->nodeType == 3B= $kid->nodeType == 4
ABresult
1X1
011
000
102 || $kid->nodeType == XML_CDATA_SECTION_NODE)
103 {
104 0 $rv .= encode_entities_numeric($kid->nodeValue);
105 }
106 elsif ($kid->nodeType == XML_COMMENT_NODE)
107 {
108 0 $rv .= "<!--" . $kid->nodeValue . "-->";
109 }
110 elsif ($kid->nodeType == XML_ELEMENT_NODE)
111 {
112 0 $rv .= $kid->toClarkML;
113 }
114 }
115
116 0 ▶ if (defined $n->namespaceURI)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n->namespaceURI) { } 0 0 0
117 {
118 0 $rv .= sprintf("</{%s}%s>", $n->namespaceURI, $n->localname);
119 }
120 else
121 {
122 0 $rv .= sprintf("</%s>", $n->localname);
123 }
124
125 0 return $rv;
126 }
127  
128 sub XML::LibXML::Comment::toDebuggingHash
129 0 ▶{
Subroutine toDebuggingHash: not called CC=1 SCAR=6.9
130 0 my $n = shift;
131
132 return {
133 0 'type' => 'Comment',
134 'comment' => $n->nodeValue,
135 };
136 }
137  
138 sub XML::LibXML::Comment::toClarkML
139 0 ▶{
Subroutine toClarkML: not called CC=1 SCAR=6.9
140 0 my $n = shift;
141 0 return "<!--" . $n->nodeValue . "-->";
142 }
143  
144 sub XML::LibXML::Attr::toDebuggingHash
145 2 ▶{
Subroutine toDebuggingHash: called CC=2 SCAR=6.9
146 2 my $n = shift;
147
148 2 ▶ if ($n->nodeType == XML_NAMESPACE_DECL)
Branch: 1 branch
BranchTrueFalseTotal
if ($n->nodeType == 18) 1 1 2
149 {
150 return {
151 1 'type' => 'Namespace Declaration',
152 'qname' => $n->nodeName,
153 'prefix' => $n->prefix,
154 'suffix' => $n->getLocalName,
155 'nsuri' => $n->getNamespaceURI,
156 'value' => $n->getData,
157 };
158 }
159
160 return {
161 1 'type' => 'Attribute',
162 'qname' => $n->nodeName,
163 'prefix' => $n->prefix,
164 'suffix' => $n->localname,
165 'nsuri' => $n->namespaceURI,
166 'value' => $n->nodeValue,
167 };
168 }
169  
170 sub XML::LibXML::Attr::toClarkML
171 2 ▶{
Subroutine toClarkML: called CC=4 SCAR=14.8
172 2 my $n = shift;
173  
174 2 ▶ if ($n->nodeType == XML_NAMESPACE_DECL)
Branch: 1 branch
BranchTrueFalseTotal
if ($n->nodeType == 18) 1 1 2
175 {
176 1 ▶ if (defined $n->getLocalName)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n->getLocalName) 0 1 1
177 {
178 0 return sprintf("{%s}%s=\"%s\"",
179 $n->getNamespaceURI, $n->getLocalName, $n->getData);
180 }
181 1 return sprintf("{%s}xmlns=\"%s\"",
182 $n->getNamespaceURI, $n->getData);
183 }
184
185 1 ▶ if (defined $n->namespaceURI)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n->namespaceURI) { } 1 0 1
186 {
187 1 return sprintf("{%s}%s=\"%s\"",
188 $n->namespaceURI, $n->localname, $n->nodeValue);
189 }
190 else
191 {
192 0 return sprintf("%s=\"%s\"",
193 $n->localname, $n->nodeValue);
194 }
195 }
196  
197 sub XML::LibXML::Node::toClarkML
198 0 ▶{
Subroutine toClarkML: not called CC=1 SCAR=6.9
199 0 return '';
200 }
201  
202 sub XML::LibXML::Node::toDebuggingHash
203 0 ▶{
Subroutine toDebuggingHash: not called CC=1 SCAR=6.9
204 0 return {type=>'Node'};
205 }
206  
207 sub XML::LibXML::Namespace::toClarkML
208 1 ▶{
Subroutine toClarkML: called CC=1 SCAR=0.0
209 1 return XML::LibXML::Attr::toClarkML(@_);
210 }
211  
212 sub XML::LibXML::Namespace::toDebuggingHash
213 1 ▶{
Subroutine toDebuggingHash: called CC=1 SCAR=0.0
214 1 return XML::LibXML::Attr::toDebuggingHash(@_);
215 }
216  
217 1 1;
218  
219 __END__
↑ Summary