Plagger/Plugin/Filter/LivedoorClipUsersCount.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 35 CC 3 SCAR 18.4
CC
3
Cov
0%
update
12.0
register
2.0
BEGIN
2.0
CRAP 6.3
1 package Plagger::Plugin::Filter::LivedoorClipUsersCount;
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 'update.feed.fixup' => \&update,
12 );
13 }
14  
15 sub update {
16 my ( $self, $context, $args ) = @_;
17  
18 my @permalink = map $_->permalink, $args->{feed}->entries;
19  
20 $context->log( info => 'Requesting XMLRPC call to livedoorClip with '
21 . scalar(@permalink)
22 . ' link(s)' );
23  
24 my $map = XMLRPC::Lite
25 ->proxy('http://rpc.clip.livedoor.com/count')
26 ->call( 'clip.getCount', @permalink )
27 ->result;
28  
29 unless ($map) {
30 $context->log( warn => 'livedoorClip XMLRPC failed' );
31 return;
32 }
33  
34 $context->log( info => 'XMLRPC request success.' );
35  
36 for my $entry ( $args->{feed}->entries ) {
37 if ( defined( my $count = $map->{ $entry->permalink } ) ) {
38 $entry->meta->{livedoorclip_users} = $count;
39 }
40 }
41 }
42  
43 1;
44 __END__