root/trunk/plagger/lib/Plagger/Plugin/CustomFeed/Debug.pm

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

Reorganized CustomFeed? API:

  • Added RSS/Atom auto-discovery in Aggregator::Simple. Fixes #20
  • Fixes CustomFeed? bugs with multiple instances. Fixes #56
  • Fixes Aggregator::Simple bug it ignores title in Config. Fixes #110.
  • Automatically loads Aggregator::Simple where no Aggregator is installed. Refs #125
  • Warns if no aggregator corresponds with the feed. Fixes #125
  • Added $context->is_loaded($plugin). Fixes #132
Line 
1 package Plagger::Plugin::CustomFeed::Debug;
2 use strict;
3 use warnings;
4 use base qw (Plagger::Plugin);
5
6 our $VERSION = 0.01;
7
8 sub register {
9     my ($self, $context) = @_;
10     $context->register_hook(
11         $self,
12         'subscription.load' => \&load,
13     );
14 }
15
16 sub load {
17     my ($self, $context) = @_;
18     my $feed = Plagger::Feed->new;
19     $feed->aggregator(sub { $self->aggregate(@_) });
20     $context->subscription->add($feed);
21 }
22
23 sub aggregate {
24     my ($self, $context, $args) = @_;
25
26     my $feed = Plagger::Feed->new;
27     $feed->type('debug');
28     for (keys %{$self->conf}) {
29         next if $_ eq 'entry';
30         $feed->$_($self->conf->{$_});
31     }
32
33     for my $entry_conf (@{$self->conf->{entry}}) {
34         my $entry = Plagger::Entry->new;
35         $entry->$_($entry_conf->{$_}) for keys %$entry_conf;
36         $feed->add_entry($entry);
37     }
38
39     $context->update->add($feed);
40 }
41
42 1;
43
44 __END__
45
46 =head1 NAME
47
48 Plagger::Plugin::CustomFeed::Debug - Feed in config.yaml
49
50 =head1 SYNOPSIS
51
52   - module: CustomFeed::Debug
53     config:
54       title: 'My Feed'
55       link: 'http://localhost/'
56       entry:
57         - title: 'First Entry'
58           link: 'http://localhost/1'
59           body: 'Hello World! :)'
60         - title: 'Second Entry'
61           link: 'http://localhost/2'
62           body: 'Good Bye! :P'
63
64 =head1 DESCRIPTION
65
66 This plugin allows you to define your feed in C<config.yaml>, which
67 makes it easier creating a testing environment for your Plugin
68 development.
69
70 =head1 AUTHOR
71
72 Naoya Ito E<lt>naoya@bloghackers.netE<gt>
73
74 =head1 SEE ALSO
75
76 L<Plagger>
77
78 =cut
79
Note: See TracBrowser for help on using the browser.