From 37c10d56bf558fc0df0f97422fd7dd72672672c7 Mon Sep 17 00:00:00 2001 From: "Deven T. Corzine" Date: Tue, 17 Mar 2020 13:56:48 -0400 Subject: [PATCH] Fix prototype mismatch warning for JSON functions. 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! --- lib/Catalyst/Plugin/RapidApp/NavCore/Controller.pm | 2 +- lib/RapidApp/JSON/MixedEncoder.pm | 6 +++--- lib/RapidApp/Test.pm | 2 +- lib/RapidApp/Test/Client.pm | 2 +- lib/RapidApp/Util/MetaKeys.pm | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/Catalyst/Plugin/RapidApp/NavCore/Controller.pm b/lib/Catalyst/Plugin/RapidApp/NavCore/Controller.pm index e586b0a7..bf11537d 100644 --- a/lib/Catalyst/Plugin/RapidApp/NavCore/Controller.pm +++ b/lib/Catalyst/Plugin/RapidApp/NavCore/Controller.pm @@ -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 diff --git a/lib/RapidApp/JSON/MixedEncoder.pm b/lib/RapidApp/JSON/MixedEncoder.pm index 18c5bbb3..50335dc2 100644 --- a/lib/RapidApp/JSON/MixedEncoder.pm +++ b/lib/RapidApp/JSON/MixedEncoder.pm @@ -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]); } diff --git a/lib/RapidApp/Test.pm b/lib/RapidApp/Test.pm index 9628b83a..2cf07bd2 100644 --- a/lib/RapidApp/Test.pm +++ b/lib/RapidApp/Test.pm @@ -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; diff --git a/lib/RapidApp/Test/Client.pm b/lib/RapidApp/Test/Client.pm index 2f8222f4..acdd43f5 100644 --- a/lib/RapidApp/Test/Client.pm +++ b/lib/RapidApp/Test/Client.pm @@ -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: diff --git a/lib/RapidApp/Util/MetaKeys.pm b/lib/RapidApp/Util/MetaKeys.pm index 3840c17f..df7d7e2c 100644 --- a/lib/RapidApp/Util/MetaKeys.pm +++ b/lib/RapidApp/Util/MetaKeys.pm @@ -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;