vanstyn / RapidApp

Turnkey ajaxy webapps
http://rapi.io
Other
48 stars 15 forks source link

Fix prototype mismatch warning for JSON functions. #182

Open deven opened 4 years ago

deven commented 4 years ago

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!

nrdvana commented 4 years ago

I'm not sure that fixing the warning is the right thing to do. The RapidApp MixedEncoder is not compatible with the JSON module in the first place (MixedEncoder is writing javascript, where JSON module is strictly json) and it depends on using JSON::PP internally. So, if you use JSON::XS and use RapidApp::JSON::MixedEncoder in the same file, one of those is not going to have the desired effect. Probably the names of the functions exported by MixedEncoder should have been named something different, like "encode_javascript", but its a bit late to change now. maybe.

vanstyn commented 3 years ago

@nrdvana - looks like @deven has made some changes since your comment, can you comment to see if this PR is a good thing to merge now in your opinion. Also, why does CI show failure? I'm not going to merge a PR thats failing in Travis

vanstyn commented 3 years ago

@nrdvana - looks like @deven has made some changes since your comment, can you comment to see if this PR is a good thing to merge now in your opinion. Also, why does CI show failure? I'm not going to merge a PR thats failing in Travis

@nrdvana - is it a good thing to merge in your opinion? I haven't found the time to look closely and probably won't for a while. as I recall you wrote MixedEncoder not me...

vanstyn commented 3 years ago

@deven - also and separately, one of you will need to investigate the CI test fails before it can be considered for merge