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

Revision 1473 (checked in by mizzy, 14 years ago)

CustomFeed?::Debug: support enclosure

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         # enclosure
39         for my $enclosure_conf ( @{ $entry_conf->{enclosure} } ){
40             my $enclosure = Plagger::Enclosure->new;
41             $enclosure->$_($enclosure_conf->{$_}) for keys %$enclosure_conf;
42             $entry->add_enclosure($enclosure);
43         }
44     }
45
46     $context->update->add($feed);
47 }
48
49 1;
50
51 __END__
52
53 =head1 NAME
54
55 Plagger::Plugin::CustomFeed::Debug - Feed in config.yaml
56
57 =head1 SYNOPSIS
58
59   - module: CustomFeed::Debug
60     config:
61       title: 'My Feed'
62       link: 'http://localhost/'
63       entry:
64         - title: 'First Entry'
65           link: 'http://localhost/1'
66           body: 'Hello World! :)'
67         - title: 'Second Entry'
68           link: 'http://localhost/2'
69           body: 'Good Bye! :P'
70           enclosure:
71             - url: http://localhost/debug.flv
72               filename: debug.flv
73               type: video/x-flv
74
75 =head1 DESCRIPTION
76
77 This plugin allows you to define your feed in C<config.yaml>, which
78 makes it easier creating a testing environment for your Plugin
79 development.
80
81 =head1 AUTHOR
82
83 Naoya Ito E<lt>naoya@bloghackers.netE<gt>
84
85 =head1 SEE ALSO
86
87 L<Plagger>
88
89 =cut
90
Note: See TracBrowser for help on using the browser.