Skip Menu |

This queue is for tickets about the WWW-Facebook-API CPAN distribution.

Report information
The Basics
Id: 27704
Status: resolved
Priority: 0/
Queue: WWW-Facebook-API

People
Owner: Nobody in particular
Requestors: jshirley+cpan [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: v0.3.2
Fixed in: (no value)



Subject: JSON::Any parsing preference clobbered (w/ patch)
Hi there, We've discovered a problem in the way that sub _parse { } handles loading the JSON::Any module. I didn't want to go crazy in a refactor, but added some safety checks to not reload the module if it is already loaded. The reason for this is a request that has large numbers (such as 2161368895015881889 for a pid) without using JSON::DWIW will get wrapped, and you end up with the largely useless "2.16136889501596e+18" So, doing a "use JSON::Any qw|DWIW Syck XS|;" had no effect because of the duplicate use JSON::Any line in the eval in _parse. The order was being defaulted back, and subsequently breaking. My simple check just tries to create a JSON::Any object, and if it fails it will continue to attempt to load JSON::Any in the same fashion. Thanks, -Jay
Subject: WWW-Facebook-API.patch
=== lib/WWW/Facebook/API.pm ================================================================== --- lib/WWW/Facebook/API.pm (revision 4897) +++ lib/WWW/Facebook/API.pm (local) @@ -222,16 +222,24 @@ sub _parse { my ( $self, $response ) = @_; - ## no critic - eval q{use JSON::Any}; - croak "Unable to load JSON module for parsing:$@\n" if $@; + my $parser; + eval { $parser = JSON::Any->new; }; + # Only load JSON::Any if we haven't already. Lets the developers + # pick their choice of JSON modules (JSON::DWIW, for example) + if ( $@ ) { + ## no critic + eval q{use JSON::Any}; + croak "Unable to load JSON module for parsing:$@\n" if $@; + $parser = JSON::Any->new; + } + if ( $self->debug ) { carp 'JSON::Any is using ' . JSON::Any->handler . " to parse\n$response\n\n"; } - return JSON::Any->new->decode($response); + return $parser->decode($response); } sub _check_values_of {
Subject: Re: [rt.cpan.org #27704] JSON::Any parsing preference clobbered (w/ patch)
Date: Fri, 22 Jun 2007 19:24:00 -0700
To: "J. Shirley via RT" <bug-WWW-Facebook-API [...] rt.cpan.org>
From: David Romano <david.romano [...] gmail.com>
Hi Jay, J. Shirley via RT wrote on Fri, Jun 22, 2007 at 05:45:43PM PDT: Show quoted text
> We've discovered a problem in the way that sub _parse { } handles > loading the JSON::Any module. I didn't want to go crazy in a refactor, > but added some safety checks to not reload the module if it is already > loaded. > > The reason for this is a request that has large numbers (such as > 2161368895015881889 for a pid) without using JSON::DWIW will get > wrapped, and you end up with the largely useless "2.16136889501596e+18" > > So, doing a "use JSON::Any qw|DWIW Syck XS|;" had no effect because of > the duplicate use JSON::Any line in the eval in _parse. The order was > being defaulted back, and subsequently breaking. > > My simple check just tries to create a JSON::Any object, and if it fails > it will continue to attempt to load JSON::Any in the same fashion.
Thank you for your patch! It's been applied to trunk, which has been released as v0.3.4 on CPAN. I've added you as a contributor in the docs, using your gmail address. Let me know if you find anything else or have other ideas for improving the module, - David -- "If a man will begin with certainties, he shall end in doubts; but if he will be content to begin with doubts he shall end in certainties." -- Sir Francis Bacon
v0.3.4
Subject: Re: [rt.cpan.org #27704] JSON::Any parsing preference clobbered (w/ patch)
Date: Fri, 22 Jun 2007 19:47:13 -0700
To: bug-WWW-Facebook-API [...] rt.cpan.org
From: "J. Shirley" <jshirley [...] gmail.com>
On 6/22/07, david.romano@gmail.com via RT <bug-WWW-Facebook-API@rt.cpan.org> wrote: Show quoted text
> > <URL: http://rt.cpan.org/Ticket/Display.html?id=27704 > > > Hi Jay, > J. Shirley via RT wrote on Fri, Jun 22, 2007 at 05:45:43PM PDT:
> > We've discovered a problem in the way that sub _parse { } handles > > loading the JSON::Any module. I didn't want to go crazy in a refactor, > > but added some safety checks to not reload the module if it is already > > loaded. > > > > The reason for this is a request that has large numbers (such as > > 2161368895015881889 for a pid) without using JSON::DWIW will get > > wrapped, and you end up with the largely useless "2.16136889501596e+18" > > > > So, doing a "use JSON::Any qw|DWIW Syck XS|;" had no effect because of > > the duplicate use JSON::Any line in the eval in _parse. The order was > > being defaulted back, and subsequently breaking. > > > > My simple check just tries to create a JSON::Any object, and if it fails > > it will continue to attempt to load JSON::Any in the same fashion.
> Thank you for your patch! It's been applied to trunk, which has been > released as v0.3.4 on CPAN. I've added you as a contributor in the > docs, using your gmail address. Let me know if you find anything else > or have other ideas for improving the module, > > - David >
Great! Thanks so much David -- very nice turnaround on a nice module. -- J. Shirley :: jshirley@gmail.com :: Killing two stones with one bird... http://www.toeat.com