blib/lib/EPUB/Parser/File/Parser.pm

filter: Statementstmt 100% 51 / 51 Branchbran 62.5% 10 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 4 totaltotal 84.0% 74 / 88 SCAR 23.2
CC
10
Cov
89%
context_node
6.1
_find
4.8
single
2.0
CRAP 10.1
« blib/lib/EPUB/Parser/File/OPF/Context/Manifest.pm ↑ Summary blib/lib/EPUB/Parser/File/OPF.pm »
1 package EPUB::Parser::File::Parser;
2 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use Smart::Args;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use XML::LibXML::XPathContext;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 14 use constant CONTEXT_XPATH => {
10 metadata => '/pkg:package/pkg:metadata',
11 manifest => '/pkg:package/pkg:manifest',
12 spine => '/pkg:package/pkg:spine',
13 guide => '/pkg:package/pkg:guide',
14 toc => '/xhtml:html/xhtml:body/xhtml:nav[@id="toc"]',
15 14 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 sub new {
18 32 ▶ args(
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
19 my $class => 'ClassName',
20 my $data,
21 );
22  
23 32 my $xml = XML::LibXML->new({ no_network => 1, recover => 1 });
24 32 my $xml_document = $xml->parse_string($data);
25 32 my $xpath = XML::LibXML::XPathContext->new($xml_document);
26  
27 32 my $self = bless {
28 parser => $xpath,
29 doc => $xml_document,
30 current_context_key => '',
31 } => $class;
32  
33 32 return $self;
34 }
35  
36 sub context_node {
37 120 ▶ my $self = shift;
Subroutine context_node: called CC=6 SCAR=18.0
Pod undocumented
38 120 my $key = shift;
39  
40 120 ▶ return $self->{parser}->getContextNode unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 74 46 120
41  
42 46 ▶ if ( $self->{current_context_key} ne $key ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"current_context_key"} ne $key) 21 25 46
43  
44 21 ▶ croak "did not match key($key) in CONTEXT_XPATH()" unless my $xpath = CONTEXT_XPATH()->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless my $xpath = {"guide" => "/pkg:package/pkg:guide","manifest" => "/pkg:package/pkg:manifest","metadata" => "/pkg:package/pkg:metadata","spine" => "/pkg:package/pkg:spine","toc" => "/xhtml:html/xhtml:body/xhtml:nav[\@id=\"toc\"]"}->{$key} 0 21 21
45  
46 21 my $nodes = $self->{parser}->findnodes($xpath);
47 21 my $context_node;
48 21 ▶ if ( $nodes->size >= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nodes->size >= 1) 21 0 21
49 21 $context_node = $nodes->get_node(1);
50 }
51  
52 21 ▶ croak '$context_node not found' unless $context_node;
Branch: 1 branch
BranchTrueFalseTotal
unless $context_node 0 21 21
53
54 21 $self->{parser}->setContextNode($context_node);
55 21 $self->{current_context_key} = $key;
56 }
57  
58 46 return $self;
59 }
60  
61 sub _find {
62 73 ▶ my $self = shift;
Subroutine _find: called CC=4 SCAR=15.6
63 73 ▶ my $xpath = shift or croak 'please input xpath';
Branch: 1 branch
BranchTrueFalseTotal
my $xpath = shift() or croak("please input xpath") 0 73 73
64 73 ▶ my $node = shift || $self->context_node;
Condition33%1/3
shift() || $self->context_node
l!l&&r!l&&!r
0730
MC/DC0%0/2
shift() || $self->context_node
shift() $self->context_node
Truth table33%1/3
A || B
A= shift()B= $self->context_node
ABresult
1X1
011
000
65  
66 $node ? $self->{parser}->findnodes($xpath, $node)
67 73 ▶ : $self->{parser}->findnodes($xpath);
Branch: 1 branch
BranchTrueFalseTotal
$node ? : 73 0 73
68 }
69  
70 sub find {
71 44 ▶ my $self = shift;
Subroutine find: called CC=1 SCAR=0.0
Pod undocumented
72 44 $self->_find(@_);
73 }
74  
75 sub single {
76 29 ▶ my $self = shift;
Subroutine single: called CC=2 SCAR=7.0
Pod undocumented
77 29 my $node_list = $self->_find(@_);
78 29 ▶ if ( $node_list->size >= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node_list->size >= 1) 29 0 29
79 29 $node_list->get_node(1);
80 }
81 }
82  
83  
84 14 1;
« blib/lib/EPUB/Parser/File/OPF/Context/Manifest.pm ↑ Summary blib/lib/EPUB/Parser/File/OPF.pm »