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...