root/trunk/plagger/lib/Plagger/Plugin/Subscription/2chThreadList.pm

Revision 1506 (checked in by miyagawa, 14 years ago)

switch XML::Feed to UserAgent->fetch_parse

Line 
1 package Plagger::Plugin::Subscription::2chThreadList;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use URI;
6 use Plagger::UserAgent;
7
8 sub register {
9     my($self, $context) = @_;
10
11     $context->register_hook(
12         $self,
13         'subscription.load' => \&load,
14     );
15 }
16
17 sub load {
18     my($self, $context) = @_;
19
20     my $threadlists = ref($self->conf->{url}) ? $self->conf->{url} : [ $self->conf->{url} ]
21         or $context->error('ThreadList url is missing');
22
23     my $agent = Plagger::UserAgent->new;
24
25     for my $threadlist (@$threadlists) {
26         my $remote = eval { $agent->fetch_parse($threadlist) }
27             or $context->error("feed parse error: $@");
28         for my $r ($remote->entries) {
29             $context->log(info => "thread: ". $r->link);
30
31             my $feed = Plagger::Feed->new;
32             $feed->url($r->link);
33             $feed->link($r->link);
34             $feed->title($r->title);
35             $context->subscription->add($feed);
36         }
37     }
38 }
39
40 1;
Note: See TracBrowser for help on using the browser.