| 1 | # $Id$ |
|---|
| 2 | |
|---|
| 3 | package Data::Feed::RSS; |
|---|
| 4 | use Moose; |
|---|
| 5 | use DateTime::Format::Mail; |
|---|
| 6 | use DateTime::Format::W3CDTF; |
|---|
| 7 | |
|---|
| 8 | with 'Data::Feed::Feed'; |
|---|
| 9 | |
|---|
| 10 | __PACKAGE__->meta->make_immutable; |
|---|
| 11 | |
|---|
| 12 | no Moose; |
|---|
| 13 | |
|---|
| 14 | sub format { 'RSS ' . $_[0]->feed->{'version'} } |
|---|
| 15 | |
|---|
| 16 | ## The following elements are the same in all versions of RSS. |
|---|
| 17 | sub title { shift->feed->channel('title', @_) } |
|---|
| 18 | sub link { shift->feed->channel('link', @_) } |
|---|
| 19 | sub description { shift->feed->channel('description', @_) } |
|---|
| 20 | |
|---|
| 21 | ## This is RSS 2.0 only--what's the equivalent in RSS 1.0? |
|---|
| 22 | sub copyright { shift->feed->channel('copyright', @_) } |
|---|
| 23 | |
|---|
| 24 | ## The following all work transparently in any RSS version. |
|---|
| 25 | sub language { |
|---|
| 26 | my $feed = shift->feed; |
|---|
| 27 | |
|---|
| 28 | if (@_) { |
|---|
| 29 | $feed->channel('language', $_[0]); |
|---|
| 30 | $feed->channel->{dc}{language} = $_[0]; |
|---|
| 31 | } |
|---|
| 32 | else { |
|---|
| 33 | $feed->channel('language') || |
|---|
| 34 | $feed->channel->{dc}{language}; |
|---|
| 35 | } |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | sub generator { |
|---|
| 39 | my $feed = shift->feed; |
|---|
| 40 | |
|---|
| 41 | if (@_) { |
|---|
| 42 | $feed->channel('generator', $_[0]); |
|---|
| 43 | $feed->channel->{'http://webns.net/mvcb/'}{generatorAgent} = |
|---|
| 44 | $_[0]; |
|---|
| 45 | } |
|---|
| 46 | else { |
|---|
| 47 | $feed->channel('generator') || |
|---|
| 48 | $feed->channel->{'http://webns.net/mvcb/'}{generatorAgent}; |
|---|
| 49 | } |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | sub author { |
|---|
| 53 | my $feed = shift->feed; |
|---|
| 54 | |
|---|
| 55 | if (@_) { |
|---|
| 56 | $feed->channel('webMaster', $_[0]); |
|---|
| 57 | $feed->channel->{dc}{creator} = $_[0]; |
|---|
| 58 | } |
|---|
| 59 | else { |
|---|
| 60 | $feed->channel('webMaster') || |
|---|
| 61 | $feed->channel->{dc}{creator}; |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | sub modified { |
|---|
| 66 | my $feed = shift->feed; |
|---|
| 67 | |
|---|
| 68 | if (@_) { |
|---|
| 69 | $feed->channel('pubDate', |
|---|
| 70 | DateTime::Format::Mail->format_datetime($_[0])); |
|---|
| 71 | ## XML::RSS is so weird... if I set this, it will try to use |
|---|
| 72 | ## the value for the lastBuildDate, which I don't want--because |
|---|
| 73 | ## this date is formatted for an RSS 1.0 feed. So it's commented out. |
|---|
| 74 | #$rss->channel->{dc}{date} = |
|---|
| 75 | # DateTime::Format::W3CDTF->format_datetime($_[0]); |
|---|
| 76 | } else { |
|---|
| 77 | my $date; |
|---|
| 78 | eval { |
|---|
| 79 | if (my $ts = $feed->channel('pubDate')) { |
|---|
| 80 | $date = DateTime::Format::Mail->parse_datetime($ts); |
|---|
| 81 | } elsif ($ts = $feed->channel->{dc}{date}) { |
|---|
| 82 | $date = DateTime::Format::W3CDTF->parse_datetime($ts); |
|---|
| 83 | } |
|---|
| 84 | }; |
|---|
| 85 | return $date; |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | sub entries { |
|---|
| 90 | my $feed = $_[0]->feed; |
|---|
| 91 | my @entries; |
|---|
| 92 | for my $item (@{ $feed->{items} }) { |
|---|
| 93 | push @entries, Data::Feed::RSS::Entry->new( item => $item ); |
|---|
| 94 | } |
|---|
| 95 | @entries; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | sub add_entry { |
|---|
| 99 | my $feed = shift->feed; |
|---|
| 100 | my($entry) = @_; |
|---|
| 101 | $feed->add_item(%{ $entry->unwrap }); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | 1; |
|---|
| 105 | |
|---|
| 106 | __END__ |
|---|
| 107 | |
|---|
| 108 | =head1 NAME |
|---|
| 109 | |
|---|
| 110 | Data::Feed::RSS - RSS Feed |
|---|
| 111 | |
|---|
| 112 | =head1 METHODS |
|---|
| 113 | |
|---|
| 114 | =head2 add_entry |
|---|
| 115 | |
|---|
| 116 | =head2 as_xml |
|---|
| 117 | |
|---|
| 118 | =head2 author |
|---|
| 119 | |
|---|
| 120 | =head2 copyright |
|---|
| 121 | |
|---|
| 122 | =head2 description |
|---|
| 123 | |
|---|
| 124 | =head2 entries |
|---|
| 125 | |
|---|
| 126 | =head2 format |
|---|
| 127 | |
|---|
| 128 | =head2 generator |
|---|
| 129 | |
|---|
| 130 | =head2 language |
|---|
| 131 | |
|---|
| 132 | =head2 link |
|---|
| 133 | |
|---|
| 134 | =head2 modified |
|---|
| 135 | |
|---|
| 136 | =head2 title |
|---|
| 137 | |
|---|
| 138 | =cut |
|---|
| 139 | |
|---|