XML::Feed(3pm)
๐ XML::Feed(3pm) โ the manual page, but make it cute ๐
okay bestie, pull up a chair, we're reading a man page together and honestly? it's a good one. this is <purple>XML::Feed(3pm)</purple> from the User Contributed Perl Documentation crew, and it's about to be your new hyperfixation. no cap. ๐ฆ
โจ NAME โจ
XML::Feed โ syndication feed parser and auto-discovery. it literally does both. main character energy fr. ๐
๐ SYNOPSIS ๐
bestie here's the vibe in code form, copy it exactly, don't retype it from memory:
use XML::Feed;
my $feed = XML::Feed->parse(URI->new('http://example.com/atom.xml'))
or die XML::Feed->errstr;
print $feed->title, "\n";
for my $entry ($feed->entries) {
}
## Find all of the syndication feeds on a given page, using
## auto-discovery.
my @feeds = XML::Feed->find_feeds('http://example.com/');
look at that. clean. slay. ๐
๐ DESCRIPTION ๐
XML::Feed is a syndication feed parser for both RSS and Atom feeds. it also implements feed auto-discovery for finding feeds, given a URI. it's giving two jobs and doing both flawlessly, honestly iconic. โจ
here's the format roster it fucks with (affectionate):
- RSS 0.91
- RSS 1.0
- RSS 2.0
- Atom
the whole goal of XML::Feed is to give you one unified API for parsing and using all these different syndication formats. because babes โ the different flavors of RSS and Atom handle data in completely different ways: date handling, summaries and content, escaping and quoting, etc. etc. etc. ๐ญ
this module tries to remove those differences by wrapping the formats and the classes that implement them (XML::RSS and XML::Atom::Feed). for example! dates are handled differently in each of the formats above. so to give you a unified API for date handling, XML::Feed converts all date formats transparently into DateTime objects, which it then hands back to the caller. it's giving translator bestie, we love a middleman who actually helps. ๐ซถ
๐ธ USAGE ๐ธ
๐ง XML::Feed->new($format)
๐ง XML::Feed->new($format, \%args)
creates a new empty XML::Feed object using the format $format. look:
$feed = XML::Feed->new('Atom');
$feed = XML::Feed->new('RSS');
$feed = XML::Feed->new('RSS', version => '0.91');
an optional hashref of arguments can be provided as the last parameter:
my $ua = LWP::UserAgent->new;
$ua->timeout(30);
$feed = XML::Feed->new('Atom', { useragent => $ua });
currently supported arguments, bestie, listen up:
- useragent โ an
LWP::UserAgentobject (or subclass) to use for fetching feeds via URI. if you don't provide one, a defaultUserAgentwill be created when needed. it's got a whole backup plan, we stan a prepared queen. ๐
๐ XML::Feed->parse($stream)
๐ XML::Feed->parse($stream, \%args)
๐ XML::Feed->parse($stream, $format)
๐ XML::Feed->parse($stream, $format, \%args)
parses a syndication feed identified by $stream and returns an XML::Feed object. $stream can be any one of the following:
- Scalar reference โ a reference to string containing the XML body of the feed.
- Filehandle โ an open filehandle from which the feed XML will be read.
- File name โ the name of a file containing the feed XML.
- URI object โ a URI from which the feed XML will be retrieved.
$format lets you override format guessing. (yes, it guesses. it's psychic like that. ๐ฎ)
an optional hashref of arguments can be provided as the last parameter:
my $ua = LWP::UserAgent->new;
$ua->timeout(30);
$feed = XML::Feed->parse('https://example.com/feed', { useragent => $ua });
currently supported arguments:
- useragent โ an
LWP::UserAgentobject (or subclass) to use for fetching feeds via URI. if not provided, a defaultUserAgentwill be created when needed. (same deal as before, she's consistent ๐)
๐ซ XML::Feed->get_file($filename)
gets a feed from a file. simple! iconic!
๐ซ CML::Feed->get_fh($fh)
gets a feed from pre-opened filehandle.
ngl bestie, that CML::Feed is literally how it's written in the original manual page. i am not fixing it. i am not touching it. do not come for me, take it up with the manpage. ๐
๐ซ XML::Feed->get_uri($uri)
gets a feed from a URI.
๐ XML::Feed->find_feeds($uri)
given a URI $uri, use auto-discovery to find all of the feeds linked from that page (using <link> tags).
returns a list of feed URIs. she's a detective and she found them all, periodt. ๐ต๏ธโ๏ธโจ
๐ XML::Feed->identify_format(\$xml)
given the xml of a feed, return what format it is in, with "Atom" or "RSS" for all versions of RSS. note: you pass in a scalar ref to the xml string. don't forget the ref or she'll be confused and honestly same. ๐
๐ $feed->convert($format)
converts the XML::Feed object into the $format format, and returns the new object.
๐ $feed->splice($other_feed)
splices in all of the entries from the feed $other_feed into $feed, skipping posts that are already in $feed. no duplicates allowed, she has boundaries. ๐ซ๐
๐ท๏ธ $feed->format
returns the format of the feed ("Atom", or some version of "RSS").
๐ท๏ธ $feed->title([ $title ])
the title of the feed/channel.
๐ท๏ธ $feed->base([ $base ])
the url base of the feed/channel.
๐ท๏ธ $feed->link([ $uri ])
the permalink of the feed/channel.
๐ท๏ธ $feed->tagline([ $tagline ])
the description or tagline of the feed/channel.
๐ท๏ธ $feed->description([ $description ])
alias for $feed->tagline. (same girl, different name โจ)
๐ท๏ธ $feed->author([ $author ])
the author of the feed/channel.
๐ท๏ธ $feed->language([ $language ])
the language of the feed.
๐ท๏ธ $feed->copyright([ $copyright ])
the copyright notice of the feed. protect the intellectual property bestie ยฉ๏ธ
๐ $feed->modified([ $modified ])
a DateTime object representing the last-modified date of the feed.
if present, $modified should be a DateTime object. not optional-optional, like, actually do this.
๐ท๏ธ $feed->generator([ $generator ])
the generator of the feed.
๐ $feed->self_link ([ $uri ])
the Atom Self-link of the feed:
<http://validator.w3.org/feed/docs/warning/MissingAtomSelfLink.html>
a string. that's it, that's the whole vibe.
๐ $feed->entries
a list of the entries/items in the feed. returns an array containing XML::Feed::Entry objects.
๐ $feed->items
a synonym (alias) for "$feed->entries". two names, one queen. ๐
โ $feed->add_entry($entry)
adds an entry to the feed. $entry should be an XML::Feed::Entry object in the correct format for the feed. format match or it's not vibing, iykyk.
๐ $feed->as_xml
returns an XML representation of the feed, in the format determined by the current format of the $feed object.
๐ต๏ธ $feed->useragent([ $ua ])
get or set the LWP::UserAgent object used for fetching feeds.
if called without arguments, returns the current UserAgent object, creating a default one if it doesn't exist. (she'll make one for you, she's generous like that.)
if called with an LWP::UserAgent object (or subclass), sets it as the UserAgent for this feed.
my $ua = LWP::UserAgent->new;
$ua->timeout(30);
$feed->useragent($ua);
# Later, retrieve it
my $current_ua = $feed->useragent;
๐ $feed->first_link ([ $uri ])
the Atom First-link for feed paging and archiving (RFC 5005).
<http://tools.ietf.org/html/rfc5005>
๐ $feed->last_link ([ $uri ])
the Atom Last-link for feed paging and archiving.
๐ $feed->next_link ([ $uri ])
the Atom Next-link for feed paging and archiving.
๐ $feed->previous_link ([ $uri ])
the Atom Previous-link for feed paging and archiving.
๐ $feed->current_link ([ $uri ])
the Atom Current-link for feed paging and archiving.
๐ $feed->next_archive_link ([ $uri ])
the Atom Next-link for feed paging and archiving.
๐ $feed->prev_archive_link ([ $uri ])
the Atom Prev-Archive-link for feed paging and archiving.
๐ PACKAGE VARIABLES ๐
๐ $XML::Feed::Format::RSS::PREFERRED_PARSER
if you want to use another RSS parser class than XML::RSS (the default), you can change the class by setting the $PREFERRED_PARSER variable in the XML::Feed::Format::RSS package.
$XML::Feed::Format::RSS::PREFERRED_PARSER = "XML::RSS::LibXML";
Note: this will only work for parsing feeds, not creating feeds. know the limits bestie ๐ซถ
Note: only "XML::RSS::LibXML" version 0.3004 is known to work at the moment. specific queen, specific version. ๐
๐ $XML::Feed::MULTIPLE_ENCLOSURES
although the RSS specification states that there can be at most one enclosure per item, some feeds break this rule. rude of them honestly. ๐ค
if this variable is set, then "XML::Feed" captures all of them and makes them available as a list.
otherwise, it returns the last enclosure parsed. (last one wins, bye to the rest ๐)
Note: "XML::RSS" version 1.44 is needed for this to work. no version 1.44, no list, sorry bestie.
๐งช VALID FEEDS ๐งช
for reference, this cgi script will create valid, albeit nonsensical feeds (according to "http://feedvalidator.org" anyway) for Atom 1.0 and RSS 0.90, 0.91, 1.0 and 2.0. nonsensical but valid? that's the dream combo fr fr. ๐ฅ
#!perl -w
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use DateTime;
use XML::Feed;
my $cgi = CGI->new;
my @args = ( $cgi->param('format') // "Atom" );
push @args, ( version => $cgi->param('version') ) if $cgi->param('version');
my $feed = XML::Feed->new(@args);
$feed->id("http://".time.rand()."/");
$feed->title('Test Feed');
$feed->link($cgi->url);
$feed->self_link($cgi->url( -query => 1, -full => 1, -rewrite => 1) );
$feed->modified(DateTime->now);
my $entry = XML::Feed::Entry->new();
$entry->id("http://".time.rand()."/");
$entry->link("http://example.com");
$entry->title("Test entry");
$entry->summary("Test summary");
$entry->content("Foo");
$entry->modified(DateTime->now);
$entry->author('test@example.com (Testy McTesterson)');
$feed->add_entry($entry);
my $mime = ("Atom" eq $feed->format) ? "application/atom+xml" : "application/rss+xml";
print $cgi->header($mime);
print $feed->as_xml;
๐ LICENSE ๐
XML::Feed is free software; you may redistribute it and/or modify it under the same terms as Perl itself. free is free bestie, redistribute away. ๐๏ธ
๐ AUTHOR & COPYRIGHT ๐
except where otherwise noted, XML::Feed is Copyright 2004-2008 Six Apart. all rights reserved.
๐ SUPPORT ๐
for support, contact the XML::Feed mailing list โ xml-feed@perlhacks.com. they're your people now. email them. ๐ซ
๐ป SOURCE CODE ๐ป
the latest version of XML::Feed can be found at
http://github.com/davorg/XML-Feed
go. clone it. star it. that's your homework. โญ
okay and that's the whole page bestie!! this was XML::Feed(3pm), documented under perl v5.40.1, dated 2026-02-21 โ like, the future. ๐ซ thanks for reading the whole thing with me, you ate that fr fr. now go parse a feed and slay ๐โจ๐๐ฆ๐ธ๐
๐ซถ
๐ฆ where this page comes from
- ubuntu stonking: libxml-feed-perl 1.0.0+dfsg-1 ยท 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