NAME
XML::RSS::Feed - Encapsulate RSS XML New Items Watching
SYNOPSIS
ATTENTION! - If you want a non-blocking way to watch multiple RSS sources with one process. Use POE::Component::RSSAggregator
A quick non-POE example:
#!/usr/bin/perl -w
use strict;
use XML::RSS::Feed;
use LWP::Simple;
my %source = (
url => "http://www.jbisbee.com/rdf/",
name => "jbisbee",
delay => 10,
tmpdir => "/tmp", # optional caching
);
my $feed = XML::RSS::Feed->new(%source);
while (1) {
print "Fetching " . $feed->url . "\n";
my $rssxml = get($feed->url);
if (my @late_breaking_news = $feed->parse($rssxml)) {
for my $headline (@late_breaking_news) {
print $headline->headline . "\n";
}
}
# this sucks (and blocks)
# use the POE::Component::RSSAggregator module instead!
sleep($feed->delay);
}
An example of subclassing XML::RSS::Headline
#!/usr/bin/perl -w
use strict;
use XML::RSS::Feed;
use LWP::Simple;
use PerlJobs;
my %source = (
url => http://jobs.perl.org/rss/standard.rss
hlobj => PerlJobs
title => jobs.perl.org
name => perljobs
delay => 1800
);
my $feed = XML::RSS::Feed->new(%source);
while (1) {
print "Fetching " . $feed->url . "\n";
my $rssxml = get($feed->url);
if (my @late_breaking_news = $feed->parse($rssxml)) {
for my $headline (@late_breaking_news) {
print $headline->headline . "\n";
}
}
sleep($feed->delay);
}
and here is PerlJobs.pm which is subclassed from XML::RSS::Headline in this example.
package PerlJobs;
use strict;
use XML::RSS::Feed;
use base qw(XML::RSS::Headline);
sub headline
{
my ($self) = @_;
my $sub_hash = $self->{item}{'http://jobs.perl.org/rss/'};
return $self->{item}{title} . "\n" . $sub_hash->{company_name} .
" - " . $sub_hash->{location} . "\n" . $sub_hash->{hours} .
", " . $sub_hash->{employment_terms};
}
1;
This can pull other info from the item block into your headline. Here is the output from rssbot on irc.perl.org in channel #news (which uses these modules)
<rssbot> -- jobs.perl.org (http://jobs.perl.org/)
<rssbot> + Part Time Perl
<rssbot> Brian Koontz - United States, TX, Dallas
<rssbot> Part time, Independent contractor (project-based)
<rssbot> http://jobs.perl.org/job/950
AUTHOR
Jeff Bisbee CPAN ID: JBISBEE cpan@jbisbee.com http://search.cpan.org/author/JBISBEE/
COPYRIGHT
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.