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

filter: Statementstmt 96.2% 51 / 53 Branchbran 50.0% 3 / 6 Conditioncond 60.0% 9 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 100% 20 / 20 Podpod 92.3% 12 / 13 totaltotal 81.2% 95 / 117 SCAR 22.3
CC
9
Cov
85%
guess_version
4.1
nav_path
2.3
parser
2.0
CRAP 9.3
« blib/lib/EPUB/Parser/File/Parser.pm ↑ Summary blib/lib/EPUB/Parser/Util/Archive.pm »
1 package EPUB::Parser::File::OPF;
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 EPUB::Parser::File::Parser::OPF;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use EPUB::Parser::File::OPF::Context;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use EPUB::Parser::File::Container;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use Smart::Args;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub new {
11 10 ▶ args(
Subroutine new: called CC=1 SCAR=0.0
Pod documented
12 my $class => 'ClassName',
13 my $zip => { isa => 'EPUB::Parser::Util::Archive' },
14 my $epub_version,
15 );
16  
17 10 my $self = bless {
18 zip => $zip,
19 epub_version => $epub_version,
20 } => $class;
21  
22 10 return $self;
23 }
24  
25 sub parser {
26 17 ▶ my $self = shift;
Subroutine parser: called CC=2 SCAR=7.1
Pod documented
27  
28 $self->{parser}
29 17 ▶ ||= EPUB::Parser::File::Parser::OPF->new({ data => $self->data });
Condition66%2/3
$self->{"parser"} ||= "EPUB::Parser::File::Parser::OPF"->new({"data", $self->data})
l!l&&r!l&&!r
7100
MC/DC0%0/2
$self->{"parser"} ||= "EPUB::Parser::File::Parser::OPF"->new({"data", $self->data})
$self->{"parser"} "EPUB::Parser::File::Parser::OPF"->new({"data", $self->data})
Truth table66%2/3
A ||= B
A= $self->{"parser"}B= "EPUB::Parser::File::Parser::OPF"->new({"data", $self->data})
ABresult
1X1
011
000
30 }
31  
32 sub path {
33 18 ▶ my $self = shift;
Subroutine path: called CC=2 SCAR=7.0
Pod documented
34  
35 18 ▶ $self->{path} ||= do {
Condition66%2/3
$self->{"path"} ||= do {
l!l&&r!l&&!r
8100
MC/DC0%0/2
$self->{"path"} ||= do { my $container = "EPUB::Parser::File::Container"->new({"zip", $self->{"zip"}}); $container->opf_path }
$self->{"path"} do { my $container = "EPUB::Parser::File::Container"->new({"zip", $self->{"zip"}}); $container->opf_path }
Truth table66%2/3
A ||= B
A= $self->{"path"}B= do { my $container = "EPUB::Parser::File::Container"->new({"zip", $self->{"zip"}}); $container->opf_path }
ABresult
1X1
011
000
36 10 my $container = EPUB::Parser::File::Container->new({ zip => $self->{zip} });
37 10 $container->opf_path;
38 };
39 }
40  
41 sub dir {
42 17 ▶ my $self = shift;
Subroutine dir: called CC=2 SCAR=7.0
Pod documented
43 17 require File::Basename;
44 17 ▶ $self->{dir} ||= File::Basename::dirname($self->path);
Condition66%2/3
$self->{"dir"} ||= File::Basename::dirname($self->path)
l!l&&r!l&&!r
1070
MC/DC0%0/2
$self->{"dir"} ||= File::Basename::dirname($self->path)
$self->{"dir"} File::Basename::dirname($self->path)
Truth table66%2/3
A ||= B
A= $self->{"dir"}B= File::Basename::dirname($self->path)
ABresult
1X1
011
000
45 }
46  
47  
48 sub data {
49 11 ▶ my $self = shift;
Subroutine data: called CC=2 SCAR=7.1
Pod documented
50 11 ▶ $self->{data} ||= $self->{zip}->get_member_data({ file_path => $self->path });
Condition66%2/3
$self->{"data"} ||= $self->{"zip"}->get_member_data({"file_path", $self->path})
l!l&&r!l&&!r
1100
MC/DC0%0/2
$self->{"data"} ||= $self->{"zip"}->get_member_data({"file_path", $self->path})
$self->{"data"} $self->{"zip"}->get_member_data({"file_path", $self->path})
Truth table66%2/3
A ||= B
A= $self->{"data"}B= $self->{"zip"}->get_member_data({"file_path", $self->path})
ABresult
1X1
011
000
51 }
52  
53 sub context {
54 46 ▶ my $self = shift;
Subroutine context: called CC=2 SCAR=6.9
Pod undocumented
55 46 my $context_name = shift;
56 46 ▶ return $self->{$context_name} if $self->{$context_name};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{$context_name} 32 14 46
57  
58 14 $self->{$context_name} = EPUB::Parser::File::OPF::Context->new({
59 opf => $self,
60 parser => $self->parser,
61 context_name => $context_name,
62 });
63 }
64  
65 6 ▶sub spine { shift->context('spine' ) }
Subroutine spine: called CC=1 SCAR=0.0
Pod documented
66 26 ▶sub manifest { shift->context('manifest') }
Subroutine manifest: called CC=1 SCAR=0.0
Pod documented
67 12 ▶sub metadata { shift->context('metadata') }
Subroutine metadata: called CC=1 SCAR=0.0
Pod documented
68 1 ▶sub guide { shift->context('guide' ) }
Subroutine guide: called CC=1 SCAR=0.0
Pod documented
69  
70 sub nav_path {
71 4 ▶ my $self = shift;
Subroutine nav_path: called CC=2 SCAR=8.1
Pod documented
72 4 ▶ $self->{nav_path} ||= sprintf("%s/%s", $self->dir, $self->manifest->nav_path);
Condition33%1/3
$self->{"nav_path"} ||= sprintf("%s/%s", $self->dir, $self->manifest->nav_path)
l!l&&r!l&&!r
040
MC/DC0%0/2
$self->{"nav_path"} ||= sprintf("%s/%s", $self->dir, $self->manifest->nav_path)
$self->{"nav_path"} sprintf("%s/%s", $self->dir, $self->manifest->nav_path)
Truth table33%1/3
A ||= B
A= $self->{"nav_path"}B= sprintf("%s/%s", $self->dir, $self->manifest->nav_path)
ABresult
1X1
011
000
73 }
74  
75 sub cover_image_path {
76 2 ▶ shift->manifest->cover_image_path(@_);
Subroutine cover_image_path: called CC=1 SCAR=0.0
Pod documented
77 }
78  
79 sub guess_version {
80 1 ▶ my $self = shift;
Subroutine guess_version: called CC=3 SCAR=14.2
Pod documented
81 1 my $version = $self->parser->single('/pkg:package/@version')->string_value;
82
83 1 ▶ if ($version) {
Branch: 2 branches
BranchTrueFalseTotal
if ($version) { } 1 0 1
elsif ($self->nav_path) { } 0 0 0
84 1 return $version;
85 }
86 elsif ( $self->nav_path ) {
87 0 return '3.0';
88 }
89 else {
90 0 return;
91 }
92 }
93  
94  
95 14 1;
96  
97  
98 __END__
99  
100 =encoding utf-8
101  
102 =head1 NAME
103  
104 EPUB::Parser::File::OPF - parses opf file
105  
106 =head1 SYNOPSIS
107  
108 use EPUB::Parser;
109 my $ep = EPUB::Parser->new->load_file({ file_path => 'sample.epub' });
110 my $opf = $ep->opf;
111  
112 =head1 METHODS
113  
114 =head2 new(\%opts)
115  
116 Constructor.
117 This method called from L<EPUB::Parser> object.
118 $epub_parser->opf;
119  
120 =head2 parser
121  
122 Returns instance of L<EPUB::Parser::File::Parser::OPF>.
123  
124 =head2 path
125  
126 get opf file path from 'META-INF/container.xml'
127  
128 =head2 dir
129  
130 get directory path of opf file.
131 File::Basename::dirname($self->path);
132  
133 =head2 data
134  
135 get blob of opf file from loaded EPUB
136  
137 =head2 spine
138  
139 Returns instance of L<EPUB::Parser::File::OPF::Context::Spine>.
140  
141 =head2 manifest
142  
143 Returns instance of L<EPUB::Parser::File::OPF::Context::Manifest>.
144  
145 =head2 metadata
146  
147 Returns instance of L<EPUB::Parser::File::OPF::Context::Metadata>.
148  
149 =head2 guide
150  
151 Returns instance of L<EPUB::Parser::File::OPF::Context::Guide>.
152  
153 =head2 nav_path
154  
155 Returns navigation file path from manifest.
156  
157 =head2 cover_image_path(\%opt)
158  
159 Shortcut method.
160 see L<EPUB::Parser::File::OPF::Context::Manifest>.
161  
162 =head2 guess_version
163  
164 get opf version.
165 return '3.0' if version is not found and navigation file exists.
166  
167 =head1 LICENSE
168  
169 Copyright (C) tokubass.
170  
171 This library is free software; you can redistribute it and/or modify
172 it under the same terms as Perl itself.
173  
174 =head1 AUTHOR
175  
176 tokubass E<lt>tokubass {at} cpan.orgE<gt>
177  
178 =cut
179  
« blib/lib/EPUB/Parser/File/Parser.pm ↑ Summary blib/lib/EPUB/Parser/Util/Archive.pm »