File Coverage

blib/lib/Palm/ProjectGutenberg.pm
Criterion Covered Total %
statement 25 25 100.0
branch 1 2 50.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 32 33 96.9


line stmt bran cond sub pod time code
1             package Palm::ProjectGutenberg;
2              
3 1     1   22468 use warnings;
  1         3  
  1         37  
4 1     1   5 use strict;
  1         1  
  1         34  
5              
6 1     1   881 use Palm::Doc;
  1         9970  
  1         9  
7              
8             require Exporter;
9              
10 1     1   82 use vars qw($VERSION @EXPORT_OK @ISA);
  1         2  
  1         259  
11              
12             $VERSION = '1.02';
13             @ISA = qw(Exporter);
14             @EXPORT_OK = qw(pg2pdb);
15              
16             =head1 NAME
17              
18             Palm::ProjectGutenberg - convert PG text files to Palm Doc format
19              
20             =head1 DESCRIPTION
21              
22             This is a very simple wrapper around Palm::Doc that re-formats files
23             from Project Gutenberg so that they look better on a small screen.
24             It does this by removing line breaks apart from at paragraph breaks.
25              
26             You are unlikely to want to use this from within your own code, it
27             really ony exists for the suporting pg2pdb script to use, which is also
28             distributed and installed with this module.
29              
30             =head1 SYNOPSIS
31              
32             use Palm::ProjectGutenberg qw(pg2pdb);
33             pg2pdb($title, $infile, $outfile);
34              
35             =head1 FUNCTIONS
36              
37             There is only one function, which can be exported if you wish.
38              
39             =head2 pg2pdb
40              
41             This takes three parameters, all of them compulsory. They are, in
42             order, the e-book's title, the name of a file containing the plain-text,
43             and the name of a file to write the encoded version to.
44              
45             =head1 LIMITATIONS, BUGS and FEEDBACK
46              
47             This is subject to the limitations of Palm::Doc - eg that all documents
48             produced are compressed.
49              
50             There is no way of passing texts back and forth in variables or as
51             file handles - it's filenames or not at all. This is because it's
52             really only intended for use by the pg2pdb script. If you want that
53             extra functionality, please provide a patch with tests.
54              
55             I welcome feedback about my code, including constructive criticism.
56             Bug reports should be made using L or by email,
57             and should include the smallest possible chunk of code, along with
58             any necessary text data, which demonstrates the bug. Ideally, this
59             will be in the form of files which I can drop in to the module's
60             test suite.
61              
62             =head1 SEE ALSO
63              
64             L
65              
66             L
67              
68             =head1 AUTHOR, COPYRIGHT and LICENCE
69              
70             David Cantrell EFE
71              
72             Copyright 2009 David Cantrell Edavid@cantrell.org.ukE
73              
74             This software is free-as-in-speech software, and may be used,
75             distributed, and modified under the terms of either the GNU
76             General Public Licence version 2 or the Artistic Licence. It's
77             up to you which one you use. The full text of the licences can
78             be found in the files GPL2.txt and ARTISTIC.txt, respectively.
79              
80             =head1 CONSPIRACY
81              
82             This module is also free-as-in-mason software.
83              
84             =cut
85              
86             sub pg2pdb {
87 1     1 1 15 local $/ = undef;
88 1         3 my($title, $infile, $outfile) = @_;
89 1         10 my $pdb = Palm::Doc->new();
90 1 50       165 open(my $infh, $infile) || die("Couldn't open $infile\n");
91 1         29 my $text = <$infh>;
92 1         10 close($infh);
93 1         12 $text =~ s/\r//g; # DOS line-endings MUST DIE
94 1         40 $text =~ s/\n\n+/{PARABREAK}/g;
95 1         27 $text =~ s/\n/ /g;
96 1         14 $text =~ s/{PARABREAK}/\n\n/g;
97              
98 1         5 $pdb->text($text);
99 1         108490 $pdb->{name} = $title;
100 1         12 $pdb->Write($outfile);
101             }
102              
103             1;