| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright (c) 2009, 2010 Oleksandr Tymoshenko |
|
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
|
|
|
4
|
|
14
|
use Moo; |
|
|
4
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
23
|
|
|
26
|
4
|
|
|
4
|
|
974
|
use Types::Standard qw/ArrayRef Object Str/; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
41
|
|
|
27
|
4
|
|
|
4
|
|
4008
|
use EBook::EPUB::Lite::NCX::NavPoint; |
|
|
4
|
|
|
|
|
11
|
|
|
|
4
|
|
|
|
|
2047
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Very simplified module for generation NCX |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has uid => ( isa => Str, is => 'rw' ); |
|
32
|
|
|
|
|
|
|
has title => ( isa => Str, is => 'rw' ); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has navpoints => ( |
|
35
|
|
|
|
|
|
|
is => 'ro', |
|
36
|
|
|
|
|
|
|
isa => ArrayRef[Object], |
|
37
|
|
|
|
|
|
|
default => sub { [] }, |
|
38
|
|
|
|
|
|
|
); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub all_navpoints { |
|
41
|
2
|
|
|
2
|
1
|
3
|
return @{ shift->navpoints}; |
|
|
2
|
|
|
|
|
15
|
|
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has authors => ( |
|
47
|
|
|
|
|
|
|
is => 'ro', |
|
48
|
|
|
|
|
|
|
isa => ArrayRef[Str], |
|
49
|
|
|
|
|
|
|
default => sub { [] }, |
|
50
|
|
|
|
|
|
|
); |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub all_authors { |
|
53
|
2
|
|
|
2
|
0
|
5
|
return @{ shift->authors }; |
|
|
2
|
|
|
|
|
17
|
|
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub add_author { |
|
57
|
1
|
|
|
1
|
1
|
3
|
my ($self, @args) = @_; |
|
58
|
1
|
|
|
|
|
2
|
push @{ shift->authors }, @args; |
|
|
1
|
|
|
|
|
7
|
|
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub to_xml |
|
62
|
|
|
|
|
|
|
{ |
|
63
|
2
|
|
|
2
|
1
|
3
|
my ($self) = @_; |
|
64
|
2
|
|
|
|
|
3
|
my $xml; |
|
65
|
2
|
|
|
|
|
22
|
my $writer = XML::Writer->new( |
|
66
|
|
|
|
|
|
|
OUTPUT => \$xml, |
|
67
|
|
|
|
|
|
|
DATA_MODE => 1, |
|
68
|
|
|
|
|
|
|
DATA_INDENT => 2, |
|
69
|
|
|
|
|
|
|
); |
|
70
|
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
467
|
$writer->xmlDecl('utf-8'); |
|
72
|
2
|
|
|
|
|
143
|
$writer->doctype('ncx', '-//NISO//DTD ncx 2005-1//EN', |
|
73
|
|
|
|
|
|
|
'http://www.daisy.org/z3986/2005/ncx-2005-1.dtd'); |
|
74
|
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
67
|
$writer->startTag('ncx', |
|
76
|
|
|
|
|
|
|
version => '2005-1', |
|
77
|
|
|
|
|
|
|
xmlns => 'http://www.daisy.org/z3986/2005/ncx/', |
|
78
|
|
|
|
|
|
|
); |
|
79
|
|
|
|
|
|
|
# .. |
|
80
|
2
|
|
|
|
|
224
|
$self->create_head_element($writer); |
|
81
|
|
|
|
|
|
|
# Now document data |
|
82
|
2
|
|
|
|
|
67
|
$self->create_doc_data($writer); |
|
83
|
2
|
|
|
|
|
31
|
$self->create_navmap($writer); |
|
84
|
|
|
|
|
|
|
|
|
85
|
2
|
|
|
|
|
41
|
$writer->endTag('ncx'); |
|
86
|
2
|
|
|
|
|
45
|
$writer->end(); |
|
87
|
|
|
|
|
|
|
|
|
88
|
2
|
|
|
|
|
334
|
return $xml; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub create_head_element |
|
92
|
|
|
|
|
|
|
{ |
|
93
|
2
|
|
|
2
|
0
|
5
|
my ($self, $writer) = @_; |
|
94
|
2
|
|
|
|
|
7
|
$writer->startTag('head'); |
|
95
|
2
|
|
|
|
|
126
|
$writer->emptyTag('meta', |
|
96
|
|
|
|
|
|
|
name => 'dtb:uid', |
|
97
|
|
|
|
|
|
|
content => $self->uid, |
|
98
|
|
|
|
|
|
|
); |
|
99
|
|
|
|
|
|
|
|
|
100
|
2
|
|
|
|
|
184
|
$writer->emptyTag('meta', |
|
101
|
|
|
|
|
|
|
name => 'dtb:depth', |
|
102
|
|
|
|
|
|
|
content => '1', |
|
103
|
|
|
|
|
|
|
); |
|
104
|
|
|
|
|
|
|
|
|
105
|
2
|
|
|
|
|
127
|
$writer->emptyTag('meta', |
|
106
|
|
|
|
|
|
|
name => 'dtb:totalPageCount', |
|
107
|
|
|
|
|
|
|
content => '0', |
|
108
|
|
|
|
|
|
|
); |
|
109
|
|
|
|
|
|
|
|
|
110
|
2
|
|
|
|
|
124
|
$writer->emptyTag('meta', |
|
111
|
|
|
|
|
|
|
name => 'dtb:maxPageNumber', |
|
112
|
|
|
|
|
|
|
content => '0', |
|
113
|
|
|
|
|
|
|
); |
|
114
|
|
|
|
|
|
|
|
|
115
|
2
|
|
|
|
|
131
|
$writer->endTag('head'); |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub create_doc_data |
|
119
|
|
|
|
|
|
|
{ |
|
120
|
2
|
|
|
2
|
0
|
4
|
my ($self, $writer) = @_; |
|
121
|
|
|
|
|
|
|
|
|
122
|
2
|
|
|
|
|
8
|
$writer->startTag('docTitle'); |
|
123
|
2
|
|
|
|
|
108
|
$writer->dataElement('text', $self->title); |
|
124
|
2
|
|
|
|
|
663
|
$writer->endTag('docTitle'); |
|
125
|
|
|
|
|
|
|
|
|
126
|
2
|
|
|
|
|
173
|
foreach my $author ($self->all_authors) { |
|
127
|
1
|
|
|
|
|
5
|
$writer->startTag('docAuthor'); |
|
128
|
1
|
|
|
|
|
48
|
$writer->dataElement('text', $author); |
|
129
|
1
|
|
|
|
|
80
|
$writer->endTag('docAuthor'); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub create_navmap |
|
134
|
|
|
|
|
|
|
{ |
|
135
|
2
|
|
|
2
|
0
|
4
|
my ($self, $writer) = @_; |
|
136
|
2
|
|
|
|
|
8
|
$writer->startTag('navMap'); |
|
137
|
2
|
|
|
|
|
75
|
foreach my $point ($self->all_navpoints) { |
|
138
|
1
|
|
|
|
|
7
|
$point->encode($writer); |
|
139
|
|
|
|
|
|
|
} |
|
140
|
2
|
|
|
|
|
35
|
$writer->endTag('navMap'); |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub add_navpoint |
|
144
|
|
|
|
|
|
|
{ |
|
145
|
1
|
|
|
1
|
1
|
658
|
my ($self, @args) = @_; |
|
146
|
1
|
|
|
|
|
9
|
my $point = EBook::EPUB::Lite::NCX::NavPoint->new(@args); |
|
147
|
1
|
|
|
|
|
28
|
push @{$self->navpoints}, $point; |
|
|
1
|
|
|
|
|
6
|
|
|
148
|
1
|
|
|
|
|
4
|
return $point; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1; |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
__END__ |