Plagger/Plugin/Subscription/XPath.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran n/a Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 60 CC 1 SCAR 6.9
CC
1
Cov
0%
register
2.0
load
2.0
find_feed
2.0
CRAP 2.0
1 package Plagger::Plugin::Subscription::XPath;
2 use strict;
3 use base qw( Plagger::Plugin );
4  
5 use HTML::TreeBuilder::XPath;
6 use Plagger::Util;
7 use URI;
8  
9 sub register {
10 my($self, $context) = @_;
11  
12 $context->register_hook(
13 $self,
14 'subscription.load' => $self->can('load'),
15 );
16 }
17  
18 sub load {
19 my($self, $context) = @_;
20 my $uri = URI->new($self->conf->{url})
21 or $context->error("config 'url' is missing");
22  
23 my $xhtml = Plagger::Util::load_uri($uri, $self);
24 my $tree = HTML::TreeBuilder::XPath->new;
25 $tree->parse($xhtml);
26 $tree->eof;
27  
28 $self->find_feed($tree, $uri);
29 }
30  
31 sub find_feed {
32 my($self, $tree, $uri) = @_;
33 for my $child ($tree->findnodes($self->conf->{xpath} || '//a')) {
34 my $href = $child->attr('href') or next;
35 my $title = $child->attr('title') || $child->as_text;
36  
37 my $feed = Plagger::Feed->new;
38 $feed->url( URI->new_abs($href, $uri) );
39 $feed->title($title);
40  
41 Plagger->context->subscription->add($feed);
42 }
43 }
44  
45 1;
46  
47 __END__