Plagger/Plugin/Subscription/Feed.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 54 CC 2 SCAR 10.6
CC
2
Cov
0%
load_feed
6.0
register
2.0
load
2.0
CRAP 2.9
1 package Plagger::Plugin::Subscription::Feed;
2 use strict;
3 use warnings;
4  
5 use base qw( Plagger::Plugin );
6 use Plagger::Util;
7 use Plagger::FeedParser;
8  
9 sub register {
10 my ( $self, $context ) = @_;
11 $context->register_hook(
12 $self,
13 'subscription.load' => \&load,
14 );
15 }
16  
17 sub load {
18 my ( $self, $context ) = @_;
19  
20 # TODO: Auto-Discovery, XML::Liberal
21 my $uri = URI->new( $self->conf->{url} )
22 or $context->error("config 'url' is missing");
23  
24 $self->load_feed( $context, $uri );
25 }
26  
27 sub load_feed {
28 my ( $self, $context, $uri ) = @_;
29  
30 my $content = Plagger::Util::load_uri($uri);
31 my $feed = eval { Plagger::FeedParser->parse(\$content) };
32  
33 unless ($feed) {
34 $context->log( error => "Error loading feed $uri: $@" );
35 return;
36 }
37  
38 for my $entry ($feed->entries) {
39 my $url = $entry->link or next;
40  
41 my $feed = Plagger::Feed->new;
42 $feed->url($url);
43  
44 $context->subscription->add($feed);
45 }
46  
47 return 1;
48 }
49  
50 1;
51  
52 =head1 NAME
53  
54 Plagger::Plugin::Subscription::Feed - Subscribe entries in a XML feed (RSS/Atom)
55  
56 =head1 SYNOPSIS
57  
58 - module: Subscription::Feed
59 config:
60 url: http://del.icio.us/rss/miyagawa/mycomments
61  
62 =head1 DESCRIPTION
63  
64 This module subscribes to entries in a XML feed.
65  
66 =head1 AUTHOR
67  
68 Tatsuhiko Miyagawa
69  
70 =head1 SEE ALSO
71  
72 L<Plagger>, L<XML::Feed>