CC: | perl [...] songtwo.demon.co.uk |
Subject: | Additional accessors needed for valid Atom feeds |
XML::Feed's Atom feeds don't validate, in part because there's no way to set an id, updated date
or <link rel="self"> entry for a feed, or an updated time for an entry. I've attached a diff that
adds these accessors and tests them.
Subject: | xml_feed_atom_accessors.diff |
--- XML-Feed-0.12/lib/XML/Feed/Atom.pm 2008-03-06 20:37:11.000000000 +0000
+++ XML-Feed/lib/XML/Feed/Atom.pm 2008-03-06 20:40:51.000000000 +0000
@@ -42,6 +42,9 @@
sub copyright { shift->{atom}->copyright(@_) }
sub language { shift->{atom}->language(@_) }
sub generator { shift->{atom}->generator(@_) }
+sub id { shift->{atom}->id(@_) }
+sub updated { shift->{atom}->updated(@_) }
+sub add_link { shift->{atom}->add_link(@_) }
sub author {
my $feed = shift;
@@ -96,6 +99,9 @@
}
sub title { shift->{entry}->title(@_) }
+sub source { shift->{entry}->source(@_) }
+sub updated { shift->{entry}->updated(@_) }
+
sub link {
my $entry = shift;
if (@_) {
diff -ru XML-Feed-0.12/t/07-atom10-create.t XML-Feed/t/07-atom10-create.t
--- XML-Feed-0.12/t/07-atom10-create.t 2006-08-14 06:27:10.000000000 +0100
+++ XML-Feed/t/07-atom10-create.t 2008-03-06 20:42:03.000000000 +0000
@@ -1,20 +1,27 @@
use strict;
use Test::More;
-plan 'no_plan';
+plan tests => 17;
use XML::Feed;
+use DateTime;
+
+my $now = DateTime->now();
my $feed = XML::Feed->new('Atom');
$feed->title("foo");
$feed->description("Atom 1.0 feed");
$feed->link("http://example.org/");
+$feed->id("tag:cpan.org;xml-feed-atom");
+$feed->updated($now);
my $entry = XML::Feed::Entry->new('Atom');
$entry->title("1st Entry");
$entry->link("http://example.org/");
$entry->category("blah");
$entry->content("<p>Hello world.</p>");
+$entry->id("tag:cpan.org;xml-feed-atom-entry");
+$entry->updated($now);
$feed->add_entry($entry);
@@ -29,6 +36,8 @@
is $feed->title, "foo";
is $feed->description, "Atom 1.0 feed";
is $feed->link, "http://example.org/";
+is $feed->id, "tag:cpan.org;xml-feed-atom";
+is $feed->updated, $now;
my @entries = $feed->entries;
is @entries, 1;
@@ -40,5 +49,7 @@
is $entry->content->type, 'text/html';
like $entry->content->body, qr!\s*<p>Hello world.</p>\s*!s;
+is $entry->id, "tag:cpan.org;xml-feed-atom-entry";
+is $entry->updated, $now;