| 1 | package Plagger::Plugin::Notify::Command; | ||
| 2 | use strict; | ||
| 3 | use base qw( Plagger::Plugin ); | ||
| 4 | |||
| 5 | sub register { | ||
| 6 | my($self, $context) = @_; | ||
| 7 | $context->register_hook( | ||
| 8 | $self, | ||
| 9 | 'publish.feed' => \&update, | ||
| 10 | 'publish.finalize' => \&finalize, | ||
| 11 | 'plugin.init' => \&plugin_init, | ||
| 12 | ); | ||
| 13 | } | ||
| 14 | |||
| 15 | sub plugin_init { | ||
| 16 | my($self, $context, $args) = @_; | ||
| 17 | |||
| 18 | unless (exists $self->conf->{command}) { | ||
| 19 | $context->error("'command' config is missing"); | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | sub update { | ||
| 24 | my($self, $context, $args) = @_; | ||
| 25 | $self->{count}++ if $args->{feed}->count; | ||
| 26 | } | ||
| 27 | |||
| 28 | sub finalize { | ||
| 29 | my($self, $context, $args) = @_; | ||
| 30 | $self->do_command if $self->{count}; | ||
| 31 | } | ||
| 32 | |||
| 33 | sub do_command { | ||
| 34 | my $self = shift; | ||
| 35 | my $command = $self->conf->{command}; | ||
| 36 | system($command); | ||
| 37 | } | ||
| 38 | |||
| 39 | 1; | ||
| 40 | __END__ |