Plagger/Plugin/Notify/UpdatePing.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 56 CC 6 SCAR 32.6
CC
6
Cov
0%
feed
42.0
register
2.0
BEGIN
2.0
CRAP 26.0
1 package Plagger::Plugin::Notify::UpdatePing;
2 use strict;
3 use base qw( Plagger::Plugin );
4  
5 use XMLRPC::Lite;
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 my $feed = $args->{feed};
19  
20 my $urls = $self->conf->{url};
21 $urls = [ $urls ] unless ref $urls;
22  
23 my @args = (XMLRPC::Data->type(string => $feed->title), $feed->link);
24 my $method;
25 if ($self->conf->{extended_ping}) {
26 $method = 'weblogUpdates.extendedPing';
27 push @args, $feed->count ? $feed->entries->[0]->permalink : $feed->link;
28 push @args, $feed->url;
29 push @args, join("|", map XMLRPC::Data->type(string => $_), @{ $feed->tags })
30 if @{ $feed->tags };
31 } else {
32 $method = 'weblogUpdates.ping';
33 }
34  
35 for my $url (@$urls) {
36 $context->log(info => "Ping " . $feed->link . " to $url");
37 my $res = eval {
38 XMLRPC::Lite->new->proxy($url)->call($method, @args)->result;
39 };
40 if (my $err = $@ || $res->{flerror}) {
41 $context->log(error => "Error sending UpdatePing: $err");
42 }
43 }
44 }
45  
46 1;
47  
48 __END__