Babble::DataSource::OPML - OPML source fetcher for Babble


Babble documentation Contained in the Babble distribution.

Index


Code Index:

NAME

Top

Babble::DataSource::OPML - OPML source fetcher for Babble

SYNOPSIS

Top

 use Babble;
 use Babble::DataSource::OPML;

 my $babble = Babble->new ();
 $babble->add_sources (
	Babble::DataSource::OPML->new (
		-id => "Planet Debian",
		-location => "http://planet.debian.net/opml.xml",
		-babble => \$babble,
	)
 );
 ...

DESCRIPTION

Top

Babble::DataSource::OPML implements an unordinary data source for Babble. Instead of collecting data itself, this class parses an OPML document, and passes the information to a set of Babble::DataSource::RSS objects. For each outline, a new object is created, and the new() method returns an array of Babble::DataSource::RSS objects.

METHODS

Top

new(%params)

Parses the OPML document specified in the -location parameter, and returns an array of Babble::DataSource::RSS objects.

If one wants to use the caching provided by Babble, a reference to the Babble object should be passed in the -babble parameter.

collect()

Returns an error - this should not be called, ever.

AUTHOR

Top

Gergely Nagy, algernon@bonehunter.rulez.org

Bugs should be reported at http://bugs.bonehunter.rulez.org/babble.

SEE ALSO

Top

Babble::DataSource::RSS, Babble::DataSource, Babble::Transport


Babble documentation Contained in the Babble distribution.
## Babble/DataSource/OPML.pm
## Copyright (C) 2004 Gergely Nagy <algernon@bonehunter.rulez.org>
##
## This file is part of Babble.
##
## Babble is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; version 2 dated June, 1991.
##
## Babble is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
## for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

package Babble::DataSource::OPML;

use strict;
use Carp;

use Babble::DataSource;
use Babble::DataSource::RSS;
use Babble::Transport;

use XML::OPML;

use Exporter ();
use vars qw(@ISA);
@ISA = qw(Babble::DataSource);

sub new {
	my $type = shift;
	my %params = @_;
	my @sources;
	my $opml = XML::OPML->new ();

	my $source = Babble::Transport->get (\%params, $params{-babble});
	return undef unless $source;
	$opml->parse ($source);

	if ($params{-babble}) {
		my $babble = $params{-babble};
		$$babble->Cache->set ('Feeds', $params{-location}, 'feed',
				      $source);
		$$babble->Cache->set ('Feeds', $params{-location}, 'time',
				      UnixDate ("now",
						"%a, %d %b %Y %H:%M:%S GMT"));
	}

	foreach my $outline (@{$opml->outline}) {
		my %nparams = %params;
		$nparams{-id} = $outline->{text};
		$nparams{-location} = $outline->{xmlUrl};
		push (@sources, Babble::DataSource::RSS->new (%nparams));
	}

	return @sources;
}

sub collect () {
	carp "collect not supported by this source";
}

1;

# arch-tag: 5088ef7b-ca76-48ae-97f9-ed332d8eb2cb