The RSS mechanism
Now that we’ve set up the functions to handle incoming queries, all
that’s left is for us to define what happens every time the heartbeat in
the Jabber::Connection loop ticks past the 30-minute mark.
We registered this rss() function with the
register_beat() method earlier in the script:
sub rss {
debug("[rss]");
# Create NodeFactory
my $nf = new Jabber::NodeFactory;
In the IQ handlers iq-register(),
iq-version(), iq-browse(), and
iq-notimpl(),
we avoided the need to build elements from scratch, by simply turning around
the incoming request elements and making them into responses, before sending
them back. Here, in the rss() function, we’ll actually
be building elements from scratch—headline type <message>
elements to be precise. This is the reason we need an instance of the
Jabber::NodeFactory.
# Go through each of the RSS sources
foreach my $source (keys %sources) {
# Retrieve attempt
my $data = get($sources{$source});
# Didn't get it? Next one
unless (defined($data)) {
debug("cannot retrieve $source");
next;
}
# Parse the RSS
my $rss = XML::RSS->new();
eval { $rss->parse($data) };
if ($@) {
debug("Problems parsing $source");
next;
}
The procedure in this function reflects what we described earlier
in Section 9.3.1.3. Each time
rss() is called, it goes through each of the
sources defined in the list (%sources) and tries
to retrieve it with get(), a function from the
LWP::Simple library, and parse it with an instance
of XML::RSS.
Because XML::RSS uses XML::Parser ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access