Plagger/Plugin/Publish/OPML.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran n/a Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 46 CC 1 SCAR 6.9
CC
1
Cov
0%
init
2.0
register
2.0
finalize
2.0
CRAP 2.0
1 package Plagger::Plugin::Publish::OPML;
2 use strict;
3 use base qw( Plagger::Plugin );
4  
5 use Plagger::Date;
6 use File::Spec;
7  
8 sub init {
9 my $self = shift;
10 $self->SUPER::init(@_);
11 my $output = $self->conf->{filename}
12 or Plagger->context->error("filename is missing");
13 }
14  
15 sub register {
16 my($self, $context) = @_;
17 $context->register_hook(
18 $self,
19 'publish.finalize' => \&finalize,
20 );
21 }
22  
23 sub finalize {
24 my($self, $context, $args) = @_;
25  
26 my $out = $self->templatize('opml.tt', {
27 feeds => [ $context->subscription->feeds ],
28 now => Plagger::Date->now,
29 conf => $self->conf,
30 });
31  
32 my $path = $self->conf->{filename};
33 $context->log(info => "Writing OPML to $path");
34  
35 open my $fh, ">:utf8", $path or $context->error("$path: $!");
36 print $fh $out;
37 close $fh;
38 }
39  
40 1;
41  
42 __END__