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 {