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

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

CustomFeed?::Debug: allow 'entries' key. auto_set_type on enclosures. Update tests

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