XML::FeedWriter - simple RSS writer
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;
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 < 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.
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:
RSS version. As of 0.01, only 2.0 and its aliases are supported, and will be set to 2.0 by default.
Feed title, which should match the name of your website.
URI of your website.
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.
encoding
no_cdata
Adds items to the feed. Each item should be a hash reference, and characters are expected to be Encode::decoded perl strings.
Encode::decode
Closes several known tags such as 'rss' and 'channel'.
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.
Encode::encode
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.
XML::FeedWriter::RSS20
XML::RSS, XML::Feed, XML::Writer
Kenichi Ishigaki, <ishigaki@cpan.org>
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.
To install XML::FeedWriter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XML::FeedWriter
CPAN shell
perl -MCPAN -e shell install XML::FeedWriter
For more information on module installation, please visit the detailed CPAN module installation guide.