Skip to content

Commit

Permalink
Replace JSON -> JSON::MaybeXS, JSON::XS -> Cpanel::JSON::XS
Browse files Browse the repository at this point in the history
  • Loading branch information
perlancar committed Mar 9, 2016
1 parent d3c987d commit fbc2fb5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
15 changes: 9 additions & 6 deletions bin/check-json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!perl

# DATE
# VERSION

use 5.010;
use strict;
use warnings;

use Getopt::Long;

# VERSION

my $json_mod = '';
GetOptions(
'pp' => sub { $json_mod = 'PP' },
Expand All @@ -22,9 +23,9 @@ my $json;
if ($json_mod eq 'PP') {
require JSON::PP; $json = JSON::PP->new->allow_nonref;
} elsif ($json_mod eq 'XS') {
require JSON::XS; $json = JSON::XS->new->allow_nonref;
require Cpanel::JSON::XS; $json = Cpanel::JSON::XS->new->allow_nonref;
} else {
require JSON; $json = JSON ->new->allow_nonref;
require JSON::MaybeXS; $json = JSON->new->allow_nonref;
}

eval {
Expand All @@ -49,11 +50,13 @@ Check JSON syntax. Prints nothing if JSON syntax is okay.
=item * --pp
Force using L<JSON::PP> instead of L<JSON>.
Force using a PP module (currently L<JSON::PP>) instead of the default
L<JSON::MaybeXS>.
=item * --xs
Force using L<JSON::XS> instead of L<JSON>.
Force using an XS module (currently L<Cpanel::JSON::XS>) instead of
the default L<JSON::MaybeXS>.
=back
Expand Down
18 changes: 10 additions & 8 deletions bin/pp-json
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ use Getopt::Long;

my $json_mod = '';
GetOptions(
'pp' => sub { $json_mod = 'PP' },
'xs' => sub { $json_mod = 'XS' },
'pp' => sub { $json_mod = 'pp' },
'xs' => sub { $json_mod = 'xs' },
'help' => sub {
print "Usage: pp-json [--pp|--xs] <file>\n";
exit 0;
},
);

my $json;
if ($json_mod eq 'PP') {
if ($json_mod eq 'pp') {
require JSON::PP; $json = JSON::PP->new;
} elsif ($json_mod eq 'XS') {
require JSON::XS; $json = JSON::XS->new;
} elsif ($json_mod eq 'xs') {
require Cpanel::JSON::XS; $json = Cpanel::JSON::XS->new;
} else {
require JSON; $json = JSON ->new;
require JSON::MaybeXS; $json = JSON::MaybeXS->new;
}

$json->canonical->allow_nonref->pretty(1);
Expand All @@ -42,10 +42,12 @@ print $json->encode($json->decode(scalar <>));
=item * --pp
Force using L<JSON::PP> instead of L<JSON>.
Force using a PP module (currently L<JSON::PP>) instead of the default
L<JSON::MaybeXS>.
=item * --xs
Force using L<JSON::XS> instead of L<JSON>.
Force using an XS module (currently L<Cpanel::JSON::XS>) instead of
the default L<JSON::MaybeXS>.
=back
14 changes: 7 additions & 7 deletions bin/serializeutils-convert
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!perl

# DATE
# VERSION

use 5.010001;
use strict;
use warnings;

# VERSION
# DATE

my ($from, $to) = $0 =~ /(\w+)2(\w+)\z/
or die "Can't determine what formats to convert from/to, ".
"please call me as one of dd2json, json2dd, etc.\n";
Expand All @@ -19,8 +19,8 @@ if ($from eq 'dd') {
} elsif ($from eq 'ddc') {
$code_from = 'eval ~~<>';
} elsif ($from eq 'json') {
require JSON;
$code_from = 'JSON->new->allow_nonref->decode(~~<>)';
require JSON::MaybeXS;
$code_from = 'JSON::MaybeXS->new->allow_nonref->decode(~~<>)';
} elsif ($from eq 'phpser') {
require PHP::Serialization;
$code_from = 'PHP::Serialization::unserialize(~~<>)';
Expand All @@ -46,8 +46,8 @@ if ($to eq 'dd') {
require Data::Dump::Color;
$code_to = "Data::Dump::Color::dump($code_from)";
} elsif ($to eq 'json') {
require JSON;
$code_to = "JSON->new->allow_nonref->encode($code_from)";
require JSON::MaybeXS;
$code_to = "JSON::MaybeXS->new->allow_nonref->encode($code_from)";
} elsif ($to eq 'phpser') {
require PHP::Serialization;
$code_to = "PHP::Serialization::serialize($code_from)";
Expand Down
9 changes: 2 additions & 7 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,14 @@ name=App-SerializeUtils
[Prereqs]
perl=5.010001

; core modules

strict=0
warnings=0
Getopt::Long=0
Storable=0

; non-core modules

JSON=0
JSON::MaybeXS=0
;JSON::Color=0
JSON::PP=0
JSON::XS=0
Cpanel::JSON::XS=0
Data::Dump=0
Data::Dump::Color=0
Sereal::Decoder=0
Expand Down

0 comments on commit fbc2fb5

Please sign in to comment.