| 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
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 1 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 46 | 0 | croak "error: call to $method failed: $@"; | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 2 | ▶ | if (defined $r) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | # A STRING | ||||||||||||||||||||
| 52 | 1 | ▶ | if (!ref($r)) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 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; | |||||||||||||||||||