Subject: | Object state stored in globals |
Some of the parser object's state is kept in globals, making it
impossible to use two parsers at once.
The attached test decodes the same string twice, with different results.
Show quoted text
----- BEGIN RESULTS -----
1..2
ok 1
not ok 2
# Failed test at encapsulation.t line 21.
# Structures begin differing at:
# $got = 'died with "'"' expected, at character offset 1
(before "foo:"foo"}") at encapsulation.t line 14."'
# $expected = HASH(0x9e21af8)
# Looks like you failed 1 test of 2.
----- END RESULTS -----
Subject: | encapsulation.t |
use strict;
use warnings;
use Test::More tests => 2;
BEGIN { $ENV{PERL_JSON_BACKEND} = 'JSON::XS'; }
use JSON -support_by_pp;
use Data::Dumper;
sub test {
my ($coder, $str) = @_;
my $rv;
return $rv if eval { $rv = $coder->decode($str); 1 };
chomp( my $e = $@ );
return "died with \"$e\"";
};
my $coder = JSON->new->allow_barekey;
for (1..2) {
is_deeply( test($coder, q!{foo:"foo"}! ), {foo=>'foo'} );
JSON->new->allow_singlequote(0);
}