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

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

Subscription::Config: support just URL

  • 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 use Plagger::Tag;
6
7 sub register {
8     my($self, $context) = @_;
9
10     $context->register_hook(
11         $self,
12         'subscription.load' => \&load,
13     );
14 }
15
16 sub load {
17     my($self, $context) = @_;
18
19     my $feeds = $self->conf->{feed};
20        $feeds = [ $feeds ] unless ref $feeds;
21
22     for my $config (@$feeds) {
23         if (!ref($config)) {
24             $config = { url => $config };
25         }
26         my $feed = Plagger::Feed->new;
27         $feed->url($config->{url}) or $context->error("Feed URL is missing");
28         $feed->link($config->{link})   if $config->{link};
29         $feed->title($config->{title}) if $config->{title};
30
31         if (my $tags = $config->{tag}) {
32             unless (ref $tags) {
33                 $tags = [ Plagger::Tag->parse($config->{tag}) ];
34             }
35             $feed->tags($tags);
36         }
37
38         $context->subscription->add($feed);
39     }
40 }
41
42 1;
43
44 __END__
45
46 =head1 NAME
47
48 Plagger::Plugin::Subscription::Config - Subscription in config.yaml
49
50 =head1 SYNOPSIS
51
52     - module: Subscription::Config
53       config:
54         feed:
55           - url: http://bulknews.typepad.com/blog/atom.xml
56           - url: http://blog.bulknews.net/mt/index.rdf
57
58 =head1 DESCRIPTION
59
60 This plugin allows you to configure your subscription I<hardwired> in
61 C<config.yaml>.
62
63 =head1 AUTHOR
64
65 Tatsuhiko Miyagawa
66
67 =head1 SEE ALSO
68
69 L<Plagger>
70
71 =cut
Note: See TracBrowser for help on using the browser.