RSS and Atom feeds in Catalyst

The Catalyst cookbook provides two recommendations for adding RSS feeds to your application:

  1. Create an XML template, populate the stash with data, let your template view render it, then override the Content-Type: header of your view with Catalyst::Response.
  2. Use an XML::* feed module to render the XML, manually set the Catalyst::Response body, then set the Content-Type: header.

The former almost makes me angry, and the latter, although saner, puts view-specific responsibilities on the shoulders of the Controller.

Catalyst::View::XML::Feed

Catalyst::View::XML::Feed is an attempt at something cleaner, and more in the spirit of MVC, which makes the nitty-gritty details of presentation entirely the responsibility of the view. Using it is pretty much what you would expect from any view:

  • Put your data in $c->stash->{feed}
  • Forward to your View::Feed (or whatever you called your Catalyst::View::XML::Feed subclass)

It attempts to be as intelligent as possible, allowing you to supply data in a wide range of formats to the feed value in the stash. These can be XML::* Atom or RSS objects, custom objects, plain hashrefs of values, etc.

As always, any recommendations or other feedback are warmly welcomed.

Leave a comment

About Mark A. Stratman

user-pic Perl developer, forever trapped in the DarkPAN