Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle old JSON::XS version #48

Open
rovo89 opened this issue May 4, 2021 · 1 comment
Open

How to handle old JSON::XS version #48

rovo89 opened this issue May 4, 2021 · 1 comment

Comments

@rovo89
Copy link

rovo89 commented May 4, 2021

I have a scenario with hundreds of servers with different Perl versions and operating systems. On these servers, I need to run a script which decodes a JSON file. I can push additional libraries to the servers via a shared directory, but due to the different Perl versions, they can't contain XS code.

I'd like to leverage a pre-installed JSON::XS wherever possible and fall back to JSON::PP otherwise. Caveat: I use boolean_values(), which is only available from version 4.0. Various servers have only JSON::XS version 3.0.1, so this call fails.

Is there any way to use JSON::XS only if it has a certain minimum version / supports a certain method and use PP otherwise?
I also tried -support_by_pp, but it didn't help here.

@charsbar
Copy link
Collaborator

charsbar commented May 4, 2021

I hope this works for you.

BEGIN {
    if ( !eval { require JSON::XS; JSON::XS->VERSION(4.00) } ) {
        $ENV{PERL_JSON_BACKEND} = 'JSON::backportPP'; 
    }
}
use JSON;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants