line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package EBook::MOBI::Driver::Example; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.72'; # TRIAL VERSION (hook for Dist::Zilla::Plugin::OurPkgVersion) |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
1316
|
use EBook::MOBI::Converter; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
56
|
|
6
|
2
|
|
|
2
|
|
500
|
use EBook::MOBI::Driver; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
663
|
|
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
|
|
|
|
|
10
|
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
|
|
|
|
|
5
|
my $mobiFormat = ''; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# We have some usefull methods from EBook::MOBI::Driver |
23
|
2
|
|
|
|
|
11
|
$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
|
|
|
|
|
14
|
while($input =~ /([^\n]+\n?)/g){ |
32
|
9
|
|
|
|
|
17
|
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
|
|
|
|
|
28
|
my $mobi_line .= $converter->text($line); |
38
|
|
|
|
|
|
|
|
39
|
9
|
50
|
|
|
|
37
|
if ($mobi_line =~ /^!(.)!\s+(.*)/) { |
40
|
9
|
|
|
|
|
17
|
my $cmd = $1; |
41
|
9
|
|
|
|
|
14
|
my $txt = $2; |
42
|
|
|
|
|
|
|
|
43
|
9
|
|
|
|
|
40
|
$self->debug_msg('work'); |
44
|
|
|
|
|
|
|
|
45
|
9
|
100
|
|
|
|
34
|
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
|
|
|
|
|
14
|
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
|
|
|
|
|
6
|
$self->debug_msg("...done"); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# and return the complete converted text |
62
|
2
|
|
|
|
|
17
|
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__ |