Skip to content
Browse files

Add support for RFC 5005 Feed Paging and Archiving in Atom feeds

  • Loading branch information...
1 parent e46a668 commit 02de179025c30a980577c721afb8713c27851c74 @nichtich nichtich committed
Showing with 94 additions and 7 deletions.
  1. +4 −0 Changes
  2. +39 −0 lib/XML/Feed.pm
  3. +25 −7 lib/XML/Feed/Format/Atom.pm
  4. +8 −0 lib/XML/Feed/Format/RSS.pm
  5. +18 −0 t/02-create.t
View
4 Changes
@@ -1,3 +1,7 @@
+2012-04-10 Jakob Voss <voss@gbv.de>
+
+ * Add support for RFC 5005 Feed Paging and Archiving in Atom feeds
+
2012-04-05 Dave Cross <dave@dave.org.uk>
* lib/XML/Feed.pm: Remove svn tag.
View
39 lib/XML/Feed.pm
@@ -167,6 +167,15 @@ sub id;
sub tagline { shift->description(@_) }
sub items { $_[0]->entries }
+# RFC 5005
+sub first_link;
+sub last_link;
+sub previous_link;
+sub next_link;
+sub current_link;
+sub prev_archive_link;
+sub next_archive_link;
+
1;
__END__
@@ -350,6 +359,36 @@ object in the correct format for the feed.
Returns an XML representation of the feed, in the format determined by
the current format of the I<$feed> object.
+=head2 $feed->first_link ([ $uri ])
+
+The Atom First-link for feed paging and archiving (RFC 5005).
+
+L<http://tools.ietf.org/html/rfc5005>
+
+=head2 $feed->last_link ([ $uri ])
+
+The Atom Last-link for feed paging and archiving.
+
+=head2 $feed->next_link ([ $uri ])
+
+The Atom Next-link for feed paging and archiving.
+
+=head2 $feed->previous_link ([ $uri ])
+
+The Atom Previous-link for feed paging and archiving.
+
+=head2 $feed->current_link ([ $uri ])
+
+The Atom Current-link for feed paging and archiving.
+
+=head2 $feed->next_archive_link ([ $uri ])
+
+The Atom Next-link for feed paging and archiving.
+
+=head2 $feed->prev_archive_link ([ $uri ])
+
+The Atom Prev-Archive-link for feed paging and archiving.
+
=head1 PACKAGE VARIABLES
=over 4
View
32 lib/XML/Feed/Format/Atom.pm
@@ -56,25 +56,43 @@ sub link {
}
}
-sub self_link {
+sub _rel_link {
my $feed = shift;
+ my $rel = shift;
if (@_) {
my $uri = shift;
- $feed->{atom}->add_link({type => "application/atom+xml", rel => "self", href => $uri});
+ $feed->{atom}->add_link({type => "application/atom+xml", rel => $rel, href => $uri});
return $uri;
}
else
{
- my $l =
- first
- { !defined $_->rel || $_->rel eq 'self' }
- $feed->{atom}->link;
- ;
+ my $l;
+
+ if ($rel eq 'self') {
+ $l = first
+ { !defined $_->rel || $_->rel eq 'self' }
+ $feed->{atom}->link;
+ ;
+ } else {
+ $l = first
+ { !defined $_->rel || $_->rel eq $rel }
+ $feed->{atom}->link;
+ ;
+ }
return $l ? $l->href : undef;
}
}
+sub self_link { shift->_rel_link( 'self', @_ ) }
+sub first_link { shift->_rel_link( 'first', @_ ) }
+sub last_link { shift->_rel_link( 'last', @_ ) }
+sub next_link { shift->_rel_link( 'next', @_ ) }
+sub previous_link { shift->_rel_link( 'previous', @_ ) };
+sub current_link { shift->_rel_link( 'current', @_ ) }
+sub prev_archive_link { shift->_rel_link( 'prev-archive', @_ ) }
+sub next_archive_link { shift->_rel_link( 'next-archive', @_ ) }
+
sub description { shift->{atom}->tagline(@_) }
sub copyright { shift->{atom}->copyright(@_) }
sub language { shift->{atom}->language(@_) }
View
8 lib/XML/Feed/Format/RSS.pm
@@ -103,6 +103,14 @@ sub self_link {
return $feed->{rss}->channel->{'atom'}{'link'};
}
+# This doesn't exist in RSS
+sub first_link { };
+sub last_link { };
+sub previous_link { };
+sub next_link { };
+sub current_link { };
+sub prev_archive_link { };
+sub next_archive_link { };
sub generator {
my $feed = shift;
View
18 t/02-create.t
@@ -91,6 +91,24 @@ for my $format (qw( Atom RSS )) {
{
like ($feed->as_xml(), qr{\Q<link rel="self" href="http://tor.tld/my-feed.rss" type="application/atom+xml"/>\E},
"Feed contains the atom:link");
+
+ my %rfc5005 = (
+ first_link => "http://tor.tld/my-feed.xml?page=1",
+ next_link => "http://tor.tld/my-feed.xml?page=4",
+ previous_link => "http://tor.tld/my-feed.xml?page=2",
+ last_link => "http://tor.tld/my-feed.xml?page=99",
+ current_link => "http://tor.tld/archive/2.xml",
+ prev_archive_link => "http://tor.tld/archive/1.xml",
+ next_archive_link => "http://tor.tld/archive/3.xml",
+ );
+
+ while ( my($name,$url) = each(%rfc5005) ) {
+ $feed->$name($url);
+ $name =~ s/_link$//;
+ $name =~ s/_/-/g;
+ like ($feed->as_xml(), qr{\Q<link rel="$name" href="$url" type="application/atom+xml"/>\E},
+ "Feed contains an RFC 5005 rel=\"$name\" link");
+ }
}
}

0 comments on commit 02de179

Please sign in to comment.
Something went wrong with that request. Please try again.