File Coverage

blib/lib/Text/Amuse/Compile/Devel.pm
Criterion Covered Total %
statement 36 36 100.0
branch 3 6 50.0
condition n/a
subroutine 9 9 100.0
pod 2 2 100.0
total 50 53 94.3


line stmt bran cond sub pod time code
1             package Text::Amuse::Compile::Devel;
2              
3 8     8   5294 use utf8;
  8         21  
  8         61  
4 8     8   377 use strict;
  8         16  
  8         206  
5 8     8   54 use warnings;
  8         16  
  8         538  
6 8     8   2342 use Text::Amuse::Compile::Utils qw/write_file read_file/;
  8         38  
  8         709  
7 8     8   1074 use Text::Amuse::Compile::Fonts;
  8         25  
  8         277  
8 8     8   1180 use Text::Amuse::Compile::Fonts::Selected;
  8         25  
  8         338  
9 8     8   1053 use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
  8         121980  
  8         6821  
10              
11              
12             our @ISA = qw(Exporter);
13             our @EXPORT_OK = qw/explode_epub create_font_object/;
14              
15              
16             =head1 NAME
17              
18             Text::Amuse::Compile::Utils - Common routines used for developmetn
19              
20             =head1 FUNCTIONS
21              
22             =head2 explode_epub
23              
24             Return the HTML content of an epub
25              
26             =head2 create_font_object
27              
28             Return a valid Text::Amuse::Compile::Fonts::Selected object.
29              
30             =cut
31              
32             sub explode_epub {
33 5     5 1 29493 my $epub = shift;
34 5         60 my $zip = Archive::Zip->new;
35 5 50       262 die "Couldn't read $epub" if $zip->read($epub) != AZ_OK;
36 5         30561 my $tmpdir = File::Temp->newdir(CLEANUP => 1);
37 5 50       3601 $zip->extractTree('OPS', $tmpdir->dirname) == AZ_OK
38             or die "Cannot extract $epub OPS into $tmpdir";
39 5 50       152094 opendir (my $dh, $tmpdir->dirname) or die $!;
40 5         392 my @pieces = sort grep { /\Apiece\d+\.xhtml\z/ } readdir($dh);
  80         235  
41 5         63 closedir $dh;
42 5         16 my @html;
43 5         18 foreach my $piece ('toc.ncx', 'titlepage.xhtml', @pieces) {
44 58         272 push @html, "",
45             read_file(File::Spec->catfile($tmpdir->dirname, $piece));
46             }
47 5         173 return join('', @html);
48             }
49              
50             sub create_font_object {
51 9     9 1 29193 my $fonts = Text::Amuse::Compile::Fonts->new;
52 9         578 return Text::Amuse::Compile::Fonts::Selected->new(size => 12,
53             sans => ($fonts->sans_fonts)[0],
54             main => ($fonts->serif_fonts)[0],
55             mono => ($fonts->mono_fonts)[0],
56             all_fonts => $fonts,
57             );
58             }