File Coverage

blib/lib/EBook/MOBI/Driver/Example.pm
Criterion Covered Total %
statement 24 28 85.7
branch 8 10 80.0
condition n/a
subroutine 3 4 75.0
pod 2 2 100.0
total 37 44 84.0


line stmt bran cond sub pod time code
1             package EBook::MOBI::Driver::Example;
2              
3             our $VERSION = '0.71'; # TRIAL VERSION (hook for Dist::Zilla::Plugin::OurPkgVersion)
4              
5 2     2   1210 use EBook::MOBI::Converter;
  2         6  
  2         49  
6 2     2   492 use EBook::MOBI::Driver;
  2         4  
  2         657  
7              
8             our @ISA = ('EBook::MOBI::Driver');
9              
10             sub parse {
11 2     2 1 6 my ($self, $input) = @_;
12              
13             # This module can help me to translate my stuff to html understood by
14             # the mopipocket format
15 2         12 my $converter = EBook::MOBI::Converter->new();
16              
17             # Because of "KISS" the module does not do much, but return the
18             # converted stuff. So I need to manage the output myself.
19             # I'll keep everything in this variable.
20 2         4 my $mobiFormat = '';
21              
22             # We have some usefull methods from EBook::MOBI::Driver
23 2         26 $self->debug_msg("Start parsing...");
24              
25             ########################################################################
26             # Here is the parsing... for sure this looks different for any other #
27             # format. You might even use an existing parser like e.g. POD::Parser. #
28             ########################################################################
29              
30             # work on each line, including newline
31 2         13 while($input =~ /([^\n]+\n?)/g){
32 9         18 my $line = $1;
33              
34             # this converts every html special char to it's html entity.
35             # if your markups format does interfere with html special chars
36             # you should call this AFTER parsing.
37 9         24 my $mobi_line .= $converter->text($line);
38              
39 9 50       34 if ($mobi_line =~ /^!(.)!\s+(.*)/) {
40 9         14 my $cmd = $1;
41 9         17 my $txt = $2;
42              
43 9         36 $self->debug_msg('work');
44              
45 9 100       32 if ($cmd eq 'h') { $mobiFormat .= $converter->title ($txt) }
  2 100       8  
    100          
    50          
46 1         3 elsif ($cmd eq 'i') { $mobiFormat .= $converter->italic($txt)
47             . $converter->newline(); }
48 2         11 elsif ($cmd eq 'b') { $mobiFormat .= $converter->bold ($txt)
49             . $converter->newline(); }
50 4         11 elsif ($cmd eq ' ') { $mobiFormat .= $txt
51             . $converter->newline(); }
52 0         0 else { $self->debug_msg("Unknown format: $cmd") }
53             }
54             else {
55 0         0 $self->debug_msg("Unknown line: $mobi_line");
56             }
57             }
58              
59 2         7 $self->debug_msg("...done");
60              
61             # and return the complete converted text
62 2         15 return $mobiFormat;
63             }
64              
65             sub set_options {
66 0     0 1   my $self = shift;
67 0           $self->debug_msg('this plugin has no options');
68             }
69              
70             1;
71              
72             __END__