Plagger/Plugin/Publish/Pipe.pm untested

filter: Statementstmt 0.0% 0 / 22 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 41 CC 2 SCAR 11.5
CC
2
Cov
0%
convert
6.0
register
2.0
feed
2.0
CRAP 3.1
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: $!"); ## no critic
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__