No-fuss generation of atom syndication feeds
This document describes XML::Atom::SimpleFeed version 0.84
use XML::Atom::SimpleFeed; my $feed = XML::Atom::SimpleFeed->new( title => 'Example Feed', link => 'http://example.org/', link => { rel => 'self', href => 'http://example.org/atom', }, updated => '2003-12-13T18:30:02Z', author => 'John Doe', id => 'urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6', ); $feed->add_entry( title => 'Atom-Powered Robots Run Amok', link => 'http://example.org/2003/12/13/atom03', id => 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a', summary => 'Some text.', updated => '2003-12-13T18:30:02Z', category => 'Atom', category => 'Miscellaneous', ); $feed->print;
This module provides a minimal \s-1API\s0 for generating Atom syndication feeds quickly and easily. It supports all aspects of the Atom format, but has no provisions for generating feeds with extension elements.
You can supply strings for most things, and the module will provide useful defaults. When you want more control, you can provide data structures, as documented, to specify more particulars.
XML::Atom::SimpleFeed instances are created by the \*(C`new\*(C' constructor, which takes a list of key-value pairs as parameters. The keys are used to create the corresponding \*(L"Atom elements\*(R". The following elements are available:
"\*(C`id\*(C'" (omissible)
"\*(C`link\*(C'" (omissible, multiple)
"\*(C`title\*(C'" (required)
"\*(C`author\*(C'" (optional, multiple)
"\*(C`category\*(C'" (optional, multiple)
"\*(C`contributor\*(C'" (optional, multiple)
"\*(C`generator\*(C'" (optional)
"\*(C`icon\*(C'" (optional)
"\*(C`logo\*(C'" (optional)
"\*(C`rights\*(C'" (optional)
"\*(C`subtitle\*(C'" (optional)
"\*(C`updated\*(C'" (optional)
To specify multiple instances of an element that may be given multiple times, simply list multiple key-value pairs with the same key. This method adds an entry into the Atom feed. It takes a list of key-value pairs as parameters. The keys are used to create the corresponding \*(L"Atom Elements\*(R". The following elements are available:
"\*(C`author\*(C'" (required unless there is a feed-level author, multiple)
"\*(C`id\*(C'" (omissible)
"\*(C`link\*(C'" (required, multiple)
"\*(C`title\*(C'" (required)
"\*(C`category\*(C'" (optional, multiple)
"\*(C`content\*(C'" (optional)
"\*(C`contributor\*(C'" (optional, multiple)
"\*(C`published\*(C'" (optional)
"\*(C`rights\*(C'" (optional)
"\*(C`summary\*(C'" (optional)
"\*(C`updated\*(C'" (optional)
To specify multiple instances of an element that may be given multiple times, simply list multiple key-value pairs with the same key. Suppresses the output of a default \*(C`generator\*(C' element. It is not necessary to call this method if you supply a custom \*(C`generator\*(C' element. Returns the \s-1XML\s0 representation of the feed as a string. Outputs the \s-1XML\s0 representation of the feed to a handle which should be passed as a parameter. Defaults to \*(C`STDOUT\*(C' if you do not pass a handle.
A \*(L"Person Construct\*(R" denoting the author of the feed or entry.
If you supply at least one author for the feed, you can omit this information from entries; the feed's author(s) will be assumed as the author(s) for those entries. If you do not supply any author for the feed, you must supply one for each entry. One or more categories that apply to the feed or entry. You can supply a string which will be used as the category term. The full range of details that can be provided by passing a hash instead of a string is as follows: The category term. A \s-1URI\s0 that identifies a categorization scheme. It is common to provide the base of some kind of by-category \s-1URL\s0 here. F.ex., if the weblog \*(C`http://www.example.com/blog/\*(C' can be browsed by category using URLs such as \*(C`http://www.example.com/blog/category/personal\*(C', you would supply \*(C`http://www.example.com/blog/category/\*(C' as the scheme and, in that case, \*(C`personal\*(C' as the term. A human-readable version of the term. The actual, honest-to-goodness, body of the entry. This is like a \*(L"Text Construct\*(R", with a couple of extras.
In addition to the \*(C`type\*(C' values of a \*(L"Text Construct\*(R", you can also supply any \s-1MIME\s0 Type (except multipart types, which the Atom format specification forbids). If you specify a \*(C`text/*\*(C' type, the same rules apply as for \*(C`text\*(C'. If you pass a \*(C`*/xml\*(C' or \*(C`*/*+xml\*(C' type, the same rules apply as for \*(C`xhtml\*(C' (except in that case there is no wrapper \*(C`<div>\*(C' element). Any other type will be transported as Base64-encoded binary.
\s-1XXX\s0 Furthermore, you can supply a \*(C`src\*(C' key in place of the \*(C`content\*(C' key. In that case, the value of the \*(C`src\*(C' key should be a \s-1URL\s0 denoting the actual location of the content. \s-1FIXME\s0 This is not currently supported. \s-1XXX\s0 A \*(L"Person Construct\*(R" denoting a contributor to the feed or entry. The software used to generate the feed. Can be supplied as a string, or a hash with \*(C`uri\*(C', \*(C`version\*(C' and \*(C`name\*(C' keys. Defaults to reporting XML::Atom::SimpleFeed as the generator, which can be calling \*(C`no_generator\*(C'. The \s-1URI\s0 of a small image that should have the same height and width. A \s-1URI\s0 that is a permanent, globally unique identifier for the feed or entry that \s-1MUST\s0 \s-1NEVER\s0 \s-1CHANGE\s0.
You are encouraged to generate a \s-1UUID\s0 using Data::UUID for the purpose of identifying entries/feeds. It should be stored alongside the resource corresponding to the entry/feed, f.ex. in a column of the article table of your weblog database. To use it as an identifier in the entry/feed, use the \*(C`urn:uuid:########-####-####-####-############\*(C' \s-1URI\s0 form.
If you do not specify an \s-1ID\s0, the permalink will be used instead. This is unwise, as permalinks do unfortunately occasionally change. It is your responsibility to ensure that the permalink \s-1NEVER\s0 \s-1CHANGES\s0. A link element. You can either supply a bare string as the parameter, which will be used as the permalink \s-1URI\s0, or a hash. The permalink for a feed is generally a browser-viewable weblog, upload browser, search engine results page or similar web page; for an entry, it is generally a browser-viewable article, upload details page, search result or similar web page. This \s-1URI\s0 should be unique. If you supply a hash, you can provide the following range of details in the given hash keys: The link relationship. If omitted, defaults to \*(C`alternate\*(C' (note that you can only have one alternate link per feed/entry). Other permissible values are \*(C`related\*(C', \*(C`self\*(C', \*(C`enclosure\*(C' and \*(C`via\*(C', as well as any \s-1URI\s0. Where the link points to. An advisory media type that provides a hint about the type of the resource pointed to by the link. The language of the resource pointed to by the link, an an \s-1RFC3066\s0 language tag. Human-readable information about the link. A hint about the content length in bytes of the resource pointed to by the link. The \s-1URI\s0 of an image that should be twice as wide as it is high. A \*(L"Date Construct\*(R" denoting the moment in time when the entry was first published. This should never change. A \*(L"Text Construct\*(R" containing a human-readable statement of legal rights for the content of the feed or entry. This is not intended for machine processing. A \*(L"Text Construct\*(R" containing an optional additional description of the feed. A \*(L"Text Construct\*(R" giving a short summary of the entry. A \*(L"Text Construct\*(R" containing the title of the feed or entry. A \*(L"Date Construct\*(R" denoting the moment in time when the feed or entry was last updated. Defaults to the current date and time if omitted.
In entries, you can use this element to signal significant changes at your discretion.
A number of Atom elements share a common structure. The following sections outline the data you can (or must) pass in each case.
A string denoting a date and time in W3CDTF format. You can generate those using something like
use POSIX qw( strftime ); my $now = strftime '%Y-%m-%dT%H:%M:%SZ', gmtime;
You can supply a string to Person Construct parameters, which will be used as the name of the person. The full range of details that can be provided by passing a hash instead of a string is as follows: The name of the person. The person's email address. A \s-1URI\s0 to distinguish this person. This would usually be a homepage, but need not actually be a dereferencable \s-1URL\s0.
You can supply a string to Text Construct parameters, which will be used as the \s-1HTML\s0 content of the element.
\s-1FIXME\s0 details, text/html/xhtml
Atom Enabled (<http://www.atomenabled.org/>)
W3CDTF Spec (<http://www.w3.org/TR/NOTE-datetime>)
\s-1RFC\s0 3066 (<http://rfc.net/rfc3066.html>)
XML::Atom::Syndication
XML::Feed
http://groups.yahoo.com/group/atomic-perl/
In \*(C`content\*(C' elements, the \*(C`src\*(C' attribute cannot be used, and non-XML or -text media types do not get Base64-encoded automatically. This is a bug.
There are practically no tests. This is a bug.
Support for \*(C`xml:lang\*(C' and \*(C`xml:base\*(C' is completely absent. This is a bug and should be partially addressed in a future version. There are however no plans to allow these attributes on arbitrary elements.
There are no plans to ever support generating feeds with arbitrary extensions, although support for specific extensions may or may not be added in the future.
The \*(C`source\*(C' element is not and may never be supported.
Nothing is done to ensure that text constructs with type \*(C`xhtml\*(C' and entry contents using either that or an \s-1XML\s0 media type are well-formed. So far, this is by design. You should strongly consider using an \s-1XML\s0 writer if you want to include content with such types in your feed.
If you find bugs or you have feature requests, please report them to <mailto:[email protected]>, or through the web interface at <http://rt.cpan.org>.
Aristotle Pagaltzis, <mailto:[email protected]>
\s-1API\s0 designed largely by H. Wade Minter.
Copyright (c) 2005-2006, Aristotle Pagaltzis. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
\s-1BECAUSE\s0 \s-1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