Subject: | [PATCH] Fix support for Multiple Categories in XML-Atom |
As the test in the patch demonstrates, when ->category() for a
LiveJournal Atom feed is called in list context, only the first item is
returned. This patch fixes the problem by calling the XML::Atom function
in list context and processing them all. It includes a test case.
I should note that in XML::RSS as of version 1.40, the category may
return either a string or an arrayref. So the RSS backend should make it
consistent with that of XML-Atom.
Regards,
-- Shlomi Fish
Subject: | xml-feed-multi-cat.diff |
Index: t/12-atom-multi-cats.t
===================================================================
--- t/12-atom-multi-cats.t (revision 0)
+++ t/12-atom-multi-cats.t (revision 0)
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+
+use XML::Feed;
+use File::Spec;
+
+{
+ my $feed = XML::Feed->parse(
+ File::Spec->catfile(
+ File::Spec->curdir(),
+ "t", "samples", "atom-several-categories.xml"
+ ),
+ );
+
+ my @e = $feed->entries;
+ my $entry = $e[0];
+ # TEST
+ is_deeply(
+ [$entry->category()],
+ [
+ "apple",
+ "irack",
+ "open source",
+ "telux",
+ "mini-intro",
+ "meeting",
+ "foss",
+ "osdclub",
+ "linux",
+ "tel aviv",
+ "report",
+ ],
+ );
+ print join(",", $entry->category()), "\n";
+}
Index: t/samples/atom-several-categories.xml
===================================================================
--- t/samples/atom-several-categories.xml (revision 0)
+++ t/samples/atom-several-categories.xml (revision 0)
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- If you are running a bot please visit this policy page outlining rules you must respect. http://www.livejournal.com/bots/ -->
+<feed xmlns="http://www.w3.org/2005/Atom" xmlns:lj="http://www.livejournal.com">
+ <id>urn:lj:livejournal.com:atom1:shlomif_tech</id>
+ <title>Shlomif's Technical Posts Community</title>
+ <subtitle>Shlomif's Technical Posts Community</subtitle>
+ <author>
+ <name>Shlomif's Technical Posts Community</name>
+ </author>
+ <link rel="alternate" type="text/html" href="http://community.livejournal.com/shlomif_tech/"/>
+ <link rel="self" type="text/xml" href="http://community.livejournal.com/shlomif_tech/data/atom"/>
+ <updated>2008-11-24T19:57:23Z</updated>
+ <lj:journal username="shlomif_tech" type="community"/>
+ <link rel="service.feed" type="application/x.atom+xml" href="http://community.livejournal.com/shlomif_tech/data/atom" title="Shlomif's Technical Posts Community"/>
+ <entry>
+ <id>urn:lj:livejournal.com:atom1:shlomif_tech:18352</id>
+ <link rel="alternate" type="text/html" href="http://community.livejournal.com/shlomif_tech/18352.html"/>
+ <link rel="self" type="text/xml" href="http://community.livejournal.com/shlomif_tech/data/atom/?itemid=18352"/>
+ <title>Report on the Last OSDClub Tel Aviv Meeting</title>
+ <published>2008-11-24T19:57:23Z</published>
+ <updated>2008-11-24T19:57:23Z</updated>
+ <category term="apple"/>
+ <category term="irack"/>
+ <category term="open source"/>
+ <category term="telux"/>
+ <category term="mini-intro"/>
+ <category term="meeting"/>
+ <category term="foss"/>
+ <category term="osdclub"/>
+ <category term="linux"/>
+ <category term="tel aviv"/>
+ <category term="report"/>
+ <lj:music>The Crystals - He's a Rebel</lj:music>
+ <content type="html"><p>
+Yesterday, the <a href="http://www.cs.tau.ac.il/telux/">Tel Aviv Open Source
+Developers' Club</a> held the first meeting in the 2008 Welcome-to-Linux
+series for the "Mini-Intro" presentation. I arrived to the place early as
+usual, and there was no one in the class-room except for some students who
+came for the previous class. They asked me what is going to be there, though.
+</p>
+
+<p>
+The attendees arrived shortly afterwards. Then some minutes before the
+presentation, I called Eddie, who was going to give the talk on the cell-phone
+and asked him where he was. He said he forgot all about the talk, and asked
+if I could find a different lecturer instead of him. Luckily, Ori was there
+and we went over the slides in preparation.
+</p>
+
+<p>
+Ori gave a good presentation, in my opinion, and some people from the
+audience asked him questions, and I and other people gave some commentary. Then,
+some people arrived while the talk was in progress.
+</p>
+
+<p>
+During the break some people asked me about the possibility on soliciting
+some presentations that they were interested in. One of them told me he came
+for a presentation about the command line, and was less interested in all
+the GUI stuff which he was already mostly familiar with. Another asked if
+we could give a presentation about SELinux, NIS or similar topics related
+to system administration, because he was studying for his RHCE. We'll see
+what we can do about these requests.
+</p>
+
+<p>
+I forgot the camera at home, so I couldn't take pictures.
+</p>
+
+<p>
+Then I ushered everyone out of the room, and those that were interested went
+to the café. I went with two other guys, who turned out to be Biology students
+- one of them talked on his cellphone all the way and while we waited for the
+others to come, but I could talk with the other guy. He asked me which
+programming language he should learn first and I told him the conclusions
+from my <a href="http://www.shlomifish.org/philosophy/computers/education/introductory-language/">Introductory
+Progrmmaing Language essay</a>. We also discussed distributions.
+</p>
+
+<p>
+Then Galia and Kobi (who went to re-park Galia's car) found us, and said they
+had thought we already were sitted in the café. We found a table, but then
+decided it was too low to be effective, and so switched places. Then we
+ate, drank and talked. We exchanged many jokes about Apple and stuff
+like <a href="http://www.youtube.com/watch?v=rw2nkoGLhrE">the iRack</a>
+and "iLand", which is Apple's CEO's private island. (One of our guests
+made the latter one on the spot.)
+</p>
+
+<p>
+In short, a lot of good time was had. Next presentation is next Sunday
+about the Installation Process. Hope to see you all there.
+</p></content>
+ </entry>
+</feed>
Index: lib/XML/Feed/Format/Atom.pm
===================================================================
--- lib/XML/Feed/Format/Atom.pm (revision 115)
+++ lib/XML/Feed/Format/Atom.pm (working copy)
@@ -230,8 +230,12 @@
if (@_) {
$entry->{entry}->add_category({ term => $_[0] });
} else {
- my $category = $entry->{entry}->category;
- my @return = $category ? ($category->label || $category->term) : $entry->{entry}->getlist($ns, 'subject');
+ my @category = $entry->{entry}->category;
+
+ my @return = @category
+ ? (map { $_->label || $_->term } @category)
+ : $entry->{entry}->getlist($ns, 'subject');
+
return wantarray? @return : $return[0];
}
}
Index: MANIFEST
===================================================================
--- MANIFEST (revision 115)
+++ MANIFEST (working copy)
@@ -1,13 +1,13 @@
Build.PL
Changes
-lib/XML/Feed.pm
lib/XML/Feed/Content.pm
lib/XML/Feed/Entry.pm
lib/XML/Feed/Format/Atom.pm
lib/XML/Feed/Format/RSS.pm
+lib/XML/Feed.pm
Makefile.PL
+MANIFEST.SKIP
MANIFEST This list of files
-MANIFEST.SKIP
META.yml
README
t/00-compile.t
@@ -23,8 +23,12 @@
t/10-mix-and-match.t
t/11-xml-base-atom.t
t/11-xml-base-rss.t
+t/12-atom-multi-cats.t
+t/pod-coverage.t
+t/pod.t
t/samples/atom-10-example.xml
t/samples/atom-full.xml
+t/samples/atom-several-categories.xml
t/samples/atom.xml
t/samples/base_atom.xml
t/samples/base_rss.xml
@@ -32,5 +36,3 @@
t/samples/rss10.xml
t/samples/rss20-no-summary.xml
t/samples/rss20.xml
-t/pod.t
-t/pod-coverage.t