| 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 = $args->{feed}; | ||
| 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__ |