Update: As ikegami++ points out, the below won't work: as mentioned in the documentation, the different backends have incompatible object formats, so you can't mix-and-match. Without updating any modules, then, the only way to get at this functionality is to use JSON::PP as the backend (eg by setting the PERL_JSON_BACKEND environment variable), which will be at the cost of the speed benefit of the XS backend.
It should be possible to create a shim module that checks which of the available backends has a boolean_values function, and sets the backend accordingly. But if the code is deployed only in a single place that probably has little value.
I would expect the approach in my original answer below to work for classes that have a single master object and delegate to your choice of backends for the functionality - this is how I wrongly thought the JSON class worked.
Looking at the code for JSON-4.02, there is no mention of boolean_values, so I suspect you will need to call the JSON::PP function explicitly. This should work:
JSON::PP::boolean_values($json, 0, 1);Alternatively, in your code you could inject the desired pass-through function into the JSON package:
{ package JSON { sub boolean_values { JSON::PP::boolean_values(@_); } }; }
.. or create your own application-specific JSON wrapper:
package Our::JSON; use base qw{ JSON }; sub boolean_values { JSON::PP::boolean_values(@_); } 1;
For extra points, inject the function in a BEGIN block only if !JSON->can('boolean_values'), so it automatically turns itself off when a JSON release catches up - that doesn't seem to have happened yet as of v4.10.
I'd recommend reporting this as an issue against the JSON package, it's possible I'm missing some good reason why this isn't already implemented - I suspect it involves no more than adding it to the @PublicMethods list, with corresponding docs and tests.
In reply to Re: Issues using boolean_values in JSON v4.02
by hv
in thread Issues using boolean_values in JSON v4.02
by bc3-au
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |