|
Revision 1588
(checked in by miyagawa, 2 years ago)
|
- Added Test::Perl::Critic test and t/perlcriticrc policy file
- Fixed 2 args open() to comfort with PBP
- Added ## no critic to express "I know what I'm doing"
|
| Line | |
|---|
| 1 |
package Plagger::Plugin::Publish::Pipe; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use base qw( Plagger::Plugin ); |
|---|
| 4 |
|
|---|
| 5 |
use Encode; |
|---|
| 6 |
|
|---|
| 7 |
sub register { |
|---|
| 8 |
my($self, $context) = @_; |
|---|
| 9 |
$context->register_hook( |
|---|
| 10 |
$self, |
|---|
| 11 |
'publish.feed' => \&feed, |
|---|
| 12 |
); |
|---|
| 13 |
} |
|---|
| 14 |
|
|---|
| 15 |
sub feed { |
|---|
| 16 |
my($self, $context, $args) = @_; |
|---|
| 17 |
|
|---|
| 18 |
open my $out, "|" . $self->conf->{command} or $context->error("Can't open pipe: $!"); |
|---|
| 19 |
$context->log(info => "Publishing to " . $self->conf->{command}); |
|---|
| 20 |
for my $entry ($args->{feed}->entries) { |
|---|
| 21 |
print $out $self->convert($entry->title) . "\n"; |
|---|
| 22 |
print $out $self->convert($entry->permalink) . "\n\n"; |
|---|
| 23 |
} |
|---|
| 24 |
close $out; |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
sub convert { |
|---|
| 28 |
my ($self, $str) = @_; |
|---|
| 29 |
utf8::decode($str) unless utf8::is_utf8($str); |
|---|
| 30 |
return encode($self->conf->{encoding} || 'utf8', $str); |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
1; |
|---|
| 34 |
|
|---|
| 35 |
__END__ |
|---|
| 36 |
|
|---|
| 37 |
=head1 NAME |
|---|
| 38 |
|
|---|
| 39 |
Plagger::Plugin::Publish::Pipe - Publish to other program |
|---|
| 40 |
|
|---|
| 41 |
=head1 SYNOPSIS |
|---|
| 42 |
|
|---|
| 43 |
- module: Publish::Pipe |
|---|
| 44 |
config: |
|---|
| 45 |
command: /usr/bin/mail youpy |
|---|
| 46 |
# command: /usr/bin/lpr |
|---|
| 47 |
# command: /usr/bin/fax |
|---|
| 48 |
# (for OSX user) command: /usr/bin/say |
|---|
| 49 |
encoding: iso-2022-jp |
|---|
| 50 |
|
|---|
| 51 |
=head1 DESCRIPTION |
|---|
| 52 |
|
|---|
| 53 |
This plugin publish feed updates to other program using a pipe. |
|---|
| 54 |
|
|---|
| 55 |
=head1 EXAMPLE |
|---|
| 56 |
|
|---|
| 57 |
L<http://subtech.g.hatena.ne.jp/youpy/20060301/p2> |
|---|
| 58 |
|
|---|
| 59 |
=head1 AUTHOR |
|---|
| 60 |
|
|---|
| 61 |
id:youpy |
|---|
| 62 |
|
|---|
| 63 |
=head1 SEE ALSO |
|---|
| 64 |
|
|---|
| 65 |
L<Plagger> |
|---|
| 66 |
|
|---|
| 67 |
=cut |
|---|