blib/lib/XML/LibXML/TreeDumper.pm

filter: Statementstmt 100% 45 / 45 Branchbran 100% 8 / 8 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 100% 65 / 65 CC 8 SCAR 10.5
CC
8
Cov
100%
_dump_node
5.0
dump
3.0
_build_node
2.0
CRAP 2.9
↑ Summary
1 package XML::LibXML::TreeDumper;
2  
3 # ABSTRACT: print a tree of libxml elements
4  
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 our $VERSION = '0.03';
13  
14 4 has data => ( is => 'rw', trigger => \&_parse );
15 4 has node => ( is => 'rw', lazy => 1, builder => \&_parse);
16  
17 4 ▶sub dump {
Subroutine dump: called CC=3 SCAR=11.0
Pod documented
18 4 my ($self, $xpath) = @_;
19  
20 4 ▶ my @nodes = $xpath ? $self->node->findnodes( $xpath ) : $self->node;
Branch: 1 branch
BranchTrueFalseTotal
$xpath ? : 2 2 4
21 4 my $string = '';
22 4 for my $node ( @nodes ) {
23 4 $self->_dump_node( $node, \$string );
24 }
25  
26 4 return $string;
27 }
28  
29 4 ▶sub _parse {
Subroutine _build_node: called CC=2 SCAR=6.9
30 4 my ($self) = @_;
31  
32 4 my $parser = XML::LibXML->new;
33  
34 4 my $doc;
35 4 ▶ if ( ref $self->data ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->data) { } 2 2 4
36 2 $doc = $parser->parse_string( ${ $self->data } );
37 }
38 else {
39 2 $doc = $parser->parse_file( $self->data );
40 }
41  
42 4 $self->node( $doc->getDocumentElement );
43 }
44  
45 14 ▶sub _dump_node {
Subroutine _dump_node: called CC=5 SCAR=16.1
46 14 my ($self, $node, $out, $indent) = @_;
47  
48 14 ▶ $indent //= '';
Condition100%2/2
$indent //= ""
l!l
104
MC/DC100%1/1
$indent //= ""
$indent
Truth table100%2/2
A
A= $indent
Aresult
11
00
49  
50 14 my $name = $node->getName;
51  
52 14 ▶ my $text = $node->isa( 'XML::LibXML::Text' ) ? $node->getData : '';
Branch: 1 branch
BranchTrueFalseTotal
$node->isa('XML::LibXML::Text') ? : 8 6 14
53 14 ▶ if ( length $text ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $text) 8 6 14
54 8 $text =~ s/\\/\\\\/g;
55 8 $text =~ s/"/\\"/g;
56 #$text =~ s/([[:cntrl:]])/quotemeta($1)/eg;
57 8 $name = sprintf '"%s"', $text;
58 }
59  
60 14 $$out .= $indent . ref( $node ) . ' ' . $name . "\n";
61 14 my @children = $node->childNodes;
62 14 for my $child ( @children ) {
63 10 $self->_dump_node( $child, $out, $indent . ( ' ' x 4 ) );
64 }
65 }
66  
67 4 1;
68  
69 __END__
↑ Summary