NAME
Mojo::Feed::Reader - Fetch feeds
SYNOPSIS
use Mojo::Feed::Reader;
my $feedr = Mojo::Feed::Reader->new( ua => $ua );
my $feed = $feedr->parse("atom.xml");
print $feed->title, "\n",
$feed->items->map('title')->join("\n");
# Feed discovery (returns a Promise):
$feedr->discover("search.cpan.org")->then(sub {
my (@feeds) = @_;
if (@feeds) {
print $_ for (@feeds);
}
})->catch(sub { die "Error: ", @_; });
#
DESCRIPTION
Mojo::Feed::Reader is an Object Oriented module for identifying, fetching and parsing RSS and Atom Feeds. It relies on Mojo::DOM for XML/HTML parsing and Mojo::UserAgent for fetching feeds and checking URLs.
ATTRIBUTES
Mojo::Feed::Reader implements the following attributes.
ua
$feed->ua(Mojo::UserAgent->new());
$feed->ua->get("http://example.com");
Mojo::UserAgent object used to fetch feeds from the web.
METHODS
Mojo::Feed::Reader inherits all methods from Mojo::Base and implements the following new ones.
new
Construct a new Mojo::Feed::Reader object.
discover
my @feeds;
Mojo::Feed::Reader->new->discover('search.cpan.org')
->then(sub { @feeds = @_; })
->wait();
for my $feed in (@feeds) {
print $feed . "\n";
}
# @feeds is a list of Mojo::URL objects
A Mojo port of Feed::Find by Benjamin Trott. This method implements feed auto-discovery for finding syndication feeds, given a URL. Returns a Mojo::Promise, which is fulfilled with a list of feeds (Mojo::URL objects)
parse
my $feedr = Mojo::Feed::Reader->new;
# parse an RSS/Atom feed
my $url = Mojo::URL->new('http://rss.slashdot.org/Slashdot/slashdot');
my $feed = $feedr->parse($url);
# parse a file
$feed2 = $feedr->new->parse('/downloads/foo.rss');
# parse a string
my $str = Mojo::File->new('atom.xml')->slurp;
$feed3 = $feedr->parse($str);
A minimalist liberal RSS/Atom parser, using Mojo::DOM queries.
If the parsed object is not a feed (for example, the parser was given an HTML page), the method will return undef.
parse_opml
my @subscriptions = Mojo::Feed::Reader->new->parse_opml( 'mysubs.opml' );
foreach my $sub (@subscriptions) {
say 'RSS URL is: ', $sub->{xmlUrl};
say 'Website URL is: ', $sub->{htmlUrl};
say 'categories: ', join ',', @{$sub->{categories}};
}
Parse an OPML subscriptions file and return the list of feeds as an array of hashrefs.
Each hashref will contain an array ref in the key 'categories' listing the folders (parent nodes) in the OPML tree the subscription item appears in.
CREDITS
Dotan Dimet
Mario Domgoergen
Some tests adapted from Feed::Find and XML:Feed, Feed auto-discovery adapted from Feed::Find.
LICENSE
Copyright (C) Dotan Dimet.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
Dotan Dimet <dotan@corky.net>
Mario Domgoergen