1 # $Id: RSS.pm,v 1.3 2004/05/30 09:39:52 btrott Exp $
3 package XML::Feed::RSS;
6 use base qw( XML::Feed );
8 use DateTime::Format::Mail;
9 use DateTime::Format::W3CDTF;
14 my $rss = $feed->{rss} = XML::RSS->new;
21 sub format { 'RSS ' . $_[0]->{rss}->{'version'} }
23 ## The following elements are the same in all versions of RSS.
24 sub title { $_[0]->{rss}->channel('title') }
25 sub link { $_[0]->{rss}->channel('link') }
26 sub description { $_[0]->{rss}->channel('description') }
28 ## This is RSS 2.0 only--what's the equivalent in RSS 1.0?
29 sub copyright { $_[0]->{rss}->channel('copyright') }
31 ## The following all work transparently in any RSS version.
33 $_[0]->{rss}->channel('language') ||
34 $_[0]->{rss}->channel->{dc}{language}
38 $_[0]->{rss}->channel('generator') ||
39 $_[0]->{rss}->channel->{'http://webns.net/mvcb/'}{generatorAgent};
43 $_[0]->{rss}->channel('webMaster') ||
44 $_[0]->{rss}->channel->{dc}{creator};
48 my $rss = $_[0]->{rss};
49 if (my $ts = $rss->channel('pubDate')) {
50 return DateTime::Format::Mail->parse_datetime($ts);
51 } elsif ($ts = $rss->channel->{dc}{date}) {
52 return DateTime::Format::W3CDTF->parse_datetime($ts);
57 my $rss = $_[0]->{rss};
59 for my $item (@{ $rss->{items} }) {
60 push @entries, XML::Feed::RSS::Entry->wrap($item);
65 package XML::Feed::RSS::Entry;
68 use base qw( XML::Feed::Entry );
70 sub title { $_[0]->{entry}{title} }
71 sub link { $_[0]->{entry}{link} }
72 sub summary { $_[0]->{entry}{description} }
75 my $item = $_[0]->{entry};
76 $_[0]->{entry}{'http://purl.org/rss/1.0/modules/content/'}{encoded} ||
77 $_[0]->{entry}{'http://www.w3.org/1999/xhtml'}{body} ||
78 $_[0]->{entry}{description};
82 $_[0]->{entry}{category} || $_[0]->{entry}{dc}{subject};
86 $_[0]->{entry}{author} || $_[0]->{entry}{dc}{creator};
89 ## XML::RSS doesn't give us access to the rdf:about for the <item>,
90 ## so we have to fall back to the <link> element in RSS 1.0 feeds.
92 $_[0]->{entry}{guid} || $_[0]->{entry}{link};
96 if (my $ts = $_[0]->{entry}{pubDate}) {
97 return DateTime::Format::Mail->parse_datetime($ts);
98 } elsif ($ts = $_[0]->{entry}{dc}{date}) {
99 return DateTime::Format::W3CDTF->parse_datetime($ts);
104 if (my $ts = $_[0]->{entry}{'http://purl.org/rss/1.0/modules/dcterms/'}{modified}) {
105 return DateTime::Format::W3CDTF->parse_datetime($ts);