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

NAME

Data::Feed - Extensible Feed Parsing Tool

SYNOPSIS

  use Data::Feed;

  # from a file
  $feed = Data::Feed->parse( '/path/to/my/feed.xml' );

  # from an URI
  $feed = Data::Feed->parse( URI->new( 'http://example.com/atom.xml' ) );

  # from a string
  $feed = Data::Feed->parse( \$feed );

  # from a handle
  $feed = Data::Feed->parse( $fh );

  # Data::Feed auto-guesses the type of a feed by its contents, but you can
  # explicitly tell what parser to use

  $feed = Data::Feed->new( parser => $myparser )->parse(...);

DESCRIPTION

Data::Feed is a frontend for feeds. It will attempt to auto-guess what type of feed you are passing it, and will generate the appropriate feed object.

What, another XML::Feed? Yes, but this time it's extensible. It's cleanly OO (until you get down to the XML nastiness), and it's easy to add your own parser to do whatever you want it to do.

STRUCTURE

Data::Feed has a fairly simple structure. The first layer is a "dynamic" parser -- "dynamic" in that Data::Feed will try to find what the feed is, and then create the appropriate parser to parse it.

This is done in Data::Feed->find_parser() and Data::Feed->guess_format(). By default we recognize RSS and Atom feeds. Should the need arise to either provide a custom parser or to provide more refined logic to find a parser type, override the respective method and do what you will with it.

The second layer is a thin wrapper around RSS and Atom feed objects. We use XML::RSS::LibXML (or XML::RSS) and XML::Atom for this purpose.

PARSING FEEDS

Data::Feed can parse files, URIs, raw strings, and file handles. All you need to do is to pass an appropriate parameters.

For file names, we expect a plain scalar:

  Data::Feed->parse( '/path/to/feed.xml' );

For URI, pass in an URI object:

  Data::Feed->parse( URI->new("http://example.com/feed.xml") );

For raw strings, pass in a scalar ref:

  Data::Feed->parse( \qq{<?xml version="1.0"><feed> .... </feed>} );

For file handles, pass in a glob:

  open(my $fh, '<', '/path/to/feed.xml' );
  Data::Feed->parse( $fh );

METHODS

parse($stream)

find_parser($stream)

Attempts to find an appropriate parser for the given stream.

guess_format($stream)

fetch_stream($stream)

parse_datetime($datetime_string)

Parses a datetime string, first trying DateTime::Format::ISO8601, then DateTime::Format::Flexible, and finally DateTime::Format::Natural. The first one to succeed will have its value returned. If none succeeds, it returns undef. Used by the format classes to create the values returned by the issued() and modified() methods.

parse_w3cdtf_date($datetime_string)

Like parse_datetime(), but tries parsing the string with DateTime::Format::W3CDTF before falling back on parse_datetime().

parse_mail_date($datetime_string)

Like parse_datetime(), but tries parsing the string with DateTime::Format::Mail before falling back on parse_datetime().

TODO

Be able to /set/ enclosures (We can already get enclosures).

AUTHORS

Daisuke Maki <daisuke@endeworks.jp>

Taro Funaki <t@33rpm.jp>

A /Lot/ of the code is based on code from XML::Feed.

LICENSE

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

See http://www.perl.com/perl/misc/Artistic.html