You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The settings variables are global variables (although not visible in a global scope); they may be clobbered by a reentrant call to JSON::PP.
Here is a minimal test case demonstrating the problem:
use JSON;
sub MyClass::new { bless {}, shift }
sub MyClass::TO_JSON { encode_json([]) }
my $jsonist = JSON->new->convert_blessed;
print "So far, so good:\n";
print $jsonist->encode([MyClass->new]);
print "But the next line will crash:\n";
print $jsonist->encode([MyClass->new, MyClass->new]);
In the last line, the “JSONificiation” of a first MyClass->new instance goes through the TO_JSON method, which changes the global variables, which prevents the “JSONification” of the second object.
All the settings variables should be refactored as instance properties of the object returned by JSON->new.
The text was updated successfully, but these errors were encountered:
I just hit this issue as well. It has been open for only a year in a core Perl module - is there any likelihood of it being fixed? Otherwise I'll open an issue in the Perl github.
The settings variables are global variables (although not visible in a global scope); they may be clobbered by a reentrant call to JSON::PP.
Here is a minimal test case demonstrating the problem:
In the last line, the “JSONificiation” of a first
MyClass->new
instance goes through theTO_JSON
method, which changes the global variables, which prevents the “JSONification” of the second object.All the settings variables should be refactored as instance properties of the object returned by
JSON->new
.The text was updated successfully, but these errors were encountered: