diff options
-rwxr-xr-x | Porting/Maintainers.pl | 2 | ||||
-rw-r--r-- | cpan/JSON-PP/lib/JSON/PP.pm | 35 | ||||
-rw-r--r-- | cpan/JSON-PP/t/113_overloaded_eq.t | 41 | ||||
-rw-r--r-- | pod/perldelta.pod | 2 |
4 files changed, 62 insertions, 18 deletions
diff --git a/Porting/Maintainers.pl b/Porting/Maintainers.pl index d9d24231bd..b90230d8c4 100755 --- a/Porting/Maintainers.pl +++ b/Porting/Maintainers.pl @@ -871,7 +871,7 @@ use File::Glob qw(:case); 'JSON::PP' => { 'MAINTAINER' => 'makamaka', - 'DISTRIBUTION' => 'MAKAMAKA/JSON-PP-2.27103.tar.gz', + 'DISTRIBUTION' => 'MAKAMAKA/JSON-PP-2.27104.tar.gz', 'FILES' => q[cpan/JSON-PP], 'EXCLUDED' => [ 't/900_pod.t', # Pod testing 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; diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 0072e75fc1..765ed01092 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -96,7 +96,7 @@ XXX =item * -XXX +C<JSON::PP> has been upgraded from version 2.27103 to 2.27104 =back |