Commit | Line | Data |
3be1e192 |
1 | package JSON::MaybeXS; |
2 | |
3 | use strict; |
4 | use warnings FATAL => 'all'; |
5 | use base qw(Exporter); |
6 | |
7 | BEGIN { |
8 | our $JSON_Class; |
9 | |
10 | our @err; |
11 | |
12 | if (eval { require Cpanel::JSON::XS; 1; }) { |
13 | $JSON_Class = 'Cpanel::JSON::XS'; |
14 | } else { |
15 | push @err, "Error loading Cpanel::JSON::XS: $@"; |
16 | if (eval { require JSON::PP; 1; }) { |
17 | $JSON_Class = 'JSON::PP'; |
18 | } else { |
19 | push @err, "Error loading JSON::PP: $@"; |
20 | } |
21 | } |
22 | unless ($JSON_Class) { |
23 | die join("\n", "Couldn't load a JSON module:", @err); |
24 | } |
25 | $JSON_Class->import(qw(encode_json decode_json)); |
26 | } |
27 | |
28 | our @EXPORT = qw(encode_json decode_json JSON); |
29 | |
30 | sub JSON () { our $JSON_Class } |
31 | |
32 | 1; |