Lite/NCX.pm

filter: Statementstmt 100% 60 / 60 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 50.0% 4 / 8 totaltotal 95.0% 77 / 81 CC 3 SCAR 2.4
CC
3
Cov
100%
create_doc_data
2.0
create_navmap
2.0
BEGIN
1.0
CRAP 1.3
« Lite/Metadata/Item.pm ↑ Summary Lite/Manifest/Item.pm »
1 # Copyright (c) 2009, 2010 Oleksandr Tymoshenko <gonzo@bluezbox.com>
2 # All rights reserved.
3  
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
7 # 1. Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # 2. Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
12  
13 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 # SUCH DAMAGE.
24 package EBook::EPUB::Lite::NCX;
25 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 ▶use Types::Standard qw/ArrayRef Object Str/;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 ▶use EBook::EPUB::Lite::NCX::NavPoint;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 # Very simplified module for generation NCX
30  
31 4 has uid => ( isa => Str, is => 'rw' );
32 4 has title => ( isa => Str, is => 'rw' );
33  
34 has navpoints => (
35 is => 'ro',
36 isa => ArrayRef[Object],
37 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
38 4 );
39  
40 2 ▶sub all_navpoints {
Subroutine all_navpoints: called CC=1 SCAR=0.0
Pod documented
41 2 return @{ shift->navpoints};
42 }
43  
44  
45  
46 has authors => (
47 is => 'ro',
48 isa => ArrayRef[Str],
49 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
50 4 );
51  
52 2 ▶sub all_authors {
Subroutine all_authors: called CC=1 SCAR=0.0
Pod undocumented
53 2 return @{ shift->authors };
54 }
55  
56 1 ▶sub add_author {
Subroutine add_author: called CC=1 SCAR=0.0
Pod documented
57 1 my ($self, @args) = @_;
58 1 push @{ shift->authors }, @args;
59 }
60  
61 sub to_xml
62 2 ▶{
Subroutine to_xml: called CC=1 SCAR=0.0
Pod documented
63 2 my ($self) = @_;
64 2 my $xml;
65 2 my $writer = XML::Writer->new(
66 OUTPUT => \$xml,
67 DATA_MODE => 1,
68 DATA_INDENT => 2,
69 );
70  
71 2 $writer->xmlDecl('utf-8');
72 2 $writer->doctype('ncx', '-//NISO//DTD ncx 2005-1//EN',
73 'http://www.daisy.org/z3986/2005/ncx-2005-1.dtd');
74
75 2 $writer->startTag('ncx',
76 version => '2005-1',
77 xmlns => 'http://www.daisy.org/z3986/2005/ncx/',
78 );
79 # <head>..</head>
80 2 $self->create_head_element($writer);
81 # Now document data
82 2 $self->create_doc_data($writer);
83 2 $self->create_navmap($writer);
84  
85 2 $writer->endTag('ncx');
86 2 $writer->end();
87  
88 2 return $xml;
89 }
90  
91 sub create_head_element
92 2 ▶{
Subroutine create_head_element: called CC=1 SCAR=0.0
Pod undocumented
93 2 my ($self, $writer) = @_;
94 2 $writer->startTag('head');
95 2 $writer->emptyTag('meta',
96 name => 'dtb:uid',
97 content => $self->uid,
98 );
99  
100 2 $writer->emptyTag('meta',
101 name => 'dtb:depth',
102 content => '1',
103 );
104  
105 2 $writer->emptyTag('meta',
106 name => 'dtb:totalPageCount',
107 content => '0',
108 );
109  
110 2 $writer->emptyTag('meta',
111 name => 'dtb:maxPageNumber',
112 content => '0',
113 );
114  
115 2 $writer->endTag('head');
116 }
117  
118 sub create_doc_data
119 2 ▶{
Subroutine create_doc_data: called CC=2 SCAR=6.9
Pod undocumented
120 2 my ($self, $writer) = @_;
121  
122 2 $writer->startTag('docTitle');
123 2 $writer->dataElement('text', $self->title);
124 2 $writer->endTag('docTitle');
125  
126 2 foreach my $author ($self->all_authors) {
127 1 $writer->startTag('docAuthor');
128 1 $writer->dataElement('text', $author);
129 1 $writer->endTag('docAuthor');
130 }
131 }
132  
133 sub create_navmap
134 2 ▶{
Subroutine create_navmap: called CC=2 SCAR=6.9
Pod undocumented
135 2 my ($self, $writer) = @_;
136 2 $writer->startTag('navMap');
137 2 foreach my $point ($self->all_navpoints) {
138 1 $point->encode($writer);
139 }
140 2 $writer->endTag('navMap');
141 }
142  
143 sub add_navpoint
144 1 ▶{
Subroutine add_navpoint: called CC=1 SCAR=0.0
Pod documented
145 1 my ($self, @args) = @_;
146 1 my $point = EBook::EPUB::Lite::NCX::NavPoint->new(@args);
147 1 push @{$self->navpoints}, $point;
148 1 return $point;
149 }
150  
151 4 1;
152  
153 __END__
« Lite/Metadata/Item.pm ↑ Summary Lite/Manifest/Item.pm »