The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

OpenInteract2::Action::RSS - OpenInteract2 action type for displaying RSS feeds

SYNOPSIS

# Define the action type in your server configuration

# In '$WEBSITE/conf/server.ini' (do this once per site)

[action_types]
...
rss = OpenInteract2::Action::RSS

# Define the action that will use a RSS feed

# In your package's 'conf/action.ini'

[myaction]
action_type  = rss
feed_url     = http://somesite/rss.xml
title        = My Feed
template     = mypackage::myfeed
cache_expire = 180m

# Another example of an action:
# Pull from a local file, grab the 'title' from the feed, use the
# default template, and don't do any caching (NOT RECOMMENDED)

[myaction]
action_type = rss
feed_url    = file:///home/httpd/mysite/html/feeds/rss.xml

# Sample Template Toolkit Template displaying the feed

<h3>[% title %]</h3>
[% FOREACH entry = feed.entries -%]
- [% OI.date_format( entry.issued, '%b %d, %r' ) %]:
    <a href="[% entry.link %]">[% entry.title %]</a><br />
[% END -%]

DESCRIPTION

This module defines an OpenInteract2 action type. An action type is a class that can generally be instantiated through configuration only -- in this case we can define a component that fetches and displays an RSS feed without writing any code. (See OpenInteract2::Action for details on action types.)

Executing the action will ask XML::Feed to retrieve the RSS/Atom feed for us and parse it into an object. That object is passed to your template as 'feed' and you can then iterate over the items in the feed (with the entries() method). See the XML::Feed docs for more.

OBJECT METHODS

process()

Retrieve the feed from the given location or cache, parse it and send it to a template. The parameters you can use to control this are:

feed_url (required)

URL from which we fetch the RSS/Atom. If you are fetching the feed using other means and want to retrieve it locally you can use a 'file://' URL as well.

template (optional)

Template to which we send feed data to generate the content. If you do not specify we use a default (listed below).

title (optional)

Title to use for feed in template. If you do not specify this or 'title_key' we pull the title from the feed.

title_key (optional)

Message key to use for the title. (See OpenInteract2::I18N.)

num_display (optional)

Number of entries to display. Defaults to displaying all.

Default template

Here is the default TT template we use:

[%- rss_display_cap = OI.action_param( 'num_display' ) || feed.entries.size;
    count = 0; -%]
<h3>[% title %]</h3>
[% FOREACH entry = feed.entries;
       IF count < rss_display_cap; -%]
 - [% OI.date_format( entry.issued, '%b %d, %r' ) %]:
   <a href="[% entry.link %]">[% entry.title %]</a><br />
[%     END;
       count = count + 1;
   END -%]

To use your own specify a 'template' parameter in the action. This template name should be in the normal 'package::template' format.

SEE ALSO

XML::Feed

COPYRIGHT

Copyright (c) 2004 Chris Winters. All rights reserved.

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

AUTHORS

Chris Winters <chris@cwinters.com>