Initial import of JSON::MaybeXS
[p5sagit/JSON-MaybeXS.git] / lib / JSON / MaybeXS.pm
CommitLineData
3be1e192 1package JSON::MaybeXS;
2
3use strict;
4use warnings FATAL => 'all';
5use base qw(Exporter);
6
7BEGIN {
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
28our @EXPORT = qw(encode_json decode_json JSON);
29
30sub JSON () { our $JSON_Class }
31
321;