Transformer.pm

filter: Statementstmt 90.3% 28 / 31 Branchbran 50.0% 5 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 74.0% 40 / 54 CC 8 SCAR 14.9
CC
8
Cov
77%
transform
7.3
new
3.2
BEGIN
1.0
CRAP 4.4
↑ Summary Enhanced.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package XML::LibXML::Transformer;
5  
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use XML::LibXML::Enhanced qw(parse_xml_chunk);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.8
Pod undocumented
10 1 my ($proto, $namespace) = @_;
11
12 1 ▶ croak "error: namespace not defined" unless defined $namespace;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $namespace 0 1 1
13
14 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
15
16 1 my $self = {
17 NAMESPACE => $namespace,
18 };
19
20 1 bless $self, $class;
21 }
22  
23 1 ▶sub transform {
Subroutine transform: called CC=6 SCAR=19.9
Pod undocumented
24 1 my ($self, $doc, @args) = @_;
25
26 # In scalar context, findnodes returns a NodeList object which
27 # provides iterators, etc. This might be worth investigating if
28 # findnodes is returning a lot of nodes, and the following gives
29 # poor performance.
30  
31 1 my @n = $doc->findnodes(
32 "descendant-or-self::*[namespace-uri() = '$self->{NAMESPACE}']"
33 );
34
35 1 foreach my $n (@n) {
36  
37 2 my $method = $n->localname;
38
39 2 my $r = eval {
40 2 $self->$method($n->toAttributeHash, $n, @args);
41 };
42
43 # TODO check that $method actually exists before this call...
44  
45 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
46 0 croak "error: call to $method failed: $@";
47 }
48
49 2 ▶ if (defined $r) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $r) 1 1 2
50  
51 # A STRING
52 1 ▶ if (!ref($r)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $r) { } 1 0 1
elsif (UNIVERSAL::isa($r, 'XML::LibXML::Node')) { } 0 0 0
53 1 $n->replaceNode($doc->adoptNode(parse_xml_chunk($r)));
54 }
55  
56 # A NODE
57 elsif (UNIVERSAL::isa($r, "XML::LibXML::Node")) {
58 0 $n->replaceNode($r);
59 }
60  
61 else {
62 0 carp qq{warning: "$method" returned neither a node nor a string};
63 }
64 }
65  
66 }
67
68 }
69  
70 1 1;
↑ Summary Enhanced.pm »