line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package EPublisher::Target::Plugin::Mobi; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Use Mobi format as a target for EPublisher |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1150
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1370
|
use File::Temp; |
|
1
|
|
|
|
|
28451
|
|
|
1
|
|
|
|
|
106
|
|
9
|
1
|
|
|
1
|
|
1123
|
use EBook::MOBI; |
|
1
|
|
|
|
|
157541
|
|
|
1
|
|
|
|
|
53
|
|
10
|
1
|
|
|
1
|
|
1147
|
use EPublisher::Target::Base; |
|
1
|
|
|
|
|
361
|
|
|
1
|
|
|
|
|
486
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(EPublisher::Target::Base); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = 0.6; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub deploy { |
17
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
0
|
|
|
|
my $pods = $self->_config->{source} || []; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
0
|
|
|
|
my $author = $self->_config->{author} || 'Perl Author'; |
22
|
0
|
|
0
|
|
|
|
my $title = $self->_config->{title} || 'Pod Document'; |
23
|
0
|
|
0
|
|
|
|
my $language = $self->_config->{lang} || 'en'; |
24
|
0
|
|
0
|
|
|
|
my $out_filename = $self->_config->{output} || ''; |
25
|
0
|
|
0
|
|
|
|
my $encoding = $self->_config->{encoding} || ':encoding(UTF-8)'; |
26
|
0
|
|
0
|
|
|
|
my $imgcover = $self->_config->{cover} || ''; |
27
|
0
|
|
0
|
|
|
|
my $htmcover = $self->_config->{htmcover} || ''; |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
if ( !$out_filename ) { |
30
|
0
|
|
|
|
|
|
my $fh = File::Temp->new; |
31
|
0
|
|
|
|
|
|
$out_filename = $fh->filename; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Create an object of a book |
35
|
0
|
|
|
|
|
|
my $book = EBook::MOBI->new(); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# give some meta information about this book |
38
|
0
|
|
|
|
|
|
$book->set_filename($out_filename); |
39
|
0
|
|
|
|
|
|
$book->set_title ($title); |
40
|
0
|
|
|
|
|
|
$book->set_author ($author); |
41
|
0
|
|
|
|
|
|
$book->set_encoding($encoding); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# create title page from an image, if set |
44
|
0
|
0
|
0
|
|
|
|
if ($imgcover and -e $imgcover) { |
45
|
0
|
|
|
|
|
|
$book->add_content( data => "\n=image $imgcover\n\n", |
46
|
|
|
|
|
|
|
driver => 'EBook::MOBI::Driver::POD', |
47
|
|
|
|
|
|
|
); |
48
|
0
|
|
|
|
|
|
$book->add_pagebreak(); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
# create title page from mhtml, if set |
51
|
0
|
0
|
|
|
|
|
if ($htmcover) { |
52
|
0
|
|
|
|
|
|
$book->add_mhtml_content($htmcover); |
53
|
0
|
|
|
|
|
|
$book->add_pagebreak(); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# insert a table of contents after the titlepage |
57
|
0
|
|
|
|
|
|
$book->add_toc_once(); |
58
|
0
|
|
|
|
|
|
$book->add_pagebreak(); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# insert content of the book |
61
|
0
|
|
|
|
|
|
for my $data (@{$pods}) { |
|
0
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $chap = $data->{title}; |
64
|
0
|
|
|
|
|
|
my $pod = $data->{pod}; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$book->add_content( data => "\n=head1 $chap\n\n", |
67
|
|
|
|
|
|
|
driver => 'EBook::MOBI::Driver::POD', |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
# add the books text, which is e.g. in the POD format |
70
|
0
|
|
|
|
|
|
$book->add_content( data => $pod, |
71
|
|
|
|
|
|
|
driver => 'EBook::MOBI::Driver::POD', |
72
|
|
|
|
|
|
|
driver_options => { |
73
|
|
|
|
|
|
|
pagemode => 1, |
74
|
|
|
|
|
|
|
head0_mode => 1, |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# prepare the book (e.g. calculate the references for the TOC) |
80
|
0
|
|
|
|
|
|
$book->make(); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# let me see how this mobi-html looks like |
83
|
|
|
|
|
|
|
#$book->print_mhtml(); |
84
|
|
|
|
|
|
|
# TODO: should only print in DEBUG-MODE |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# ok, give me that mobi-book as a file! |
87
|
0
|
|
|
|
|
|
$book->save(); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return $out_filename; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |