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

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

utf8 off url even if YAML is utf-8 decoded. Fixes #370

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