Template::Plugin::XML::Feed - Plugin interface to XML::Feed


Template-Plugin-XML-Feed documentation Contained in the Template-Plugin-XML-Feed distribution.

Index


Code Index:

NAME

Top

Template::Plugin::XML::Feed - Plugin interface to XML::Feed

SYNOPSIS

Top

    [% USE news = XML.Feed('news.rdf') %]

    [% FOREACH item IN news.items %]
       [% item.title %]
       [% item.link  %]
    [% END %]

DESCRIPTION

Top

This Template Toolkit plugin provides a simple interface to the XML::Feed module.

    [% USE news = XML.Feed('mysite.rdf') %]

It creates an XML::Feed object, which is then used to parse the RSS or Atom file specified as a parameter in the USE directive. A reference to the XML::Feed object is then returned.

The attributes of the channel and image elements can be retrieved directly from the plugin object using the familiar dotted compound notation:

    [% news.channel.title  %]
    [% news.channel.link   %]
    [% news.channel.etc... %]  

    [% news.image.title    %]
    [% news.image.url      %]
    [% news.image.link     %]
    [% news.image.etc...   %]  

The list of news items can be retrieved using the 'items' method:

    [% FOREACH item IN news.items %]
       [% item.title %]
       [% item.link  %]
    [% END %]

METHODS

Top

new

Constructor method. Delegates to XML::Feed->parse to create an XML::Feed object. Not usually called directly.

AUTHORS

Top

This plugin was written by Dave Cross and was heavily based on the code for Template::Plugin::XML::RSS by Andy Wardley.

The XML::Feed module, which implements all of the functionality that this plugin delegates to, was written by Benjamin Trott and is now maintained by Simon Wardley.

COPYRIGHT AND LICENCE

Top

SEE ALSO

Top

Template::Plugin, XML::Feed


Template-Plugin-XML-Feed documentation Contained in the Template-Plugin-XML-Feed distribution.

package Template::Plugin::XML::Feed;

use strict;
use warnings;
use base 'Template::Plugin';
use XML::Feed;

our $VERSION = 0.01;

sub new {
  my ($class, $context, $filename) = @_;

  return $class->fail('No filename specified')
    unless $filename;
    
  my $feed = XML::Feed->parse($filename)
    or return $class->error('failed to create XML::Feed');

  return $feed;
}

1;

__END__