Kenichi Ishigaki > XML-FeedWriter > XML::FeedWriter

Download:
XML-FeedWriter-0.06.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.06   Source  

NAME ^

XML::FeedWriter - simple RSS writer

SYNOPSIS ^

    use XML::FeedWriter;

    # let's create a writer.

    my $writer = XML::FeedWriter->new(

      # specify type/version; RSS 2.0 by default
      version     => '2.0',

      # and channel info
      title       => 'feed title',
      link        => 'http://example.com',
      description => 'blah blah blah',
    );

    # add as many items as you wish (and spec permits).

    $writer->add_items(
      # each item should be a hash reference
      {
        title       => 'first post',
        description => 'plain text of the first post',
        link        => 'http://example.com/first_post',
        updated     => time(),  # will be converted to a pubDate
        creator     => 'me',  # alias for "dc:creator"
      },
      {
        title       => 'second post',
        description => '<p>html of the second post</p>',
        link        => 'http://example.com/second_post',
        pubdate     => DateTime->now, # will be formatted properly
        creator     => 'someone',
      },
    );

    # this will close several tags such as root 'rss'.

    $writer->close;

    # then, if you want to save the feed to a file

    $writer->save('path_to_file.xml');

    # or just use it as an xml string.

    my $string = $writer->as_string;

DESCRIPTION ^

This is yet another simple feed writer. Not for parsing. Just to write. And as of 0.01, it only can write an RSS 2.0 feed. Then, what's the point?

XML::RSS does almost fine. But when you pass it a long html for description, you'll see a lot of &#x3C and the likes. I don't like that.

XML::FeedWriter also converts date/time information to a required format. You don't need to prepare a properly formatted date/time string by yourself.

And I'm too lazy to specify well-known modules or their namespaces again and again. Several aliases are provided such as 'creator' => 'dc:creator'.

In short, if you want completeness, use XML::RSS (or XML::Feed in that sense). If you're lazy, XML::FeedWriter may be a good option.

METHODS ^

new

Creates a writer object (actually, this returns an object of a subordinate class according to the version you specified).

Required (channel) elements may vary in the future but you usually need to specify:

version

RSS version. As of 0.01, only 2.0 and its aliases are supported, and will be set to 2.0 by default.

title

Feed title, which should match the name of your website.

link

URI of your website.

description

Feed description.

You may specify as many channel elements as you wish.

Some minor elements may require hash/array references to specify extra attributes or child elements. Basically, a hash reference will be considered as child elements, and an array reference will be considered as a value of the elements plus a hash of attributes, but there're exceptions. See appropriate pod for details.

XML::FeedWriter also accepts encoding option ('utf-8' by default) and no_cdata option, if you really care.

add_items

Adds items to the feed. Each item should be a hash reference, and characters are expected to be Encode::decoded perl strings.

close

Closes several known tags such as 'rss' and 'channel'.

save

Saves the feed to a file. The feed will be Encode::encoded. So, if you really want to use octets while adding items, avoid this and save the result of as_string by yourself.

as_string

Returns the feed as a string. This is supposed to be a (Encode::decoded) perl string but actually this doesn't care if the string is flagged or not.

SEE ALSO ^

XML::FeedWriter::RSS20

XML::RSS, XML::Feed, XML::Writer

AUTHOR ^

Kenichi Ishigaki, <ishigaki@cpan.org>

COPYRIGHT AND LICENSE ^

Copyright (C) 2008 by Kenichi Ishigaki.

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

syntax highlighting: