| 1 | package Plagger::Plugin::Publish::FOAFRoll; | ||
| 2 | use strict; | ||
| 3 | use base qw( Plagger::Plugin ); | ||
| 4 | |||
| 5 | use File::Spec; | ||
| 6 | |||
| 7 | sub init { | ||
| 8 | my $self = shift; | ||
| 9 | $self->SUPER::init(@_); | ||
| 10 | my $output = $self->conf->{filename} | ||
| 11 | or Plagger->context->error("filename is missing"); | ||
| 12 | } | ||
| 13 | |||
| 14 | sub register { | ||
| 15 | my($self, $context) = @_; | ||
| 16 | $context->register_hook( | ||
| 17 | $self, | ||
| 18 | 'publish.finalize' => \&finalize, | ||
| 19 | ); | ||
| 20 | } | ||
| 21 | |||
| 22 | sub finalize { | ||
| 23 | my($self, $context, $args) = @_; | ||
| 24 | |||
| 25 | my $out = $self->templatize('foafroll.tt', { | ||
| 26 | feeds => [ $context->subscription->feeds ], | ||
| 27 | conf => $self->conf, | ||
| 28 | }); | ||
| 29 | |||
| 30 | my $path = $self->conf->{filename}; | ||
| 31 | $context->log(info => "Writing FOAFRoll to $path"); | ||
| 32 | |||
| 33 | open my $fh, ">:utf8", $path or $context->error("$path: $!"); | ||
| 34 | print $fh $out; | ||
| 35 | close $fh; | ||
| 36 | } | ||
| 37 | |||
| 38 | 1; | ||
| 39 | |||
| 40 | __END__ |