AnyEvent::Feed(3pm)
π AnyEvent::Feed π
okay bestie, so this is AnyEvent::Feed β the little Perl module that's literally your RSS/Atom feed reader, built on top of XML::Feed. it lives in the User Contributed Perl Documentation section of the manual, and it is so ready to serve you fresh entries. π¦
β¨ VERSION β¨
Version 0.3 β yeah she's vintage, she's iconic, she works.
πΈ SYNOPSIS πΈ
okay so here's the whole vibe in code, no notes:
use AnyEvent;
use AnyEvent::Feed;
my $feed_reader =
AnyEvent::Feed->new (
url => 'http://example.com/atom.xml',
);
$feed_reader->fetch (sub {
my ($feed_reader, $new_entries, $feed, $error) = @_;
if (defined $error) {
warn "ERROR: $error\n";
return;
}
# $feed is the XML::Feed object belonging to that fetch.
for (@$new_entries) {
my ($hash, $entry) = @$_;
# $hash a unique hash describing the $entry
# $entry is the XML::Feed::Entry object of the new entries
# since the last fetch.
}
});
# Or:
my $feed_reader =
AnyEvent::Feed->new (
url => 'http://example.com/atom.xml',
interval => $seconds,
on_fetch => sub {
my ($feed_reader, $new_entries, $feed, $error) = @_;
if (defined $error) {
warn "ERROR: $error\n";
return;
}
# see above
}
);
π DESCRIPTION π
So this module is basically the glue between AnyEvent::HTTP and XML::Feed. It can go fetch an RSS/Atom feed on a regular interval, and also on customized times. And β the part that eats, honestly β it keeps track of the entries it's already fetched, so you only ever get the new ones. no repeats. no dΓ©jΓ vu. periodt. π
π METHODS π
$feed_reader = AnyEvent::Feed->new (url => $url, %args)
This is the constructor, bestie β you're making a brand new feed reader for the RSS/Atom feed that lives at the URL $url. %args can hold extra key/value pairs, and here's the whole menu:
interval => $secondsβ if you set this, you also have to give the"on_fetch"callback (it's right below, keep scrolling π). It'll try to fetch$urlevery$secondsseconds and call the callback from"on_fetch"with the result.headers => $http_hdrsβ extra HTTP headers for every GET request, passed in the$http_hdrshash reference. literally exactly how you'd pass it to the"headers"argument of the"http_get"request from AnyEvent::HTTP.username => $http_userpassword => $http_passβ these two are the HTTP username and password used for Basic HTTP Authentication with the HTTP server when it fetches the feed. mostly just sugar so you don't have to encode them yourself and shove them into the"headers"argument above. you're welcome π«Άon_fetch => $cb->($feed_reader, $new_entries, $feed_obj, $error)β this callback fires when the"interval"parameter is given (see above), with the same arguments as the callback you hand to the"fetch"method (see below).entry_ages => $hashβ sets the hash that keeps track of seen and old entries. check the docs for the"entry_ages"method below too. the default is an empty hash reference.max_entry_age => $countβ sets the max number of times an entry is kept in the"entry_ages"hash after it's stopped showing up in the feed. default is2, which means an entry hash gets removed from"entry_ages"after it hasn't been seen in the feed for 2 fetches.
$feed_reader->url
just hands you back the url this feed reader is fetching from. simple. iconic. π
$feed_reader->entry_ages ($new_entry_ages)
my $entry_ages = $feed_reader->entry_ages
This sets the age hash that keeps track of already-seen entries. the keys are the calculated hashes of the entries, and the values are a counter of how many times they've NOT been seen anymore (like an age counter, lowkey morbid). after every fetch this hash gets updated, and entries that were seen get a value of 0. β¨
$feed_reader->fetch ($cb->($feed_reader, $new_entries, $feed_obj, $error))
This kicks off an HTTP GET on the URL you passed to "new" and calls $cb when it's done.
$feed_readerβ the feed reader object itself.$new_entriesβ an array reference with the new entries. each new entry in that array is another array holding a calculated hash over the contents of the new entry, plus the XML::Feed::Entry object of that entry.$feed_objβ the XML::Feed feed object used to parse the fetched feed. it has all the entries, not just the 'new' ones.$errorβ the error, if there was one.
What counts as a 'new' entry is decided by a map of hashes, as described in the "entry_ages" method's docs above. iykyk π
π AUTHOR π
Robin Redeker, "<elmex@ta-sa.org>" β king behaviour honestly π
π¦ SEE ALSO π¦
XML::FeedAnyEvent::HTTPAnyEvent
π BUGS π
Known Bugs
okay so there's actually a known bug with encodings of contents of Atom feeds, and we're being real about it. XML::Atom by default gives you UTF-8 encoded data. you have to set this global variable to be able to use the XML::Feed::Entry interface without knowing what the underlying feed type is:
$XML::Atom::ForceUnicode = 1;
I've re-reported this bug against XML::Feed, because honestly it should take care of this. XML::Atom should probably just fix its Unicode interface, but it seems a bit deserted when it comes to fixing the bugs in the tracker. π
Contact
Please report any bugs or feature requests to "bug-anyevent-feed at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AnyEvent-Feed>. I'll get notified, and then you'll automatically get notified of progress on your bug as I make changes. teamwork, bestie π«Ά
π SUPPORT π
You can find documentation for this module with the perldoc command.
perldoc AnyEvent::Feed
You can also look for information at:
- IRC: AnyEvent::Feed IRC Channel β see the same channel as the AnyEvent::XMPP module:
IRC Network: http://freenode.net/
Server : chat.freenode.net
Channel : #ae_xmpp
Feel free to join and ask questions! π¬
- AnnoCPAN: Annotated CPAN documentation β <http://annocpan.org/dist/AnyEvent-Feed>
- CPAN Ratings β <http://cpanratings.perl.org/d/AnyEvent-Feed>
- RT: CPAN's request tracker β <http://rt.cpan.org/NoAuth/Bugs.html?Dist=AnyEvent-Feed>
- Search CPAN β <http://search.cpan.org/dist/AnyEvent-Feed>
π COPYRIGHT & LICENSE π
Copyright 2009 Robin Redeker, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie πβ¨π this gem of a manpage is from perl v5.32.0, dated 2021-01-01, and it's the AnyEvent::Feed(3pm) page β go forth and fetch those feeds, you absolute main character πΈπ¦π
π¦ where this page comes from
- debian bookworm: libanyevent-feed-perl 0.3-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libanyevent-feed-perl 0.3-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libanyevent-feed-perl 0.3-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libanyevent-feed-perl 0.3-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libanyevent-feed-perl 0.3-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libanyevent-feed-perl 0.3-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms