NAME

XML::Atom::SimpleFeed - Generate simple Atom syndication feeds

SYNOPSIS

    use XML::Atom::SimpleFeed;

    # Create the feed object
    my $atom = XML::Atom::SimpleFeed->new(
        title    => "My Atom Feed",
        link     => "http://www.example.com/blog/",
        modified => "2005-02-18T15:00:00Z",
        tagline => "This is an example feed.  Nothing to see here.  Move along."
    );

    # Add an entry to the feed
    $atom->add_entry(
        title    => "A Sample Entry",
        link     => "http://www.example.com/blog/entries/1234",
        author   => { name => "J. Random Hacker", email => 'jrh@example.com' },
        modified => "2005-02-18T16:45:00Z",
        issued   => "2005-02-18T15:30:00Z",
        content  => "This is the body of the entry"
    );

    # Add a more complicated entry
    $atom->add_entry(
        title => 'A more complicated example.',
        link  => [
            {
                rel  => 'alternate',
                href => 'http://www.example.com/blog/entries/1337',
                type => 'text/html'
            },
            {
                rel  => 'start',
                href => 'http://www.example.com/blog/entries/1',
                type => 'text/html'
            }
        ],
        author => {
            name  => 'Foo Bar',
            url   => 'http://www.example.com/foobar/',
            email => 'foo@example.com'
        },

        copyright => 'Copyright 2005 by Foo Bar Inc.',
        generator => 'Elite Blogs LLP',
        subject   => 'Technology',
        content   => 'I have nothing to say now.'
    );

    # Print out the feed
    $atom->print;

DESCRIPTION

This module exists to generate basic Atom syndication feeds. While it does not provide a full, object-oriented interface into all the nooks and crannies of Atom feeds, an Atom parser, or an Atom client API, it should be useful for people who want to generate basic, valid Atom feeds of their content quickly and easily.

The module should, by default, allow you to produce valid Atom feeds by supplying simple strings to fill in most structures. However, you can provide more advanced structures (hashes, arrays) to do more advanced things if you need to. Check the docs to see which options take more complex datatypes.

METHODS

my $atom = XML::Atom::SimpleFeed->new(%args);

This creates a new XML::Atom::SimpleFeed objects with the supplied parameters. The parameters are supplied as a hash. Some parameters are required, some are optional. For many fields, the default is to encode the item as escaped HTML, so that you don't accidentally produce invalid feeds by including an HTML tag. They are:

  • title

    REQUIRED (string/hash). The title of the Atom feed. If supplied as a string, it will be equivalent to the hash { mode => 'escaped', type => 'text/html', content => $string }. You can override this by supplying an anonymous hash with those fields defined.

  • link

    REQUIRED (string/hash/array). The URL link of the Atom feed. Normally points to the home page of the resource you are syndicating. If supplied as a string, it will be given the parameters rel=alternate, type=text/html. If supplied as a hash, you must provide the keys for rel=alternate, the href, and the type ( such as link => { rel=>'alternate', href=>'http://www.example.com/', type=>'text/plain'} ). If supplied as an array, must be an array of hashes, each hash providing the rel, href, and type, and at least one being rel=alternate.

  • modified

    OPTIONAL (string). The date the feed was last modified in W3CDTF format. This is a REQUIRED element in the Atom spec, but if you do not supply it, the current date and time will be used.

  • tagline

    OPTIONAL (string/hash). A description or tagline for the feed. If supplied as a string, it will be equivalent to the hash { mode => 'escaped', type => 'text/html', content => $string }. You can override this by supplying an anonymous hash with those fields defined.

  • generator

    OPTIONAL (string/hash). The software agent used to generate the feed. Can be supplied as a string, or a hash providing a URL, version, and content. If not supplied, will be set to the hash { url => 'http://search.cpan.org/dist/XML-Atom-SimpleFeed', version => $XML::Atom::SimpleFeed::VERSION, content => 'XML::Atom::SimpleFeed' }

  • copyright

    OPTIONAL (string/hash). The copyright string for the feed. If supplied as a string, it will be equivalent to the hash { mode => 'escaped', type => 'text/html', content => $string }. You can override this by supplying an anonymous hash with those fields defined.

  • info

    OPTIONAL (string/hash). A human-readable explanation of the feed format itself. If supplied as a string, it will be equivalent to the hash { mode => 'escaped', type => 'text/html', content => $string }. You can override this by supplying an anonymous hash with those fields defined.

  • id

    OPTIONAL (string). A permanent, globally unique identifier for the feed.

  • author

    OPTIONAL (hash). An anonymous hash of information about the author of the feed. If this element exists, it will be used to provide author information for a feed entry, if no author information was provided for the entry. The author hash contains the following information:

    • name

      REQUIRED (string). The name of the author ("J. Random Hacker")

    • email

      OPTIONAL (string). The email address of the author ("jrh@example.com")

    • url

      OPTIONAL (string). The URL of the author ("http://www.example.com/jrh/")

