Mojo::Feed::Reader - Fetch feeds
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: ", @_; }); #
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.
Mojo::Feed::Reader implements the following attributes.
$feed->ua(Mojo::UserAgent->new()); $feed->ua->get("http://example.com");
Mojo::UserAgent object used to fetch feeds from the web.
Mojo::Feed::Reader inherits all methods from Mojo::Base and implements the following new ones.
Construct a new Mojo::Feed::Reader object.
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)
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.
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.
Dotan Dimet
Mario Domgoergen
Some tests adapted from Feed::Find and XML:Feed, Feed auto-discovery adapted from Feed::Find.
Copyright (C) Dotan Dimet.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Dotan Dimet <dotan@corky.net>
To install Mojo::Feed, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::Feed
CPAN shell
perl -MCPAN -e shell install Mojo::Feed
For more information on module installation, please visit the detailed CPAN module installation guide.