|
Revision 547
(checked in by miyagawa, 3 years ago)
|
Subscription::Config: allow empty feeds
|
- 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' => $self->can('load'), |
|---|
| 13 |
); |
|---|
| 14 |
} |
|---|
| 15 |
|
|---|
| 16 |
sub load { |
|---|
| 17 |
my($self, $context) = @_; |
|---|
| 18 |
|
|---|
| 19 |
my $feeds = $self->conf->{feed} or return; |
|---|
| 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 |
$feed->meta($config->{meta}) if $config->{meta}; |
|---|
| 31 |
|
|---|
| 32 |
if (my $tags = $config->{tag}) { |
|---|
| 33 |
unless (ref $tags) { |
|---|
| 34 |
$tags = [ Plagger::Tag->parse($config->{tag}) ]; |
|---|
| 35 |
} |
|---|
| 36 |
$feed->tags($tags); |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
$context->subscription->add($feed); |
|---|
| 40 |
} |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
1; |
|---|
| 44 |
|
|---|
| 45 |
__END__ |
|---|
| 46 |
|
|---|
| 47 |
=head1 NAME |
|---|
| 48 |
|
|---|
| 49 |
Plagger::Plugin::Subscription::Config - Subscription in config.yaml |
|---|
| 50 |
|
|---|
| 51 |
=head1 SYNOPSIS |
|---|
| 52 |
|
|---|
| 53 |
- module: Subscription::Config |
|---|
| 54 |
config: |
|---|
| 55 |
feed: |
|---|
| 56 |
- url: http://bulknews.typepad.com/blog/atom.xml |
|---|
| 57 |
- url: http://blog.bulknews.net/mt/index.rdf |
|---|
| 58 |
|
|---|
| 59 |
=head1 DESCRIPTION |
|---|
| 60 |
|
|---|
| 61 |
This plugin allows you to configure your subscription I<hardwired> in |
|---|
| 62 |
C<config.yaml>. |
|---|
| 63 |
|
|---|
| 64 |
=head1 AUTHOR |
|---|
| 65 |
|
|---|
| 66 |
Tatsuhiko Miyagawa |
|---|
| 67 |
|
|---|
| 68 |
=head1 SEE ALSO |
|---|
| 69 |
|
|---|
| 70 |
L<Plagger> |
|---|
| 71 |
|
|---|
| 72 |
=cut |
|---|