Skip Menu |

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

Report information
The Basics
Id: 78236
Status: rejected
Priority: 0/
Queue: XML-Feed

People
Owner: DAVECROSS [...] cpan.org
Requestors: adjel [...] eavdmeer.org
Cc:
AdminCc:

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



Subject: Bug in XML::Feed v 0.49
Date: Fri, 6 Jul 2012 08:48:52 +0200
To: bug-XML-Feed [...] rt.cpan.org
From: Adjel van der Meer <eavdmeer [...] gmail.com>
*My perl version:* This is perl 5, version 12, subversion 4 (v5.12.4) built for x86_64-linux-thread-multi *uname -a output:* Linux ultrapub6.intranet.ing-int 2.6.42.12-1.fc15.x86_64 #1 SMP Tue Mar 20 16:30:08 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux *The bug I'm reporting:* When parsing an Atom feed, I get the following error message from Perl: Attempt to bless into a reference at /usr/local/share/perl5/XML/Feed.pm line 37. The offending section of code: sub parse { my $class = shift; my($stream, $specified_format) = @_; return $class->error("Stream parameter is required") unless $stream; my $feed = bless {}, $class; ....... *The proposed solution:* Looking at the manual for bless ( http://perldoc.perl.org/functions/bless.html), it says: bless REF,CLASSNAME Since $class is not a class name, but a reference to a class, Perl rightly complains that the code tries to bless into a reference. I believe the correct code here would be: my $feed = bless {}, ref($class); That does indeed make things work again. Hope you can fix this. Adjel
On Fri Jul 06 02:49:03 2012, adjel@eavdmeer.org wrote: Show quoted text
> *My perl version:* > > This is perl 5, version 12, subversion 4 (v5.12.4) built for > x86_64-linux-thread-multi > > *uname -a output:* > > Linux ultrapub6.intranet.ing-int 2.6.42.12-1.fc15.x86_64 #1 SMP Tue Mar > 20 16:30:08 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux > > *The bug I'm reporting:* > > When parsing an Atom feed, I get the following error message from Perl: > > Attempt to bless into a reference at /usr/local/share/perl5/XML/Feed.pm > line 37. > > The offending section of code: > > sub parse { > my $class = shift; > my($stream, $specified_format) = @_; > return $class->error("Stream parameter is required") unless $stream; > my $feed = bless {}, $class; > ....... > > *The proposed solution:* > > Looking at the manual for bless ( > http://perldoc.perl.org/functions/bless.html), it says: > > bless REF,CLASSNAME > > Since $class is not a class name, but a reference to a class, Perl rightly > complains that the code tries to bless into a reference. I believe the > correct code here would be: > > my $feed = bless {}, ref($class); > > That does indeed make things work again. > > Hope you can fix this. > > Adjel
Hi, I'm not sure why you say "$class is not a class name, but a reference to a class". As you'll see from the documentation[1], parse() is supposed to be called like this: my $feed = XML::Feed->parse(URI->new('http://example.com/atom.xml')); When you use it like this, $class gets a classname as a string ("XML::Feed") and everything works as expected. parse() is a constructor. It is intended to be called as a class method, not an instance method. If you can show me how you are calling the method, then perhaps I can suggest how you can change your code to call the method correctly. Cheers, Dave... [1] https://metacpan.org/module/XML::Feed
Subject: Re: [rt.cpan.org #78236] Bug in XML::Feed v 0.49
Date: Thu, 12 Jul 2012 09:41:03 +0200
To: bug-XML-Feed [...] rt.cpan.org
From: Adjel van der Meer <eavdmeer [...] gmail.com>
Dave, Thanks a lot for responding so quickly. I certainly did not mean to imply that I understand Perl very well ;-) I am no expert by any means, but I believe I still have to disagree with your conclusion. I do not call parse() with a URI argument as in your example. I use parse() with a scalar string reference like this: #!/usr/bin/perl -w use strict; use XML::Feed; my $site_content = '<?xml version="1.0" encoding="utf-8"?> <feed xmlns="http://www.w3.org/2005/Atom"> </feed>'; my $rp = XML::Feed->new('Atom'); my $feed = $rp->parse(\$site_content); Running this results in: Attempt to bless into a reference at /usr/local/share/perl5/XML/Feed.pm line 37. When I modify the code of parse() to print the class before the bless, like this: sub parse { my $class = shift; my($stream, $specified_format) = @_; return $class->error("Stream parameter is required") unless $stream; + print('XML:Feed->parse: class is: ' . $class . "\n"); my $feed = bless {}, $class; ..... I get the following output: XML:Feed->parse: class is: XML::Feed::Format::Atom=HASH(0x1522028) Attempt to bless into a reference at /usr/local/share/perl5/XML/Feed.pm line 38. So class is definitely not a string! It is a HASH. Trying to use it with a direct URI results in the same output: #!/usr/bin/perl -w use strict; use XML::Feed; use URI; my $rp = XML::Feed->new('RSS'); my $feed = $rp->parse(URI->new('http://www.rss.intranet/rss.php/1002')); Output: XML:Feed->parse: class is: XML::Feed::Format::RSS=HASH(0x246a028) Attempt to bless into a reference at /usr/local/share/perl5/XML/Feed.pm line 38. Call me crazy, but this looks like a bug to me! The proposed solution with a ref($class) works like a charm and I believe it is the correct way to do it. Regards, Adjel On Tue, Jul 10, 2012 at 10:30 PM, Dave Cross via RT <bug-XML-Feed@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=78236 > > > On Fri Jul 06 02:49:03 2012, adjel@eavdmeer.org wrote:
>> *My perl version:* >> >> This is perl 5, version 12, subversion 4 (v5.12.4) built for >> x86_64-linux-thread-multi >> >> *uname -a output:* >> >> Linux ultrapub6.intranet.ing-int 2.6.42.12-1.fc15.x86_64 #1 SMP Tue Mar >> 20 16:30:08 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux >> >> *The bug I'm reporting:* >> >> When parsing an Atom feed, I get the following error message from Perl: >> >> Attempt to bless into a reference at /usr/local/share/perl5/XML/Feed.pm >> line 37. >> >> The offending section of code: >> >> sub parse { >> my $class = shift; >> my($stream, $specified_format) = @_; >> return $class->error("Stream parameter is required") unless $stream; >> my $feed = bless {}, $class; >> ....... >> >> *The proposed solution:* >> >> Looking at the manual for bless ( >> http://perldoc.perl.org/functions/bless.html), it says: >> >> bless REF,CLASSNAME >> >> Since $class is not a class name, but a reference to a class, Perl rightly >> complains that the code tries to bless into a reference. I believe the >> correct code here would be: >> >> my $feed = bless {}, ref($class); >> >> That does indeed make things work again. >> >> Hope you can fix this. >> >> Adjel
> > > Hi, > > I'm not sure why you say "$class is not a class name, but a reference to > a class". As you'll see from the documentation[1], parse() is supposed > to be called like this: > > my $feed = XML::Feed->parse(URI->new('http://example.com/atom.xml')); > > When you use it like this, $class gets a classname as a string > ("XML::Feed") and everything works as expected. > > parse() is a constructor. It is intended to be called as a class method, > not an instance method. > > If you can show me how you are calling the method, then perhaps I can > suggest how you can change your code to call the method correctly. > > Cheers, > > Dave... > > [1] https://metacpan.org/module/XML::Feed
-- Adjel van der Meer Soendastraat 5 3531HN Utrecht 0628107764
On Thu Jul 12 03:41:17 2012, adjel@eavdmeer.org wrote: Show quoted text
> Dave, > > Thanks a lot for responding so quickly. > > I certainly did not mean to imply that I understand Perl very well ;-) > I am no expert by any means, but I believe I still have to disagree > with your conclusion. I do not call parse() with a URI argument as in > your example. I use parse() with a scalar string reference like this: > > #!/usr/bin/perl -w > > use strict; > use XML::Feed; > > my $site_content = '<?xml version="1.0" encoding="utf-8"?> > <feed xmlns="http://www.w3.org/2005/Atom"> > </feed>'; > my $rp = XML::Feed->new('Atom'); > my $feed = $rp->parse(\$site_content); > > Running this results in: > > Attempt to bless into a reference at > /usr/local/share/perl5/XML/Feed.pm line 37.
Yes. I can see how you would get that error with that code. You are calling the parse() method in a manner that isn't documented and therefore isn't supported. If you look at the documentation for the parse() method, you'll see it is documented as: XML::Feed->parse($stream) XML::Feed->parse($stream, $format) So you call it as a *Class* method. Not as an instance method. In your sample code, your call to the new() method is unnecessary. You don't need the $rp object at all. Your code should look like this: my $feed = XML::Feed->parse(\$site_content); The new() method is used to create a new *empty* feed object which you can then populate using methods like add_entry(). To parse an existing feed you use the parse() method. There is clearly a deficiency in the documentation that I'm going to have to fix. Show quoted text
> When I modify the code of parse() to print the class before the bless, > like this: > > sub parse { > my $class = shift; > my($stream, $specified_format) = @_; > return $class->error("Stream parameter is required") unless > $stream; > + print('XML:Feed->parse: class is: ' . $class . "\n"); > my $feed = bless {}, $class; > ..... > > I get the following output: > > XML:Feed->parse: class is: XML::Feed::Format::Atom=HASH(0x1522028) > Attempt to bless into a reference at > /usr/local/share/perl5/XML/Feed.pm line 38.
Of course you do. Because you're calling the method with an object, not a class. But that's not how you're supposed to call it. Show quoted text
> So class is definitely not a string! It is a HASH.
It's not a hash, it's a blessed hash reference. But class *would* be a string if you called the method as it is documented. Show quoted text
> Trying to use it with a direct URI results in the same output: > > #!/usr/bin/perl -w > > use strict; > use XML::Feed; > use URI; > > my $rp = XML::Feed->new('RSS'); > my $feed = $rp->parse(URI- > > Output: > > XML:Feed->parse: class is: XML::Feed::Format::RSS=HASH(0x246a028) > Attempt to bless into a reference at > /usr/local/share/perl5/XML/Feed.pm line 38.
Yes, this a complete red herring. The data that you pass to the method doesn't affect this at all. What affects this is whether you call the method as documented or you call it a random fashion and expect ti to work :-) Show quoted text
> Call me crazy, but this looks like a bug to me! The proposed solution > with a ref($class) works like a charm and I believe it is the correct > way to do it.
Sorry, but I have to disagree. As I said above, the documentation might need some clarification, but the code is correct as it is and I won't be changing it to work as you suggest. Cheers, Dave...
Subject: Re: [rt.cpan.org #78236] Bug in XML::Feed v 0.49
Date: Thu, 12 Jul 2012 12:58:55 +0200
To: bug-XML-Feed [...] rt.cpan.org
From: Adjel van der Meer <eavdmeer [...] gmail.com>
Wow, that certainly clears things up. I had no idea I wasn't supposed to call it as an instance method, or even that I CAN'T call it as an instance method. Now that I look at it more closely, the documentation does actually suggest that. Told you I was no Perl expert ;-) I used XML::RSS::Parser before. Now I need to parse Atom feeds too, which that one doesn't. In the case of XML::RSS::Parser, you do need to create an instance: http://search.cpan.org/~tima/XML-RSS-Parser-4.0/lib/XML/RSS/Parser.pm That's what had me confused in the case of XML::Feed. My 'fix' would certainly break the use of your code. Not good :-) It would be nice if you can supplement the documentation to guide lost souls like myself. Thanks for your time! Adjel On Thu, Jul 12, 2012 at 10:50 AM, Dave Cross via RT <bug-XML-Feed@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=78236 > > > On Thu Jul 12 03:41:17 2012, adjel@eavdmeer.org wrote:
>> Dave, >> >> Thanks a lot for responding so quickly. >> >> I certainly did not mean to imply that I understand Perl very well ;-) >> I am no expert by any means, but I believe I still have to disagree >> with your conclusion. I do not call parse() with a URI argument as in >> your example. I use parse() with a scalar string reference like this: >> >> #!/usr/bin/perl -w >> >> use strict; >> use XML::Feed; >> >> my $site_content = '<?xml version="1.0" encoding="utf-8"?> >> <feed xmlns="http://www.w3.org/2005/Atom"> >> </feed>'; >> my $rp = XML::Feed->new('Atom'); >> my $feed = $rp->parse(\$site_content); >> >> Running this results in: >> >> Attempt to bless into a reference at >> /usr/local/share/perl5/XML/Feed.pm line 37.
> > Yes. I can see how you would get that error with that code. > > You are calling the parse() method in a manner that isn't documented and > therefore isn't supported. > > If you look at the documentation for the parse() method, you'll see it > is documented as: > > XML::Feed->parse($stream) > XML::Feed->parse($stream, $format) > > So you call it as a *Class* method. Not as an instance method. > > In your sample code, your call to the new() method is unnecessary. You > don't need the $rp object at all. Your code should look like this: > > my $feed = XML::Feed->parse(\$site_content); > > The new() method is used to create a new *empty* feed object which you > can then populate using methods like add_entry(). To parse an existing > feed you use the parse() method. > > There is clearly a deficiency in the documentation that I'm going to > have to fix. >
>> When I modify the code of parse() to print the class before the bless, >> like this: >> >> sub parse { >> my $class = shift; >> my($stream, $specified_format) = @_; >> return $class->error("Stream parameter is required") unless >> $stream; >> + print('XML:Feed->parse: class is: ' . $class . "\n"); >> my $feed = bless {}, $class; >> ..... >> >> I get the following output: >> >> XML:Feed->parse: class is: XML::Feed::Format::Atom=HASH(0x1522028) >> Attempt to bless into a reference at >> /usr/local/share/perl5/XML/Feed.pm line 38.
> > Of course you do. Because you're calling the method with an object, not > a class. But that's not how you're supposed to call it. >
>> So class is definitely not a string! It is a HASH.
> > It's not a hash, it's a blessed hash reference. But class *would* be a > string if you called the method as it is documented. >
>> Trying to use it with a direct URI results in the same output: >> >> #!/usr/bin/perl -w >> >> use strict; >> use XML::Feed; >> use URI; >> >> my $rp = XML::Feed->new('RSS'); >> my $feed = $rp->parse(URI- >> >> Output: >> >> XML:Feed->parse: class is: XML::Feed::Format::RSS=HASH(0x246a028) >> Attempt to bless into a reference at >> /usr/local/share/perl5/XML/Feed.pm line 38.
> > Yes, this a complete red herring. The data that you pass to the method > doesn't affect this at all. What affects this is whether you call the > method as documented or you call it a random fashion and expect ti to > work :-) >
>> Call me crazy, but this looks like a bug to me! The proposed solution >> with a ref($class) works like a charm and I believe it is the correct >> way to do it.
> > Sorry, but I have to disagree. As I said above, the documentation might > need some clarification, but the code is correct as it is and I won't be > changing it to work as you suggest. > > Cheers, > > Dave... >
-- -- Adjel van der Meer Soendastraat 5 3531HN Utrecht 0628107764
So, I hope we're agree that I can set this ticket to "rejected" :-)
Subject: Re: [rt.cpan.org #78236] Bug in XML::Feed v 0.49
Date: Thu, 12 Jul 2012 13:08:57 +0200
To: bug-XML-Feed [...] rt.cpan.org
From: Adjel van der Meer <eavdmeer [...] gmail.com>
Absolutely! On Thu, Jul 12, 2012 at 1:07 PM, Dave Cross via RT <bug-XML-Feed@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=78236 > > > So, I hope we're agree that I can set this ticket to "rejected" :-)
Not a bug (agreed with requestor)