Plagger/Plugin/Publish/PowerPoint.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 69 CC 2 SCAR 10.6
CC
2
Cov
0%
connect_powerpoint
6.0
register
2.0
publish_presentation
2.0
CRAP 2.9
1 package Plagger::Plugin::Publish::PowerPoint;
2  
3 use strict;
4 use base qw( Plagger::Plugin );
5  
6 use Win32::PowerPoint;
7 use Encode;
8 use File::Path;
9  
10 sub register {
11 my($self, $context) = @_;
12 $context->register_hook(
13 $self,
14 'publish.feed' => \&publish_presentation,
15 'publish.init' => \&connect_powerpoint,
16 );
17 }
18  
19 sub publish_presentation {
20 my ($self, $context, $args) = @_;
21  
22 my $feed = $args->{feed};
23  
24 $self->{powerpoint}->new_presentation;
25  
26 foreach my $entry ($feed->entries) {
27  
28 my $title_text = $entry->title_text;
29 my $body_text = $entry->body_text;
30  
31 $title_text =~ s/^\s+//mg;
32 $body_text =~ s/^\s+//mg;
33  
34 $self->{powerpoint}->new_slide;
35 $self->{powerpoint}->add_text(
36 encode('shift_jis',$title_text),
37 { size => 30, bold => 1, height => 50, link => $entry->permalink },
38 );
39 $self->{powerpoint}->add_text(
40 encode('shift_jis',$body_text),
41 { size => 20 },
42 );
43 }
44  
45 # generate file path;
46 my $file = File::Spec->catfile(
47 $self->conf->{dir}, Plagger::Util::filename_for($feed, $self->conf->{filename} || '%i.pps'),
48 );
49  
50 $context->log(info => "save feed for " . $feed->link . " to $file");
51  
52 $self->{powerpoint}->save_presentation($file);
53 $self->{powerpoint}->close_presentation;
54 }
55  
56 sub connect_powerpoint {
57 my ($self, $context, $args) = @_;
58  
59 my $dir = $self->conf->{dir} || '.';
60 unless (-e $dir && -d _) {
61 $context->log(debug => "make dir");
62 mkpath($dir, 0755) or $context->error("mkdir $dir: $!");
63 }
64  
65 $context->log(debug => "hello, PowerPoint");
66 $self->{powerpoint} = Win32::PowerPoint->new;
67 }
68  
69 1;
70  
71 __END__