Subject: | [PATCH] Add a self_link() method. |
OK - here's my first patch - it adds a self link field that is either
required or recommended by latest Atom specs.
And a note - you should really remove the Module-Install's inc/ from
the repository and from the MANIFEST - it is no longer needed due to
the switch to M-B.
Regards,
-- Shlomi Fish
Subject: | add-self-link.diff |
Index: t/02-create.t
===================================================================
--- t/02-create.t (revision 54)
+++ t/02-create.t (working copy)
@@ -1,7 +1,7 @@
# $Id$
use strict;
-use Test::More tests => 69;
+use Test::More tests => 72;
use XML::Feed;
use XML::Feed::Entry;
use XML::Feed::Content;
@@ -76,4 +76,21 @@
if ($format eq 'Atom') {
like $feed->as_xml, qr/This is the content/;
}
+ if ($format eq 'RSS') {
+ like $feed->as_xml, qr{xmlns:dcterms="http://purl.org/dc/terms/"};
+ }
+
+ $feed->self_link("http://tor.tld/my-feed.rss");
+
+ if ($format eq "RSS")
+ {
+ like ($feed->as_xml(), qr{\Q<atom:link href="http://tor.tld/my-feed.rss" rel="self" type="application/rss+xml"/>\E},
+ "Feed contains the atom:link");
+ }
+ elsif ($format eq "Atom")
+ {
+ 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");
+ }
+
}
Index: lib/XML/Feed/RSS.pm
===================================================================
--- lib/XML/Feed/RSS.pm (revision 54)
+++ lib/XML/Feed/RSS.pm (working copy)
@@ -15,7 +15,8 @@
eval "use $PREFERRED_PARSER"; die $@ if $@;
$feed->{rss} = $PREFERRED_PARSER->new(%args);
$feed->{rss}->add_module(prefix => "content", uri => 'http://purl.org/rss/1.0/modules/content/');
- $feed->{rss}->add_module(prefix => "dcterms", uri => 'http://purl.org/rss/1.0/modules/dcterms/');
+ $feed->{rss}->add_module(prefix => "dcterms", uri => 'http://purl.org/dc/terms/');
+ $feed->{rss}->add_module(prefix => "atom", uri => 'http://www.w3.org/2005/Atom');
$feed;
}
@@ -51,6 +52,24 @@
}
}
+sub self_link {
+ my $feed = shift;
+
+ if (@_) {
+ my $uri = shift;
+
+ $feed->{rss}->channel->{'atom'}{'link'} =
+ {
+ rel => "self",
+ href => $uri,
+ type => "application/rss+xml",
+ };
+ }
+
+ return $feed->{rss}->channel->{'atom'}{'link'};
+}
+
+
sub generator {
my $feed = shift;
if (@_) {
Index: lib/XML/Feed/Atom.pm
===================================================================
--- lib/XML/Feed/Atom.pm (revision 54)
+++ lib/XML/Feed/Atom.pm (working copy)
@@ -40,6 +40,26 @@
$l ? $l->href : undef;
}
}
+
+sub self_link {
+ my $feed = shift;
+ if (@_) {
+ my $uri = shift;
+ $feed->{atom}->add_link({type => "application/atom+xml", rel => "self", href => $uri});
+ return $uri;
+ }
+ else
+ {
+ my $l =
+ first
+ { !defined $_->rel || $_->rel eq 'self' }
+ $feed->{atom}->link;
+ ;
+
+ return $l ? $l->href : undef;
+ }
+}
+
sub description { shift->{atom}->tagline(@_) }
sub copyright { shift->{atom}->copyright(@_) }
sub language { shift->{atom}->language(@_) }
Index: lib/XML/Feed.pm
===================================================================
--- lib/XML/Feed.pm (revision 54)
+++ lib/XML/Feed.pm (working copy)
@@ -124,6 +124,7 @@
sub format;
sub title;
sub link;
+sub self_link;
sub description;
sub language;
sub author;
@@ -280,6 +281,14 @@
The generator of the feed.
+=head2 $feed->self_link ([ $uri ])
+
+The Atom Self-link of the feed:
+
+L<http://validator.w3.org/feed/docs/warning/MissingAtomSelfLink.html>
+
+A string.
+
=head2 $feed->entries
A list of the entries/items in the feed. Returns an array containing