blib/lib/EPublisher/Target/Plugin/Mobi.pm

filter: Statementstmt 34.6% 18 / 52 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 25.5% 24 / 94 CC 14 SCAR 50.4
CC
14
Cov
23%
deploy
210.0
BEGIN
1.0
BEGIN
1.0
CRAP 155.0
↑ Summary
1 package EPublisher::Target::Plugin::Mobi;
2  
3 # ABSTRACT: Use Mobi format as a target for EPublisher
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use EBook::MOBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use EPublisher::Target::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our @ISA = qw(EPublisher::Target::Base);
13  
14 1 our $VERSION = 0.6;
15  
16 0 ▶sub deploy {
Subroutine deploy: not called CC=14 SCAR=53.5
Pod documented
17 0 my ($self) = @_;
18
19 0 ▶ my $pods = $self->_config->{source} || [];
Condition0%0/2
$self->_config->{'source'} || []
l!l
00
MC/DC0%0/1
$self->_config->{'source'} || []
$self->_config->{'source'}
Truth table0%0/2
A
A= $self->_config->{'source'}
Aresult
11
00
20  
21 0 ▶ my $author = $self->_config->{author} || 'Perl Author';
Condition0%0/2
$self->_config->{'author'} || 'Perl Author'
l!l
00
MC/DC0%0/1
$self->_config->{'author'} || 'Perl Author'
$self->_config->{'author'}
Truth table0%0/2
A
A= $self->_config->{'author'}
Aresult
11
00
22 0 ▶ my $title = $self->_config->{title} || 'Pod Document';
Condition0%0/2
$self->_config->{'title'} || 'Pod Document'
l!l
00
MC/DC0%0/1
$self->_config->{'title'} || 'Pod Document'
$self->_config->{'title'}
Truth table0%0/2
A
A= $self->_config->{'title'}
Aresult
11
00
23 0 ▶ my $language = $self->_config->{lang} || 'en';
Condition0%0/2
$self->_config->{'lang'} || 'en'
l!l
00
MC/DC0%0/1
$self->_config->{'lang'} || 'en'
$self->_config->{'lang'}
Truth table0%0/2
A
A= $self->_config->{'lang'}
Aresult
11
00
24 0 ▶ my $out_filename = $self->_config->{output} || '';
Condition0%0/2
$self->_config->{'output'} || ''
l!l
00
MC/DC0%0/1
$self->_config->{'output'} || ''
$self->_config->{'output'}
Truth table0%0/2
A
A= $self->_config->{'output'}
Aresult
11
00
25 0 ▶ my $encoding = $self->_config->{encoding} || ':encoding(UTF-8)';
Condition0%0/2
$self->_config->{'encoding'} || ':encoding(UTF-8)'
l!l
00
MC/DC0%0/1
$self->_config->{'encoding'} || ':encoding(UTF-8)'
$self->_config->{'encoding'}
Truth table0%0/2
A
A= $self->_config->{'encoding'}
Aresult
11
00
26 0 ▶ my $imgcover = $self->_config->{cover} || '';
Condition0%0/2
$self->_config->{'cover'} || ''
l!l
00
MC/DC0%0/1
$self->_config->{'cover'} || ''
$self->_config->{'cover'}
Truth table0%0/2
A
A= $self->_config->{'cover'}
Aresult
11
00
27 0 ▶ my $htmcover = $self->_config->{htmcover} || '';
Condition0%0/2
$self->_config->{'htmcover'} || ''
l!l
00
MC/DC0%0/1
$self->_config->{'htmcover'} || ''
$self->_config->{'htmcover'}
Truth table0%0/2
A
A= $self->_config->{'htmcover'}
Aresult
11
00
28  
29 0 ▶ if ( !$out_filename ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($out_filename) 0 0 0
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 ▶ if ($imgcover and -e $imgcover) {
Branch: 1 branch
BranchTrueFalseTotal
if ($imgcover and -e $imgcover) 0 0 0
Condition0%0/3
$imgcover and -e $imgcover
!ll&&!rl&&r
000
MC/DC0%0/2
$imgcover and -e $imgcover
$imgcover -e $imgcover
Truth table0%0/3
A and B
A= $imgcoverB= -e $imgcover
ABresult
0X0
100
111
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 ▶ if ($htmcover) {
Branch: 1 branch
BranchTrueFalseTotal
if ($htmcover) 0 0 0
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}) {
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 1;
94  
95  
96 __END__
↑ Summary