Atom feed
use XML::Atom::Feed; use XML::Atom::Entry; my $feed = XML::Atom::Feed->new; $feed->title('My Weblog'); $feed->id('tag:example.com,2006:feed-id'); my $entry = XML::Atom::Entry->new; $entry->title('First Post'); $entry->id('tag:example.com,2006:entry-id'); $entry->content('Post Body'); $feed->add_entry($entry); $feed->add_entry($entry, { mode => 'insert' }); my @entries = $feed->entries; my $xml = $feed->as_xml; ## Get a list of the <link rel="..." /> tags in the feed. my $links = $feed->link; ## Find all of the Atom feeds on a given page, using auto-discovery. my @uris = XML::Atom::Feed->find_feeds('http://www.example.com/'); ## Use auto-discovery to load the first Atom feed on a given page. my $feed = XML::Atom::Feed->new(URI->new('http://www.example.com/'));
Creates a new feed object, and if $stream is supplied, fills it with the data specified by $stream.
Automatically handles autodiscovery if $stream is a \s-1URI\s0 (see below).
Returns the new XML::Atom::Feed object. On failure, returns \*(C`undef\*(C'.
$stream can be any one of the following:
Reference to a scalar This is treated as the \s-1XML\s0 body of the feed.
Scalar This is treated as the name of a file containing the feed \s-1XML\s0.
Filehandle This is treated as an open filehandle from which the feed \s-1XML\s0 can be read.
\s-1URI\s0 object This is treated as a \s-1URI\s0, and the feed \s-1XML\s0 will be retrieved from the \s-1URI\s0. If the content type returned from fetching the content at \s-1URI\s0 is text/html, this method will automatically try to perform auto-discovery by looking for a <link> tag describing the feed \s-1URL\s0. If such a \s-1URL\s0 is found, the feed \s-1XML\s0 will be automatically retrieved. If the \s-1URI\s0 is already of a feed, no auto-discovery is necessary, and the feed \s-1XML\s0 will be retrieved and parsed as normal.
Given a \s-1URI\s0 $uri, use auto-discovery to find all of the Atom feeds linked from that page (using <link> tags).
Returns a list of feed URIs. If called in scalar context, returns an XML::Atom::Link object corresponding to the first <link> tag found in the feed.
If called in list context, returns a list of XML::Atom::Link objects corresponding to all of the <link> tags found in the feed. Adds the link $link, which must be an XML::Atom::Link object, to the feed as a new <link> tag. For example:
my $link = XML::Atom::Link->new; $link->type('text/html'); $link->rel('alternate'); $link->href('http://www.example.com/'); $feed->add_link($link); Adds the entry $entry, which must be an XML::Atom::Entry object, to the feed. If you want to add an entry before existent entries, you can pass optional hash reference containing \*(C`mode\*(C' value set to \*(C`insert\*(C'.
$feed->add_entry($entry, { mode => 'insert' }); Returns list of XML::Atom::Entry objects contained in the feed. Returns the language of the feed, from xml:lang. Returns an XML::Atom::Person object representing the author of the entry, or \*(C`undef\*(C' if there is no author information present.
If $author is supplied, it should be an XML::Atom::Person object representing the author. For example:
my $author = XML::Atom::Person->new; $author->name('Foo Bar'); $author->email('[email protected]'); $feed->author($author); Returns an id for the feed. If $id is supplied, set the id. When generating the new feed, it is your responsibility to generate unique \s-1ID\s0 for the feed and set to XML::Atom::Feed object. You can use http permalink, tag \s-1URI\s0 scheme or urn:uuid for handy.
By default, XML::Atom takes off all the Unicode flag fro mthe feed content. For example,
my $title = $feed->title;
the variable $title contains \s-1UTF-8\s0 bytes without Unicode flag set, even if the feed title contains some multibyte chracters.
If you don't like this behaviour and wants to andle everything as Unicode characters (rather than \s-1UTF-8\s0 bytes), set $XML::Atom::ForceUnicode flag to 1.
$XML::Atom::ForceUnicode = 1;
then all the data returned from XML::Atom::Feed object and XML::Atom::Entry object etc., will have Unicode flag set.
The only exception will be \*(C`$entry->content->body\*(C', if content type is not text/* (e.g. image/gif). In that case, the content body is still binary data, without Unicode flag set.
By default, XML::Atom::Feed and other classes (Entry, Link and Content) will create entities using Atom 0.3 namespaces. In order to create 1.0 feed and entry elements, you can set Version as a parameter, like:
$feed = XML::Atom::Feed->new(Version => 1.0); $entry = XML::Atom::Entry->new(Version => 1.0);
Setting those Version to every element would be sometimes painful. In that case, you can override the default version number by setting $XML::Atom::DefaultVersion global variable to \*(L"1.0\*(R".
use XML::Atom;
$XML::Atom::DefaultVersion = "1.0";
my $feed = XML::Atom::Feed->new; $feed->title("blah");
my $entry = XML::Atom::Entry->new; $feed->add_entry($entry);
$feed->version; # 1.0
Please see the XML::Atom manpage for author, copyright, and license information.