Plagger/Plugin/Publish/PDF.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 55 CC 2 SCAR 11.0
CC
2
Cov
0%
feed
6.0
register
2.0
BEGIN
2.0
CRAP 3.0
1 package Plagger::Plugin::Publish::PDF;
2 use strict;
3 use base qw( Plagger::Plugin );
4  
5 use File::Spec;
6 use PDF::FromHTML;
7 use Plagger::Util;
8  
9 sub register {
10 my($self, $context) = @_;
11 $context->register_hook(
12 $self,
13 'publish.feed' => \&feed,
14 );
15 }
16  
17 sub feed {
18 my($self, $context, $args) = @_;
19  
20 my $dir = $self->conf->{dir};
21 unless (-e $dir && -d _) {
22 mkdir $dir, 0755 or $context->error("mkdir $dir: $!");
23 }
24  
25 my $file = Plagger::Util::filename_for($args->{feed}, $self->conf->{filename} || '%i.pdf');
26 my $path = File::Spec->catfile($dir, $file);
27 my $body = $self->templatize('html.tt', $args);
28 utf8::encode($body);
29  
30 $context->log(info => "Writing PDF to $path");
31  
32 my $pdf = PDF::FromHTML->new;
33 $pdf->load_file(\$body);
34 $pdf->convert();
35 $pdf->write_file($path);
36 }
37  
38 1;
39  
40 __END__