Plagger::Plugin::Subscription::Feed - Subscribe entries in a XML feed (RSS/Atom)


Plagger documentation Contained in the Plagger distribution.

Index


Code Index:

NAME

Top

Plagger::Plugin::Subscription::Feed - Subscribe entries in a XML feed (RSS/Atom)

SYNOPSIS

Top

  - module: Subscription::Feed
    config:
      url: http://del.icio.us/rss/miyagawa/mycomments

DESCRIPTION

Top

This module subscribes to entries in a XML feed.

AUTHOR

Top

Tatsuhiko Miyagawa

SEE ALSO

Top

Plagger, XML::Feed


Plagger documentation Contained in the Plagger distribution.

package Plagger::Plugin::Subscription::Feed;
use strict;
use warnings;

use base qw( Plagger::Plugin );
use Plagger::Util;
use Plagger::FeedParser;

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

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

    # TODO: Auto-Discovery, XML::Liberal
    my $uri = URI->new( $self->conf->{url} )
      or $context->error("config 'url' is missing");

    $self->load_feed( $context, $uri );
}

sub load_feed {
    my ( $self, $context, $uri ) = @_;

    my $content = Plagger::Util::load_uri($uri);
    my $feed = eval { Plagger::FeedParser->parse(\$content) };

    unless ($feed) {
        $context->log( error => "Error loading feed $uri: $@" );
        return;
    }

    for my $entry ($feed->entries) {
        my $url = $entry->link or next;

        my $feed = Plagger::Feed->new;
        $feed->url($url);

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

    return 1;
}

1;