Plagger/Plugin/Widget/BloglinesSubscription.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 48 CC 2 SCAR 10.6
CC
2
Cov
0%
add
6.0
register
2.0
new
2.0
CRAP 2.9
1 package Plagger::Plugin::Widget::BloglinesSubscription;
2 use strict;
3 use base qw( Plagger::Plugin );
4  
5 use HTML::Entities;
6 use URI;
7  
8 sub register {
9 my($self, $context) = @_;
10 $context->register_hook(
11 $self,
12 'publish.entry.fixup' => \&add,
13 );
14 }
15  
16 sub add {
17 my($self, $context, $args) = @_;
18  
19 my $feed = $args->{entry}->source || $args->{feed};
20 unless (exists $feed->meta->{bloglines_subid}) {
21 $context->log(warn => "bloglines_subid not found. Skip");
22 return;
23 }
24  
25 # create another Widget class to use feed info
26 my $widget = Plagger::Plugin::Widget::BloglinesSubscription::Widget->new;
27 $widget->{feed} = $feed;
28  
29 $args->{entry}->add_widget($widget);
30 }
31  
32 package Plagger::Plugin::Widget::BloglinesSubscription::Widget;
33  
34 sub new { bless {}, shift }
35  
36 sub html {
37 my($self, $entry) = @_;
38 my $uri = URI->new('http://www.bloglines.com/modsub');
39  
40 $uri->query_form(subid => $self->{feed}->meta->{bloglines_subid});
41  
42 my $url = HTML::Entities::encode($uri->as_string);
43 return qq(<a href="$url"><img src="http://www.bloglines.com/images/favicon.gif" alt="Edit Bloglines Subscription" style="border:0;vertical-align:middle" /></a>);
44 }
45  
46 1;
47  
48 __END__