root/trunk/plagger/lib/Plagger/Plugin/Notify/Command.pm

Revision 1659 (checked in by miyagawa, 14 years ago)

added new generic plugin Notify::Command

Line 
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__
41
42 =head1 NAME
43
44 Plagger::Plugin::Notify::Command - Execute arbitrary command or script when you have an updated feed
45
46 =head1 SYNOPSIS
47
48   - module: Notify::Command
49     config:
50       command: /path/to/script
51
52 =head1 DESCRIPTION
53
54 This plugin executes arbitrary command using Perl system() function,
55 when you have an updated feed. Specified command is executed only once
56 when your entire subscription has an updated feed.
57
58 =head1 CONFIG
59
60 =over 4
61
62 =item command
63
64   command: echo "Hello World"
65
66 Specify the path of command (and arguments to the command) to
67 execute. The command is executed using Perl's I<system> function, so
68 it would use shell.
69
70 =back
71
72 =head1 AUTHOR
73
74 Tatsuhiko Miyagawa
75
76 =head1 SEE ALSO
77
78 L<Plagger>
79
80 =cut
Note: See TracBrowser for help on using the browser.