srchulo / JSON-Slurper

Convenient slurping and spurting of data via JSON
Other
0 stars 1 forks source link

Uses JSON::PP even if JSON::XS is installed #5

Open jwrightecs opened 5 years ago

jwrightecs commented 5 years ago
use constant JSON_XS => $ENV{JSON_SLURPER_NO_JSON_XS}                                          ? do { require JSON::PP; undef }
                     : eval { require Cpanel::JSON::XS; Cpanel::JSON::XS->VERSION('4.09'); 1 } ? 1
                     : do { require JSON::PP; undef };

The constant is "JSON_XS", but that module isn't checked. Perhaps JSON::MaybeXS, which uses Cpanel::JSON::XS, with fallbacks to JSON::XS then JSON::PP, should be used instead.

srchulo commented 5 years ago

So really that constant name means use JSON XS instead of a pure perl module, which would correspond to Cpanel::JSON::XS in this module (maybe this is a confusing name since there is a JSON::XS). I didn't use JSON::MaybeXS and chose to do this due to the problems listed here on Cpanel::JSON::XS for why it was forked from JSON::XS:

https://metacpan.org/pod/Cpanel::JSON::XS#cPanel-fork

It is possible to pass in a JSON::XS object to use as the encoder if needed:

my $ref = slurp_json 'ref.json', JSON::XS->new;

Or

my $json_slurper = JSON::Slurper->new(encoder => JSON::XS->new);