XML::At...mpleFeed(3)

πŸ’– NAME πŸ’–

Okay so welcome to XML::Atom::SimpleFeed(3), bestie β€” a User Contributed Perl Documentation page for XML::Atom::SimpleFeed, aka literally No-fuss generation of Atom syndication feeds. Periodt. ✨

πŸ¦‹ SYNOPSIS πŸ¦‹

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;

🌸 DESCRIPTION 🌸

This is a minimal API for generating Atom syndication feeds quickly and easily. It supports all aspects of the Atom format itself but has no mechanism for the inclusion of extension elements. No extension-element era here, bestie β€” that's just not what this module does.

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. It's giving tiny API, huge convenience. πŸ’…


πŸ‘‘ INTERFACE πŸ‘‘

✨ new ✨

Takes a list of key-value pairs.

Most keys are used to create corresponding "Atom elements". To specify multiple instances of an element that may be given multiple times, pass multiple key-value pairs with the same key. Yes, same key again and again β€” that's the whole trick.

Keys that start with a dash specify how the XML document will be generated.

The following keys are supported:

  • -encoding β€” omissible, default us-ascii
  • id β€” omissible
  • link β€” omissible, multiple
  • title β€” required
  • author β€” optional, multiple
  • category β€” optional, multiple
  • contributor β€” optional, multiple
  • generator β€” optional
  • icon β€” optional
  • logo β€” optional
  • rights β€” optional
  • subtitle β€” optional
  • updated β€” optional

πŸ› οΈ add_entry πŸ› οΈ

Takes a list of key-value pairs, used to create corresponding "Atom elements". To specify multiple instances of an element that may be given multiple times, pass multiple key-value pairs with the same key. Same energy as new: repeat the key when the element can repeat.

The following keys are supported:

  • author β€” required unless there is a feed-level author, multiple
  • id β€” omissible
  • link β€” required, multiple
  • title β€” required
  • category β€” optional, multiple
  • content β€” optional
  • contributor β€” optional, multiple
  • published β€” optional
  • rights β€” optional
  • summary β€” optional
  • updated β€” optional

🧡 as_string 🧡

Returns the XML representation of the feed as a string. String mode: activated. ✨

πŸ–¨οΈ print πŸ–¨οΈ

Outputs the XML representation of the feed to a handle which should be passed as a parameter. Defaults to STDOUT if you do not pass a handle. No handle? Cool, it's sliding into STDOUT. 🫢


🌈 ATOM ELEMENTS 🌈

🫢 author 🫢

A "Person Construct" 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. Feed-level author is the group chat; entry-level author is optional unless the feed has none. πŸ’–

🏷️ category 🏷️

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:

  • term β€” required. The category term.
  • scheme β€” optional. A URI that identifies a categorization scheme.

It is common to provide the base of some kind of by-category URL here. F.ex., if the weblog http://www.example.com/blog/ can be browsed by category using URLs such as http://www.example.com/blog/category/personal, you would supply http://www.example.com/blog/category/ as the scheme and, in that case, personal as the term.

  • label β€” optional. A human-readable version of the term.

πŸ“ content πŸ“

The actual, honest-to-goodness, body of the entry. This is like a "Text Construct", with a couple of extras.

