'LWP::UserAgent' => 0,
'Module::Pluggable' => 0,
'URI::Fetch' => 0,
- 'XML::Atom' => 0.32,
- 'XML::LibXML' => 1.66,
- 'XML::RSS' => 1.37,
+ 'XML::Atom' => '0.32',
+ 'XML::LibXML' => '1.66',
+ 'XML::RSS' => '1.40',
'Test::More' => 0,
},
create_makefile_pl => 'traditional',
Revision history for XML::Feed
+0.41
+ - Add handling for multiple categories/tags
+ - Force v1.40 of XML::RSS to get proper multiple category support
+
0.40
- Force v1.37 of XML::RSS to get proper xml:base support
- Force v0.32 of XML::Atom to fix
sub lat;
sub long;
sub format;
+sub tags { shift->category(@_) }
1;
__END__
The category in which the entry was posted.
+Returns a list of categories if called in array context or the first
+category if called in scalar context.
+
+=head2 $entry->tags([ $tag ])
+
+A synonym for I<category>;
+
=head2 $entry->author([ $author ])
The name or email address of the person who posted the entry.
my $entry = shift;
my $ns = XML::Atom::Namespace->new(dc => 'http://purl.org/dc/elements/1.1/');
if (@_) {
- $entry->{entry}->add_category({ term => $_[0] });
+ $entry->{entry}->add_category({ term => $_ }) for @_;
+ return 1
} else {
- my $category = $entry->{entry}->category;
- my @return = $category ? ($category->label || $category->term) : $entry->{entry}->getlist($ns, 'subject');
+
+
+ my @category = ($entry->{entry}->can('categories')) ? $entry->{entry}->categories : $entry->{entry}->category;
+ my @return = @category
+ ? (map { $_->label || $_->term } @category)
+ : $entry->{entry}->getlist($ns, 'subject');
+
return wantarray? @return : $return[0];
}
}
}
sub category {
- my $item = shift->{entry};
+ my $entry = shift;
+ my $item = $entry->{entry};
if (@_) {
- $item->{category} = $item->{dc}{subject} = $_[0];
+ my @tmp = ($entry->category, @_);
+ $item->{category} = [@tmp];
+ $item->{dc}{subject} = [@tmp];
} else {
- $item->{category} || $item->{dc}{subject};
+ my $r = $item->{category} || $item->{dc}{subject};
+ my @r = ref($r)? @$r : ($r);
+ return wantarray? @r : $r[0];
}
}
--- /dev/null
+#!perl -w
+
+use strict;
+use vars qw($type $field);
+$type = "atom";
+require 't/12-multi-categories.base';
--- /dev/null
+#!perl -w
+
+use strict;
+use vars qw($type $field);
+$type = "rss";
+require 't/12-multi-categories.base';
--- /dev/null
+use strict;
+use Test::More tests => 6;
+use XML::Feed;
+
+$field ||= "categories";
+ok(my $feed = XML::Feed->parse("t/samples/${type}-multiple-${field}.xml"), "Parsed $type file with multiple categories");
+my ($entry) = $feed->entries;
+
+is_deeply(
+ [$entry->category()],
+ ["foo", "bar", "quux", "simon's tags"],
+"Got all categories");
+
+my $xml = $feed->as_xml;
+ok($feed = XML::Feed->parse(\$xml), "Reparsed $type from string");
+is_deeply(
+ [$entry->category()],
+ ["foo", "bar", "quux", "simon's tags"],
+"Got all categories again");
+
+ok($entry->category("quirka fleeg"), "Added a category");
+is_deeply(
+ [$entry->category()],
+ ["foo", "bar", "quux", "simon's tags", "quirka fleeg"],
+"Got new category");
+
--- /dev/null
+#!perl -w
+
+use vars qw($type $field);
+$type = "rss";
+$field = "subjects";
+require 't/12-multi-categories.base';
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
+ <title>Simon Wistow's blog</title>
+ <link rel="self" type="application/atom+xml" title="Simon Wistow.s blog (Atom)" href="http://deflatermouse.vox.com/library/posts/page/1/atom.xml" />
+ <updated>2008-12-09T06:37:07Z</updated>
+ <id>tag:vox.com,2006:6p00c2252555dbf219/</id>
+ <subtitle>One Drink Too Many and a Joke Gone Too Far</subtitle>
+ <entry>
+ <title>Test With Categories</title>
+ <published>2008-12-08T19:44:50Z</published>
+ <updated>2008-12-09T06:37:07Z</updated>
+ <content>content</content>
+ <category term="foo" />
+ <category term="bar" />
+ <category term="quux" />
+ <category term="simon's tags" />
+ </entry>
+</feed>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<rss version="2.0"
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:content="http://purl.org/rss/1.0/modules/content/">
+ <channel>
+ <title>Simon Wistow's blog</title>
+ <link>http://deflatermouse.vox.com/library/posts/page/1/</link>
+ <lastBuildDate>Mon, 08 Dec 2008 11:44:50 -0800</lastBuildDate>
+ <item>
+ <title>Test With Categories</title>
+ <pubDate>Mon, 08 Dec 2008 11:44:50 -0800</pubDate>
+ <description>content</description>
+ <category>foo</category>
+ <category>bar</category>
+ <category>quux</category>
+ <category>simon's tags</category>
+ </item>
+ </channel>
+</rss>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<rss version="2.0"
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:content="http://purl.org/rss/1.0/modules/content/">
+ <channel>
+ <title>Simon Wistow's blog</title>
+ <link>http://deflatermouse.vox.com/library/posts/page/1/</link>
+ <lastBuildDate>Mon, 08 Dec 2008 11:44:50 -0800</lastBuildDate>
+ <item>
+ <title>Test With Categories</title>
+ <pubDate>Mon, 08 Dec 2008 11:44:50 -0800</pubDate>
+ <description>content</description>
+ <dc:subject>foo</dc:subject>
+ <dc:subject>bar</dc:subject>
+ <dc:subject>quux</dc:subject>
+ <dc:subject>simon's tags</dc:subject>
+ </item>
+ </channel>
+</rss>