From e8fcbc5b332bd1fea62eb76350b765ac5ce4ca3f Mon Sep 17 00:00:00 2001 From: Simon Wistow Date: Fri, 22 Aug 2008 21:52:12 +0000 Subject: [PATCH] Allow accessors to make sure things validate --- Changes | 3 +++ lib/XML/Feed/Atom.pm | 8 +++++++- t/07-atom10-create.t | 13 ++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index ae1e659..5b91b3b 100644 --- a/Changes +++ b/Changes @@ -12,6 +12,9 @@ Revision history for XML::Feed - Force working version XML::Atom http://rt.cpan.org/Public/Bug/Display.html?id=22548 http://rt.cpan.org/Public/Bug/Display.html?id=19920 + - Allow extra Atom accessors + http://rt.cpan.org/Public/Bug/Display.html?id=33881 + (Paul Mison PMISON) 0.12 2006.08.13 - Generate Atom 1.0 feeds by default. Thanks to Tatsuhiko Miyagawa for diff --git a/lib/XML/Feed/Atom.pm b/lib/XML/Feed/Atom.pm index edfc8f3..5231c14 100644 --- a/lib/XML/Feed/Atom.pm +++ b/lib/XML/Feed/Atom.pm @@ -44,6 +44,9 @@ sub description { shift->{atom}->tagline(@_) } 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; @@ -98,6 +101,9 @@ sub init_empty { } sub title { shift->{entry}->title(@_) } +sub source { shift->{entry}->source(@_) } +sub updated { shift->{entry}->updated(@_) } + sub link { my $entry = shift; if (@_) { @@ -152,7 +158,7 @@ sub category { $entry->{entry}->add_category({ term => $_[0] }); } else { my $category = $entry->{entry}->category; - $category ? ($category->label || $category->term) : $entry->{entry}->get($ns, 'subject'); + $category ? ($category->label || $category->term) : $entry->{entry}->getlist($ns, 'subject'); } } diff --git a/t/07-atom10-create.t b/t/07-atom10-create.t index e5e4d57..09785f3 100644 --- a/t/07-atom10-create.t +++ b/t/07-atom10-create.t @@ -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("

Hello world.

"); +$entry->id("tag:cpan.org;xml-feed-atom-entry"); +$entry->updated($now); $feed->add_entry($entry); @@ -29,6 +36,8 @@ is $feed->format, 'Atom'; 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->category, 'blah'; is $entry->content->type, 'text/html'; like $entry->content->body, qr!\s*

Hello world.

\s*!s; +is $entry->id, "tag:cpan.org;xml-feed-atom-entry"; +is $entry->updated, $now;