Skip Menu |

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

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

People
Owner: DAVECROSS [...] cpan.org
Requestors: peter [...] stuifzand.com
Cc:
AdminCc:

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



Subject: Method 'enclosure' doesn't work in feed without enclosures
The method 'enclosure' dies when called on a entry without enclosures. Can't locate object method "new" via package "XML::Feed::Enclosure" (perhaps you forgot to load "XML::Feed::Enclosure"?) at lib/XML/Feed/Format/RSS.pm line 359. I have written and attached a patch that can be applied to SVN trunk that will fix this problem and one other problem that appears when this bug is fixed. If you want a different version or type of patch, please let me know.
Subject: xml-feed-no-enclosures.patch
Index: t/14-no-enclosures.t =================================================================== --- t/14-no-enclosures.t (revision 0) +++ t/14-no-enclosures.t (revision 0) @@ -0,0 +1,15 @@ +#!perl -w +use strict; +use Test::More; +use XML::Feed; + +my @formats = qw/rss20 atom/; +plan tests => 2*@formats; + +for my $format (@formats) { + ok (my $feed = XML::Feed->parse("t/samples/$format.xml"), "Parsed $format"); + my ($entry) = $feed->entries; + my @enclosure = $entry->enclosure; + is(@enclosure, 0); +} + Index: lib/XML/Feed/Format/RSS.pm =================================================================== --- lib/XML/Feed/Format/RSS.pm (revision 160) +++ lib/XML/Feed/Format/RSS.pm (working copy) @@ -7,6 +7,7 @@ use DateTime::Format::Mail; use DateTime::Format::W3CDTF; use XML::Atom::Util qw(iso2dt); +use XML::Feed::Enclosure; our $PREFERRED_PARSER = "XML::RSS"; @@ -356,8 +357,11 @@ } } else { my $tmp = $entry->{entry}->{enclosure}; - my @encs = map { XML::Feed::Enclosure->new($_) } (ref $tmp eq 'ARRAY')? @$tmp : ($tmp); - return ($XML::Feed::MULTIPLE_ENCLOSURES)? @encs : $encs[-1]; + if (defined $tmp) { + my @encs = map { XML::Feed::Enclosure->new($_) } (ref $tmp eq 'ARRAY')? @$tmp : ($tmp); + return ($XML::Feed::MULTIPLE_ENCLOSURES)? @encs : $encs[-1]; + } + return; } } Index: lib/XML/Feed/Format/Atom.pm =================================================================== --- lib/XML/Feed/Format/Atom.pm (revision 160) +++ lib/XML/Feed/Format/Atom.pm (working copy) @@ -314,7 +314,7 @@ return 1; } else { my @links = grep { defined $_->rel && $_->rel eq 'enclosure' } $entry->{entry}->link; - return undef unless @links; + return unless @links; my @encs = map { XML::Feed::Enclosure->new({ url => $_->href, length => $_->length, type => $_->type }) } @links ; return ($XML::Feed::MULTIPLE_ENCLOSURES)? @encs : $encs[-1]; }
This fix has been applied in v0.46 which will be on CPAN later today.