diff options
author | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2011-02-21 22:48:18 +0000 |
---|---|---|
committer | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2011-02-21 22:48:18 +0000 |
commit | 05bd2440ec700e08a3d803cbc640591d8ff3b2bd (patch) | |
tree | f0919da90c05a009376a4db9172f6baf55572ee1 /cpan | |
parent | 3097108be5f219f149228ea1c8c8c14b1e4e2199 (diff) | |
download | perl-05bd2440ec700e08a3d803cbc640591d8ff3b2bd.tar.gz |
Update JSON-PP to CPAN version 2.27104
[DELTA]
2.27104 Thu Jan 20 19:06:25 2011
- fixed a problem to convert overloaded objects (pointed by rt#64783)
- changed decoding methods object() and array() to pass a object.
Diffstat (limited to 'cpan')
-rw-r--r-- | cpan/JSON-PP/lib/JSON/PP.pm | 35 | ||||
-rw-r--r-- | cpan/JSON-PP/t/113_overloaded_eq.t | 41 |
2 files changed, 60 insertions, 16 deletions
diff --git a/cpan/JSON-PP/lib/JSON/PP.pm b/cpan/JSON-PP/lib/JSON/PP.pm index d2e36c20ed..5b4868b5b2 100644 --- a/cpan/JSON-PP/lib/JSON/PP.pm +++ b/cpan/JSON-PP/lib/JSON/PP.pm @@ -11,7 +11,7 @@ use Carp (); use B (); #use Devel::Peek; -$JSON::PP::VERSION = '2.27103'; +$JSON::PP::VERSION = '2.27104'; @JSON::PP::EXPORT = qw(encode_json decode_json from_json to_json); @@ -322,8 +322,8 @@ sub allow_bigint { if ( $convert_blessed and $obj->can('TO_JSON') ) { my $result = $obj->TO_JSON(); - if ( defined $result and overload::Overloaded( $obj ) ) { - if ( overload::StrVal( $obj ) eq $result ) { + if ( defined $result and ref( $result ) ) { + if ( refaddr( $obj ) eq refaddr( $result ) ) { encode_error( sprintf( "%s::TO_JSON method returned same object as was passed instead of a new one", ref $obj @@ -889,7 +889,7 @@ BEGIN { sub array { - my $a = []; + my $a = $_[0] || []; # you can use this code to use another array ref object. decode_error('json text or perl structure exceeds maximum nesting level (max_depth set too low?)') if (++$depth > $max_depth); @@ -939,7 +939,7 @@ BEGIN { sub object { - my $o = {}; + my $o = $_[0] || {}; # you can use this code to use another hash ref object. my $k; decode_error('json text or perl structure exceeds maximum nesting level (max_depth set too low?)') @@ -1338,6 +1338,7 @@ BEGIN { unless($@){ *JSON::PP::blessed = \&Scalar::Util::blessed; *JSON::PP::reftype = \&Scalar::Util::reftype; + *JSON::PP::refaddr = \&Scalar::Util::refaddr; } else{ # This code is from Sclar::Util. # warn $@; @@ -1367,6 +1368,23 @@ BEGIN { : length(ref($$r)) ? 'REF' : 'SCALAR'; }; + *JSON::PP::refaddr = sub { + return undef unless length(ref($_[0])); + + my $addr; + if(defined(my $pkg = blessed($_[0]))) { + $addr .= bless $_[0], 'Scalar::Util::Fake'; + bless $_[0], $pkg; + } + else { + $addr .= $_[0] + } + + $addr =~ /0x(\w+)/; + local $^W; + #no warnings 'portable'; + hex($1); + } } } @@ -1386,13 +1404,6 @@ sub null { undef; } package JSON::PP::Boolean; -#BEGIN { # when renamed into JSON::PP, delete this code. -# # avoid for warning Can't locate package JSON::PP::Boolean for @JSON::PP::Boolean::ISA -# eval q{ package JSON::PP::Boolean; }; -# @JSON::PP::Boolean::ISA = ('JSON::PP::Boolean'); -#} - -# @JSON::PP::Boolean::ISA = ('JSON::PP::Boolean'); use overload ( "0+" => sub { ${$_[0]} }, "++" => sub { $_[0] = ${$_[0]} + 1 }, diff --git a/cpan/JSON-PP/t/113_overloaded_eq.t b/cpan/JSON-PP/t/113_overloaded_eq.t index 4d2ddce410..7b56ab3e24 100644 --- a/cpan/JSON-PP/t/113_overloaded_eq.t +++ b/cpan/JSON-PP/t/113_overloaded_eq.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use strict; -use Test::More tests => 2; +use Test::More tests => 4; BEGIN { $ENV{ PERL_JSON_BACKEND } = 0; @@ -9,14 +9,47 @@ BEGIN { use JSON::PP; -my $obj = OverloadedObject->new( 'foo' ); +my $json = JSON::PP->new->convert_blessed; +my $obj = OverloadedObject->new( 'foo' ); ok( $obj eq 'foo' ); +is( $json->encode( [ $obj ] ), q{["foo"]} ); -my $json = JSON::PP->new->convert_blessed; +# rt.cpan.org #64783 +my $foo = bless {}, 'Foo'; +my $bar = bless {}, 'Bar'; + +eval q{ $json->encode( $foo ) }; +ok($@); +eval q{ $json->encode( $bar ) }; +ok(!$@); -is( $json->encode( [ $obj ] ), q{["foo"]} ); +package Foo; + +use strict; +use overload ( + 'eq' => sub { 0 }, + '""' => sub { $_[0] }, + fallback => 1, +); + +sub TO_JSON { + return $_[0]; +} + +package Bar; + +use strict; +use overload ( + 'eq' => sub { 0 }, + '""' => sub { $_[0] }, + fallback => 1, +); + +sub TO_JSON { + return overload::StrVal($_[0]); +} package OverloadedObject; |