The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

XML::Generator::RSS10 - Generate SAX events for RSS

VERSION

version 0.02

SYNOPSIS

    use XML::Generator::RSS10;

    my $rss = XML::Generator::RSS10->new( Handler => $sax_handler );

    $rss->item( title => 'Exciting News About my Pants!',
                link  => 'http://pants.example.com/my/news.html',
                description => 'My pants are full of ants!',
              );

    $rss->channel( title => 'Pants',
                   link  => 'http://pants.example.com/',
                   description => 'A fascinating pants site',
                 );

DESCRIPTION

This module generates SAX events which will create an RSS 1.0 document, based on easy to use RSS-related methods like item() and channel().

METHODS

new

This is the constructor for this class.

It takes several parameters, though only one, "Handler", is required:

  • Handler

    This should be a SAX2 handler. If you are looking to write RSS to a file or store it in a string, you probably want to use XML::SAX::Writer.

    This parameter is required.

  • pretty

    If this is true, the generated XML document will include extra spaces and newlines in an effort to make it look pretty. This defaults to false.

  • modules

    This parameter can be used to make additional RSS 1.0 modules available when creating a feed. It should be an array reference to a list of module prefixes.

    You can specify any prefix you like, and this module will try to load a module named XML::Generator::RSS10::<prefix>.

    This module comes with support for the core RSS 1.0 modules, which are Content (content), Dublin Core (dc), and Syndication (sy). It also include a module supporting the proposed Administrative (admin) and Creative Commons (cc) modules. See the docs for XML::Generator::RSS10::content, XML::Generator::RSS10::dc, XML::Generator::RSS10::sy, XML::Generator::RSS10::admin, and XML::Generator::RSS10::cc for details on how to use them.

    The Dublin Core and Syndication modules are loaded by default if this parameter is not specified.

The constructor begins the RSS document and returns a new XML::Generator::RSS10 object.

item

This method is used to add item elements to the document. It accepts the following parameters:

  • title

    The item's title. Required.

  • link

    The item's link. Required.

  • description

    The item's link. Optional.

    This element will be formatted as CDATA since many people like to put HTML in it.

image

This method is used to add an image element to the document. It may only be called once. It accepts the following parameters:

  • title

    The image's title. Required.

  • link

    The image's link. Required.

  • url

    The image's URL. Required.

textinput

This method is used to add an textinput element to the document. It may only be called once. It accepts the following parameters:

  • title

    The textinput's title. Required.

  • description

    The textinput's description. Required.

  • name

    The textinput's name. Required.

  • url

    The textinput's URL. Required.

channel

This method is used add the channel element to the document. It also finishes the document. You must have added at least one item to the document prior to calling this method.

You may not call any other methods after this one is called.

  • title

    The channel's title. Required.

  • link

    The channel's link. Required.

  • description

    The channel's description. Required.

    This element will be formatted as CDATA since many people like to put HTML in it.

RSS 1.0 MODULES

To add module output to a document, you can pass extra hash keys when calling any of the output-generating methods. The extra keys should be the module prefixes, and the values should be something expected by the relevant module.

For example, to add some Dublin Core elements to the channel element, you can write this:

    $rss->channel( title => 'Pants',
                   link  => 'http://pants.example.com/',
                   description => 'A fascinating pants site',
                   dc    => { publisher => 'The Pants People',
                              rights    => 'Mine, all mine!',
                              date      => $date,
                            },
                 );

The values for the "dc" key will be passed to XML::Generator::RSS10::dc, which will add them to the output stream appropriately.

XML::Generator::RSS10 VERSUS XML::RSS

This module is less flexible than XML::RSS in many ways. However, it does have two features that XML::RSS does not provide:

  • Because it generates SAX events, this module can be used to write a document to a handle as a stream. XML::RSS requires you to create the entire document in memory first.

  • It has support for arbitrary RSS 1.0 modules, including ones you create.

However, if you don't need any of these features you may be better off using XML::RSS instead.

BUGS

Please report any bugs or feature requests to bug-xml-generator-rss10@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

AUTHOR

Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2011 by Dave Rolsky.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)