Skip to content

Commit 931a070

Browse files
switch backends from JSON to JSON::MaybeXS
This allows for more choices in backends, including Cpanel::JSON::XS, which has fewer incompatibilities.
1 parent af1b10d commit 931a070

File tree

8 files changed

+22
-20
lines changed

8 files changed

+22
-20
lines changed

META.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@
5252
},
5353
"runtime" : {
5454
"recommends" : {
55-
"JSON::XS" : "0"
55+
"Cpanel::JSON::XS" : "0"
5656
},
5757
"requires" : {
5858
"CGI" : "0",
5959
"Class::Accessor::Lite" : "0",
6060
"HTTP::Request" : "0",
6161
"HTTP::Response" : "0",
62-
"JSON" : "0",
62+
"JSON::MaybeXS" : "0",
6363
"LWP::UserAgent" : "0",
6464
"Plack" : "0",
6565
"Router::Simple" : "0",

cpanfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ requires 'CGI';
22
requires 'Class::Accessor::Lite';
33
requires 'HTTP::Request';
44
requires 'HTTP::Response';
5-
requires 'JSON';
5+
requires 'JSON::MaybeXS';
66
requires 'LWP::UserAgent';
77
requires 'Plack';
88
requires 'Router::Simple';
99
requires 'parent';
10-
recommends 'JSON::XS';
10+
recommends 'Cpanel::JSON::XS';
1111

1212
on build => sub {
1313
requires 'ExtUtils::MakeMaker', '6.36';

lib/JSON/RPC/Dispatch.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ sub new {
2424
@args,
2525
}, $class;
2626
if (! $self->{coder}) {
27-
require JSON;
28-
$self->{coder} = JSON->new->utf8;
27+
require JSON::MaybeXS;
28+
$self->{coder} = JSON::MaybeXS::JSON()->new->utf8;
2929
}
3030
if (! $self->{parser}) {
3131
$self->{parser} = JSON::RPC::Parser->new( coder => $self->coder )

lib/JSON/RPC/Legacy/Client.pm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
##############################################################################
55

66
use strict;
7-
use JSON ();
7+
use JSON::MaybeXS 'JSON';
88
use Carp ();
99

1010
##############################################################################
@@ -62,7 +62,7 @@ sub AUTOLOAD {
6262

6363

6464
sub create_json_coder {
65-
JSON->new->allow_nonref->utf8;
65+
JSON()->new->allow_nonref->utf8;
6666
}
6767

6868

@@ -349,9 +349,9 @@ Setter/getter to L<LWP::UserAgent> object.
349349
=item json
350350
351351
Setter/getter to the JSON coder object.
352-
Default is L<JSON>, likes this:
352+
The default is the backend returned by L<JSON::MaybeXS>, created like this:
353353
354-
$self->json( JSON->new->allow_nonref->utf8 );
354+
$self->json( JSON()->new->allow_nonref->utf8 );
355355
356356
$json = $self->json;
357357

lib/JSON/RPC/Legacy/Server.pm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
##############################################################################
55

66
use strict;
7-
use JSON ();
87
use Carp ();
98

109
use HTTP::Request ();
@@ -14,6 +13,7 @@ use HTTP::Response ();
1413
##############################################################################
1514

1615
package JSON::RPC::Legacy::Server;
16+
use JSON::MaybeXS 'JSON';
1717

1818
my $JSONRPC_Procedure_Able;
1919

@@ -43,7 +43,7 @@ BEGIN {
4343

4444

4545
sub create_json_coder {
46-
JSON->new->utf8; # assumes UTF8
46+
JSON()->new->utf8; # assumes UTF8
4747
}
4848

4949

@@ -569,9 +569,9 @@ An error code number in your procedure is an integer between 501 and 899.
569569
=item json
570570
571571
Setter/Getter to json encoder/decoder object.
572-
The default value is L<JSON> object in the below way:
572+
The default value is a JSON serializer object as returned by L<JSON::MaybeXS> in the following manner:
573573
574-
JSON->new->utf8
574+
JSON()->new->utf8
575575
576576
In your procedure, changes its behaviour.
577577

t/002_basic.t

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use warnings;
33
use Test::More;
44
use Plack::Test;
55
use HTTP::Request;
6-
use JSON;
6+
use JSON::MaybeXS;
77

88
BEGIN {
99
use_ok "JSON::RPC::Dispatch";
@@ -15,7 +15,8 @@ BEGIN {
1515
subtest 'defaults' => sub {
1616
my $dispatch = JSON::RPC::Dispatch->new();
1717
if (ok $dispatch->coder) {
18-
isa_ok $dispatch->coder, 'JSON';
18+
my $json_backend = JSON::MaybeXS::JSON();
19+
isa_ok $dispatch->coder, $json_backend;
1920
}
2021

2122
if (ok $dispatch->router) {
@@ -28,7 +29,7 @@ subtest 'defaults' => sub {
2829
};
2930

3031
subtest 'normal dispatch' => sub {
31-
my $coder = JSON->new;
32+
my $coder = JSON()->new;
3233
my $router = Router::Simple->new;
3334
$router->connect( blowup => {
3435
handler => "Sum",

t/003_parser.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use strict;
22
use Test::More;
33
use Plack::Request;
4-
use JSON;
4+
use JSON::MaybeXS 'to_json', 'JSON';
55

66
use_ok "JSON::RPC::Parser";
77
use_ok "JSON::RPC::Procedure";
@@ -12,7 +12,7 @@ subtest 'basic' => sub {
1212
REQUEST_METHOD => "GET",
1313
} );
1414
my $parser = JSON::RPC::Parser->new(
15-
coder => JSON->new,
15+
coder => JSON()->new,
1616
);
1717

1818
my $procedure = $parser->construct_from_req( $req );

t/legacy/02_server.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ my $server = JSON::RPC::Legacy::Server->new;
88

99
isa_ok($server, 'JSON::RPC::Legacy::Server');
1010

11-
isa_ok($server->json, 'JSON');
11+
my $json_backend = JSON::MaybeXS::JSON();
12+
isa_ok($server->json, $json_backend);
1213

1314
my $test = JSON::RPC::Legacy::Server::Test->new;
1415

0 commit comments

Comments
 (0)