XML::RAI - RSS Abstraction Interface.
# Copyright (c) 2004-2009 Timothy Appnel
# http://appnel.com/
# This code is released under the Artistic License.
#
# XML::RAI - RSS Abstraction Interface.
#
package XML::RAI;
use strict;
use vars qw($VERSION);
$VERSION = 1.3031;
use XML::RSS::Parser 4.0;
use XML::RAI::Channel;
use XML::RAI::Item;
use XML::RAI::Image;
use constant W3CDTF => '%Y-%m-%dT%H:%M:%S%z'; # AKA...
use constant RFC8601 => W3CDTF;
use constant RFC822 => '%a, %d %b %G %T %Z';
use constant PASS_THRU => '';
use constant EPOCH => 'EPOCH';
sub new {
my $class = shift;
my $self = bless {}, $class;
$self->init(@_);
$self;
}
sub init {
my $self = shift;
my $doc;
unless (ref($_[0]) eq 'XML::RSS::Parser::Feed') {
my ($method, @r) = @_;
my $parser = XML::RSS::Parser->new;
$doc = $parser->$method(@r) or die $parser->errstr;
}
else {
$doc = shift;
}
$self->{__doc} = $doc;
my $channel = $self->{__channel} =
XML::RAI::Channel->new($doc->channel, $self);
my @items = map { XML::RAI::Item->new($_, $channel) } $doc->items;
$self->{__items} = \@items;
my @imgs = $doc->image; # fix multiple image bug ala slashdot.
$self->{__image} = XML::RAI::Image->new($imgs[0], $channel)
if $doc->image;
$self->{__timef} = W3CDTF;
}
sub time_format {
$_[0]->{__timef} = $_[1] if defined $_[1];
$_[0]->{__timef};
}
sub parse {
my $class = shift;
if (ref($_[0]) eq 'GLOB') { # is filehandle
$class->parse_file(@_);
}
else { # is string
$class->parse_string(@_);
}
}
sub parsefile {
my $class = shift;
$class->new('parse_file', @_) or die $class->errstr;
}
*parse_file = \&parsefile;
sub parse_string {
my $class = shift;
$class->new('parse_string', @_) or die $class->errstr;
}
sub parse_uri {
my $class = shift;
$class->new('parse_uri', @_) or die $class->errstr;
}
sub document { $_[0]->{__doc}; }
sub channel { $_[0]->{__channel}; }
sub items { $_[0]->{__items}; }
sub item_count { scalar @{$_[0]->{__items}}; }
sub image { $_[0]->{__image}; }
1;
__END__