Cpanel-JSON-XS
view release on metacpan or search on metacpan
t/12_blessed.t view on Meta::CPAN
my $o1 = bless { a => 3 }, "XX"; # with TO_JSON
my $o2 = bless \(my $dummy1 = 1), "YY"; # without stringification
my $o3 = bless \(my $dummy2 = 1), "ZZ"; # with stringification
my $o4 = bless \(my $dummy3 = "\x{1f603}"), "ZZ"; # with stringification Unicode
my $o5 = bless \(my $dummy4 = ""), "Verbatim"; # with stringification empty string result
if (eval 'require Hash::Util') {
if ($Hash::Util::VERSION > 0.05) {
Hash::Util::lock_ref_keys($o1);
print "# blessed hash is locked\n";
}
else {
Hash::Util::lock_hash($o1);
print "# hash is locked\n";
}
}
else {
print "# locked hashes are not supported\n";
};
my $js = Cpanel::JSON::XS->new;
eval { $js->encode ($o1) }; ok ($@ =~ /allow_blessed/, 'error no allow_blessed');
eval { $js->encode ($o2) }; ok ($@ =~ /allow_blessed/, 'error w/o TO_JSON');
eval { $js->encode ($o3) }; ok ($@ =~ /allow_blessed/, 'error w stringify');
$js->convert_blessed;
my $r = $js->encode ($o1);
ok ($js->encode ($o1) eq '{"__":""}', "convert_blessed with TO_JSON $r");
( run in 0.350 second using v1.01-cache-2.11-cpan-26ccb49234f )