Plagger/Plugin/Filter/HatenaBookmarkUsersCount.pm untested

filter: Statementstmt 0.0% 0 / 26 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 / 37 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::HatenaBookmarkUsersCount;
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 while (my @links = splice(@permalink, 0, 50)) {
21 $context->log(info => 'Requesting XMLRPC call to Hatena Bookmark with ' . scalar(@links) . ' link(s)');
22  
23 my $map = XMLRPC::Lite
24 ->proxy('http://b.hatena.ne.jp/xmlrpc')
25 ->call('bookmark.getCount', @links)
26 ->result;
27  
28 unless ($map) {
29 $context->log(warn => 'Hatena Bookmark XMLRPC failed');
30 return;
31 }
32  
33 $context->log(info => 'XMLRPC request success.');
34  
35 for my $entry ($args->{feed}->entries) {
36 if (defined(my $count = $map->{$entry->permalink})) {
37 $entry->meta->{hatenabookmark_users} = $count;
38 }
39 }
40 }
41 }
42  
43 1;
44  
45 __END__