Skip Menu |

This queue is for tickets about the XML-Feed CPAN distribution.

Report information
The Basics
Id: 41396
Status: resolved
Priority: 0/
Queue: XML-Feed

People
Owner: simonw [...] cpan.org
Requestors: SHLOMIF [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.40
Fixed in: (no value)



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">&lt;p&gt; +Yesterday, the &lt;a href="http://www.cs.tau.ac.il/telux/"&gt;Tel Aviv Open Source +Developers' Club&lt;/a&gt; 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. +&lt;/p&gt; + +&lt;p&gt; +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. +&lt;/p&gt; + +&lt;p&gt; +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. +&lt;/p&gt; + +&lt;p&gt; +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. +&lt;/p&gt; + +&lt;p&gt; +I forgot the camera at home, so I couldn't take pictures. +&lt;/p&gt; + +&lt;p&gt; +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 &lt;a href="http://www.shlomifish.org/philosophy/computers/education/introductory-language/"&gt;Introductory +Progrmmaing Language essay&lt;/a&gt;. We also discussed distributions. +&lt;/p&gt; + +&lt;p&gt; +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 &lt;a href="http://www.youtube.com/watch?v=rw2nkoGLhrE"&gt;the iRack&lt;/a&gt; +and "iLand", which is Apple's CEO's private island. (One of our guests +made the latter one on the spot.) +&lt;/p&gt; + +&lt;p&gt; +In short, a lot of good time was had. Next presentation is next Sunday +about the Installation Process. Hope to see you all there. +&lt;/p&gt;</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
First cut at support for this is in SVN. I need to sort out some backwards compatibility stuff and then I'll do a release.
Released as 0.41