| 1 | package Plagger::Plugin::Publish::PSP; | ||
| 2 | use strict; | ||
| 3 | use base qw( Plagger::Plugin ); | ||
| 4 | |||
| 5 | our $VERSION = '0.10'; | ||
| 6 | |||
| 7 | sub register { | ||
| 8 | my($self, $context) = @_; | ||
| 9 | $context->register_hook( | ||
| 10 | $self, | ||
| 11 | 'publish.feed' => \&add_feed, | ||
| 12 | 'publish.finalize' => \&finalize, | ||
| 13 | ); | ||
| 14 | } | ||
| 15 | |||
| 16 | sub add_feed { | ||
| 17 | my($self, $context, $args) = @_; | ||
| 18 | push @{ $self->{__feeds} }, $args->{feed}; | ||
| 19 | } | ||
| 20 | |||
| 21 | |||
| 22 | sub finalize { | ||
| 23 | my($self, $context) = @_; | ||
| 24 | |||
| 25 | my $body = $self->templatize('psp.tt', { feeds => $self->{__feeds} }); | ||
| 26 | my $file = $self->conf->{output_file}; | ||
| 27 | |||
| 28 | $context->log(info => "Output HTML to $file"); | ||
| 29 | open my $out, ">:utf8", $file or $context->error("$file: $!"); | ||
| 30 | print $out $body; | ||
| 31 | close $out; | ||
| 32 | } | ||
| 33 | |||
| 34 | 1; | ||
| 35 |