Plagger::Plugin::CustomFeed::Debug - Feed in config.yaml


Plagger documentation Contained in the Plagger distribution.

Index


Code Index:

NAME

Top

Plagger::Plugin::CustomFeed::Debug - Feed in config.yaml

SYNOPSIS

Top

  - module: CustomFeed::Debug
    config:
      title: 'My Feed'
      link: 'http://localhost/'
      entry:
        - title: 'First Entry'
          link: 'http://localhost/1'
          body: 'Hello World! :)'
        - title: 'Second Entry'
          link: 'http://localhost/2'
          body: 'Good Bye! :P'
          enclosure:
            - url: http://localhost/debug.flv
              filename: debug.flv
              type: video/x-flv

DESCRIPTION

Top

This plugin allows you to define your feed in config.yaml, which makes it easier creating a testing environment for your Plugin development.

AUTHOR

Top

Naoya Ito <naoya@bloghackers.net>

SEE ALSO

Top

Plagger


Plagger documentation Contained in the Plagger distribution.

package Plagger::Plugin::CustomFeed::Debug;
use strict;
use warnings;
use base qw (Plagger::Plugin);

our $VERSION = 0.01;

sub register {
    my ($self, $context) = @_;
    $context->register_hook(
        $self,
        'subscription.load' => \&load,
    );
}

sub load {
    my ($self, $context) = @_;
    my $feed = Plagger::Feed->new;
    $feed->aggregator(sub { $self->aggregate(@_) });
    $context->subscription->add($feed);
}

sub aggregate {
    my ($self, $context, $args) = @_;

    my $feed = $args->{feed};
    $feed->type('debug');
    for (keys %{$self->conf}) {
        next if $_ eq 'entry' || $_ eq 'entries';
        $feed->$_($self->conf->{$_});
    }

    for my $entry_conf (@{ $self->conf->{entry} || $self->conf->{entries} || [] }) {
        my $entry = Plagger::Entry->new;
        for my $method (keys %$entry_conf) {
            next if $method eq 'enclosure';
            $entry->$method($entry_conf->{$method});
        }
        $feed->add_entry($entry);

        # enclosure
        my $encls = $entry_conf->{enclosure} || [];
           $encls = [ $encls ] if ref $encls && ref $encls ne 'ARRAY';

        for my $enclosure_conf ( @$encls ) {
            my $enclosure = Plagger::Enclosure->new;
            $enclosure->$_($enclosure_conf->{$_}) for keys %$enclosure_conf;
            $enclosure->auto_set_type unless defined $enclosure->type;
            $entry->add_enclosure($enclosure);
        }
    }

    $context->update->add($feed);
}

1;

__END__