| 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__ |
|---|
| 42 |
|
|---|
| 43 |
=head1 NAME |
|---|
| 44 |
|
|---|
| 45 |
Plagger::Plugin::Notify::Eject - Notify feed updates to CD Drive |
|---|
| 46 |
|
|---|
| 47 |
=head1 SYNOPSIS |
|---|
| 48 |
|
|---|
| 49 |
- module: Notify::Eject |
|---|
| 50 |
|
|---|
| 51 |
=head1 DESCRIPTION |
|---|
| 52 |
|
|---|
| 53 |
This class ejects the CD each time a notification is triggered. |
|---|
| 54 |
|
|---|
| 55 |
This class relies on helper classes for the functionality for the |
|---|
| 56 |
particular operating system you are working on. Provided in the |
|---|
| 57 |
main Plagger distribution are helper classes for Linux, FreeBSD, |
|---|
| 58 |
Microsoft Windows (MSWin32) and Mac OS X (Darwin.) |
|---|
| 59 |
|
|---|
| 60 |
=head2 Writing helper classes |
|---|
| 61 |
|
|---|
| 62 |
This module relies on a helper class existing that is named after |
|---|
| 63 |
the architecture name returned in C<$^O>. |
|---|
| 64 |
|
|---|
| 65 |
Each module must simply subclass this module and implement the |
|---|
| 66 |
C<eject> method. For example, for the hypothetical HAL2000 system: |
|---|
| 67 |
|
|---|
| 68 |
package Plagger::Plugin::Notify::Eject::hal2000; |
|---|
| 69 |
use base qw( Plagger::Plugin::Notify::Eject ); |
|---|
| 70 |
|
|---|
| 71 |
sub eject { |
|---|
| 72 |
system("eject_the_cd_bay_doors_hal"); |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
1; |
|---|
| 76 |
|
|---|
| 77 |
=head1 AUTHOR |
|---|
| 78 |
|
|---|
| 79 |
Kazuhiro Osawa |
|---|
| 80 |
|
|---|
| 81 |
=head1 SEE ALSO |
|---|
| 82 |
|
|---|
| 83 |
L<Plagger>, L<Plagger::Plugin::Notify::Eject::linux>, L<Plagger::Plugin::Notify::Eject::freebsd>, |
|---|
| 84 |
L<Plagger::Plugin::Notify::Eject::mswin32>, L<Plagger::Plugin::Notify::Eject::darwin> |
|---|
| 85 |
|
|---|
| 86 |
=cut |
|---|