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 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->newinstance goes through theTO_JSONmethod, 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.