In addition to the type values of a "Text Construct", you can also supply any MIME Type (except multipart types, which the Atom format specification forbids). If you specify a text/* type, the same rules apply as for text. If you pass a */xml or */*+xml type, the same rules apply as for xhtml (except in that case there is no wrapper <div> element). Any other type will be transported as Base64-encoded binary.

XXX Furthermore, you can supply a src key in place of the content key. In that case, the value of the src key should be a URL denoting the actual location of the content. FIXME This is not currently supported. XXX

Read that XXX/FIXME bit carefully, bestie β€” it's a real note, not decorative. 🚨

🀝 contributor 🀝

A "Person Construct" denoting a contributor to the feed or entry.

βš™οΈ generator βš™οΈ

The software used to generate the feed. Can be supplied as a string or as a hash with uri, version and name keys. Can also be undef to suppress the element entirely. If nothing is passed, defaults to reporting XML::Atom::SimpleFeed as the generator. Default generator: this module, being iconic. πŸ‘‘

πŸ–ΌοΈ icon πŸ–ΌοΈ

The URI of a small image whose width and height should be identical.

πŸ†” id πŸ†”

A URI that is a permanent, globally unique identifier for the feed or entry that MUST NEVER CHANGE.

You are encouraged to generate a UUID 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 urn:uuid:########-####-####-####-############ URI form.

If you do not specify an ID, the permalink will be used instead. This is unwise, as permalinks do unfortunately occasionally change. It is your responsibility to ensure that the permalink NEVER CHANGES. No cap: ID permanence is not a vibe, it's a rule.

A link element. You can either supply a bare string as the parameter, which will be used as the permalink URI, 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 URI should be unique. If you supply a hash, you can provide the following range of details in the given hash keys:

  • rel β€” optional. The link relationship. If omitted, defaults to alternate (note that you can only have one alternate link per feed/entry). Other permissible values are related, self, enclosure and via, as well as any URI.
  • href β€” required URL. Where the link points to.
  • type β€” optional. An advisory media type that provides a hint about the type of the resource pointed to by the link.
  • hreflang β€” optional. The language of the resource pointed to by the link, an RFC3066 language tag.
  • title β€” optional. Human-readable information about the link.
  • length β€” optional. A hint about the content length in bytes of the resource pointed to by the link.

The URI of an image that should be twice as wide as it is high.

πŸ—“οΈ published πŸ—“οΈ

A "Date Construct" denoting the moment in time when the entry was first published. This should never change.

βš–οΈ rights βš–οΈ

A "Text Construct" containing a human-readable statement of legal rights for the content of the feed or entry. This is not intended for machine processing.

πŸ’¬ subtitle πŸ’¬

A "Text Construct" containing an optional additional description of the feed.

πŸ“ summary πŸ“

A "Text Construct" giving a short summary of the entry.

πŸŽ€ title πŸŽ€

A "Text Construct" containing the title of the feed or entry.

⏰ updated ⏰

A "Date Construct" 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.


🧚 COMMON ATOM CONSTRUCTS 🧚

A number of Atom elements share a common structure. The following sections outline the data you can (or must) pass in each case.

πŸ—“οΈ Date Construct πŸ—“οΈ

A string denoting a date and time in W3CDTF format. You can generate those using something like

use POSIX 'strftime';
my $now = strftime '%Y-%m-%dT%H:%M:%SZ', gmtime;

However, you can also simply pass a Unix timestamp (a positive integer) or an object that responds to an epoch method call. (Make sure that the timezone reported by such objects is correct!) Timezone correctness check: mandatory vibe check. πŸ•°οΈ

The following datetime classes from CPAN are compatible with this interface:

  • Time::Piece
  • DateTime
  • Time::Moment
  • Panda::Date
  • Class::Date
  • Time::Object (an obsolete precursor to Time::Piece)
  • Time::Date (version 0.05 or newer)

The following are not:

  • DateTime::Tiny β€” This class lacks both an epoch method or any way to emulate one – as well as any timezone support in the first place. That makes it unsuitable in principle for use in Atom feeds – unless you have separate information about the timezone.
  • Date::Handler β€” This class has a suitable method… but sadly, calls it Epoch. So it is left up to you to call $dh->Epoch to pass such values.

πŸ§‘ Person Construct πŸ§‘

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:

  • name β€” required. The name of the person.
  • email β€” optional. The person's email address.
  • uri β€” optional. A URI to distinguish this person. This would usually be a homepage, but need not actually be a dereferencable URL.

πŸ“ Text Construct πŸ“

You can supply a string to Text Construct parameters, which will be used as the HTML content of the element.

FIXME details, text/html/xhtml

That FIXME is literally part of the manual, so we're keeping it, bestie. 🫑


πŸ”­ SEE ALSO πŸ”­

πŸ’€ BUGS AND LIMITATIONS πŸ’€

Okay bestie, let's do a vibe check on the messy parts, because there are messy parts and we're not gonna pretend otherwise. πŸ™ˆ Every single item here is officially "a bug" per the docs, so no cap.

  • In content elements, the src attribute cannot be used, and non-XML or non-text media types do not get Base64-encoded automatically. This is a bug. Not me crying over unencoded media types 😭
  • There are practically no tests. This is a bug. Yeah. Whole thing held together by vibes and hope, fr fr.
  • Support for xml:lang and xml:base 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. So like, don't hold your breath 🫢
  • 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. We stay unbothered πŸ’…
  • The source element is not and may never be supported. She said "not today, not ever" periodt.
  • Nothing is done to ensure that text constructs with type xhtml and entry contents using either that or an XML media type are well-formed. So far, this is by design. You should strongly consider using an XML writer if you want to include content with such types in your feed. Lowkey the most important one here β€” take it seriously πŸ”₯
The well-formedness thing is genuinely on you, bestie. If you're putting xhtml or XML-media-type content in, pleasepleaseplease reach for an XML writer. This is not a drill 🚨

✨ AUTHOR ✨

Aristotle Pagaltzis <pagaltzis@gmx.de>

Shoutout to the author, the literal main character of this module πŸ‘‘πŸ«Ά


This software is copyright (c) 2020 by Aristotle Pagaltzis.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Slay, honestly β€” free software ate and left no crumbs πŸ’–


And that's a wrap on the whole page, bestie! πŸ¦‹ You read <pink>perl v5.42.0</pink> docs dated <purple>2022-08-11</purple> for XML::At...mpleFeed(3) β€” iconic of you, honestly. Go forth and build feeds that are correct and well-formed. Mwah πŸ’‹πŸŒΈ

πŸ“¦ where this page comes from