$atom->add_entry(%args);

This method adds an entry into the atom feed. Its arguments are supplied as a hash, with the following keys:

  • title

    REQUIRED (string/hash). The title of the entry. If supplied as a string, it will be equivalent to the hash { mode => 'escaped', type => 'text/html', content => $string }. You can override this by supplying an anonymous hash with those fields defined.

  • link

    REQUIRED (string/hash/array). The URL link of the entry itself. Should be unique to ensure valid feeds. If supplied as a string, it will be given the parameters rel=alternate, type=text/html. If supplied as a hash, you must provide the keys for rel=alternate, the href, and the type ( such as link => { rel=>'alternate', href=>'http://www.example.com/', type=>'text/plain'} ). If supplied as an array, must be an array of hashes, each hash providing the rel, href, and type, and at least one being rel=alternate.

  • author

    OPTIONAL/REQUIRED (hash). A hash of information about the author of the entry. You may only omit this if you have specified author information for the feed itself.

    • name

      REQUIRED (string). The name of the author ("J. Random Hacker")

    • email

      OPTIONAL (string). The email address of the author ("jrh@example.com")

    • url

      OPTIONAL (string). The URL of the author ("http://www.example.com/jrh/")

  • id

    OPTIONAL (string). Optional with a caveat. This is the globally unique identifier for the feed. It should be a string that does not change. If the id is not provided, the module will attempt to construct one via the link parameter, based on the Mark Pilgrim method. For more information about generating unique ids in Atom, see http://diveintomark.org/archives/2004/05/28/howto-atom-id

  • issued

    OPTIONAL (string). The date and time the entry was first published, in W3CDTF format. A REQUIRED part of the Atom spec. Should be set once and not changed (if the feed changes, use the modified parameter below). If this parameter is not provided, the current date and time will be used.

  • modified

    OPTIONAL (string). The date and time the entry was last modified, in W3CDTF format. A REQUIRED part of the Atom spec. This is the date you will change if the contents of the feed are modified. If this parameter is not provided, the current date and time will be used.

  • created

    OPTIONAL (string). The date and time the entry was created (differs from "issued" and "modified"), in W3CDTF format. May often be, but is not necessarily, the same time the entry was issued.

  • summary

    OPTIONAL (string/hash). A short summary of the entry. If supplied as a string, it will be equivalent to the hash { mode => 'escaped', type => 'text/html', content => $string }. You can override this by supplying an anonymous hash with those fields defined.

  • subject

    OPTIONAL (string). The subject of the entry. Part of Dublin Core.

  • content

    OPTIONAL (string/hash). The actual, honest-to-goodness, body of the entry. If supplied as a string, it will be equivalent to the hash { mode => 'escaped', type => 'text/html', content => $string }. You can override this by supplying an anonymous hash with those fields defined.

$atom->as_string();

Returns the text of the atom feed as a scalar.

$atom->print();

Outputs the full atom feed to STDOUT;

$atom->save_file($file);

Saves the full atom feed into the file referenced by $file. If $file is a open filehandle, the output will go there. Otherwise, $file is taken to be the name of a file which should be written to. Returns true on success.

BUGS

Most likely does not implement all the useful features of an Atom feed. Comments and patches welcome!

SEE ALSO

XML::Atom http://search.cpan.org/dist/XML-Atom/

XML::Simple http://search.cpan.org/dist/XML-Simple/

Atom Enabled http://www.atomenabled.org/

W3CDTF Spec http://www.w3.org/TR/NOTE-datetime

AUTHOR

H. Wade Minter, <minter@lunenburg.org> http://www.lunenburg.org/

CREDITS

Aristotle Pagaltzis, for suggestions on making the module much better behaved.

COPYRIGHT AND LICENSE

Copyright 2005 by H. Wade Minter

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 485:

You forgot a '=back' before '=head1'