Skip to content

Commit

Permalink
Fix prototype mismatch warning for JSON functions.
Browse files Browse the repository at this point in the history
The prototypes used in RapidApp::JSON::MixedEncoder for encode_json()
and decode_json() match the respective prototypes in JSON::XS, but they
don't match the prototypes used for those functions in Cpanel::JSON::XS,
which JSON::MaybeXS will use in preference to JSON::XS.

This can be easily demonstrated by including both modules:

$ perl -MJSON::MaybeXS -MRapidApp::JSON::MixedEncoder -e 0
Prototype mismatch: sub main::encode_json ($;$) vs ($) at /usr/share/perl/5.26/Exporter.pm line 66.
 at -e line 0.
Prototype mismatch: sub main::decode_json ($;$$) vs ($) at /usr/share/perl/5.26/Exporter.pm line 66.
 at -e line 0.

RapidApp uses Catalyst, which uses JSON::MaybeXS, causing this prototype
mismatch warning.  This commit fixes this problem by using JSON::MaybeXS
where the JSON module was previously used, and changing the prototypes
for encode_json() and decode_json() in RapidApp::JSON::MixedEncoder to
match the prototypes in Cpanel::JSON::XS, rather than JSON::XS.

Note that this change means that using RapidApp::JSON::MixedEncoder with
either JSON::XS or JSON will now cause a prototype mismatch warning!
  • Loading branch information
deven committed Mar 19, 2020
1 parent cb4c6bd commit 37c10d5
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/Catalyst/Plugin/RapidApp/NavCore/Controller.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use RapidApp::Util qw(:all);
require Module::Runtime;
require Catalyst::Utils;

use JSON qw(decode_json);
use JSON::MaybeXS qw(decode_json);

# Controller for loading a saved search in CoreSchema via ID

Expand Down
6 changes: 3 additions & 3 deletions lib/RapidApp/JSON/MixedEncoder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ our %SCALARREF_VALUE_MAP = (
# ---


# copied from JSON::PP
# copied from JSON::PP, but match prototypes to Cpanel::JSON::XS.
my $JSON; # cache
sub encode_json ($) { # encode
sub encode_json ($;$) { # encode
($JSON ||= __PACKAGE__->new)->encode($_[0]);
}
sub decode_json ($) { # decode
sub decode_json ($;$$) { # decode
($JSON ||= __PACKAGE__->new)->decode($_[0]);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/RapidApp/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use Import::Into;

use Time::HiRes qw(gettimeofday tv_interval);
use HTTP::Request::Common;
use JSON qw(decode_json);
use JSON::MaybeXS qw(decode_json);
use Catalyst::Utils;
use RapidApp::Test::Client;

Expand Down
2 changes: 1 addition & 1 deletion lib/RapidApp/Test/Client.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Scalar::Util qw(blessed);
use Time::HiRes qw(gettimeofday tv_interval);
use LWP::UserAgent;
use HTTP::Request::Common;
use JSON qw(decode_json);
use JSON::MaybeXS qw(decode_json);
use Try::Tiny;

# shorthand aliases:
Expand Down
2 changes: 1 addition & 1 deletion lib/RapidApp/Util/MetaKeys.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use Types::Standard qw(:all);
use Scalar::Util qw(blessed);

use RapidApp::Util::MetaKeys::FK;
use JSON qw( from_json -support_by_pp );
use JSON::MaybeXS qw( from_json );
use Path::Class qw( file dir );
use Try::Tiny;

Expand Down

0 comments on commit 37c10d5

Please sign in to comment.