| 1 | package Plagger::Plugin::Notify::Eject; | ||
| 2 | use strict; | ||
| 3 | use base qw( Plagger::Plugin ); | ||
| 4 | |||
| 5 | sub init { | ||
| 6 | my $self = shift; | ||
| 7 | $self->SUPER::init(@_); | ||
| 8 | |||
| 9 | my $class = 'Plagger::Plugin::Notify::Eject::' . lc($^O); | ||
| 10 | eval "require $class;"; | ||
| 11 | if ($@) { | ||
| 12 | Plagger->context->error("Eject plugin doesn't run on your platform $^O"); | ||
| 13 | } | ||
| 14 | bless $self, $class; | ||
| 15 | } | ||
| 16 | |||
| 17 | sub register { | ||
| 18 | my($self, $context) = @_; | ||
| 19 | $context->register_hook( | ||
| 20 | $self, | ||
| 21 | 'publish.feed' => \&update, | ||
| 22 | 'publish.finalize' => \&finalize, | ||
| 23 | ); | ||
| 24 | $self->{count} = 0; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub update { | ||
| 28 | my($self, $context, $args) = @_; | ||
| 29 | $self->{count}++ if $args->{feed}->count; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub finalize { | ||
| 33 | my($self, $context, $args) = @_; | ||
| 34 | $self->eject if $self->{count}; | ||
| 35 | } | ||
| 36 | |||
| 37 | sub eject { $_[1]->log(warn => 'Subclass should override this') } | ||
| 38 | |||
| 39 | 1; | ||
| 40 | |||
| 41 | __END__ |