root/trunk/plagger/lib/Plagger/Plugin/Subscription/Config.pm

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

Added Subscription::Config to put feed URLs in config file

  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Plugin::Subscription::Config;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 sub register {
6     my($self, $context) = @_;
7
8     $context->register_hook(
9         $self,
10         'subscription.load' => \&load,
11     );
12 }
13
14 sub load {
15     my($self, $context) = @_;
16
17     my $feeds = $self->conf->{feed};
18        $feeds = [ $feeds ] unless ref $feeds;
19
20     for my $config (@$feeds) {
21         my $feed = Plagger::Feed->new;
22         $feed->url($config->{url}) or $context->error("Feed URL is missing");
23         $feed->link($config->{link})   if $config->{link};
24         $feed->title($config->{title}) if $config->{title};
25
26         if ($config->{tags}) {
27             require Text::Tags::Parser;
28             my @tags = Text::Tags::Parser->new->parse_tags($config->{tags});
29             $feed->tags(\@tags);
30         }
31
32         $context->subscription->add($feed);
33     }
34 }
35
36 1;
Note: See TracBrowser for help on using the browser.