Update JSON-PP to CPAN version 2.27104
authorChris 'BinGOs' Williams <chris@bingosnet.co.uk>
Mon, 21 Feb 2011 22:48:18 +0000 (22:48 +0000)
committerChris 'BinGOs' Williams <chris@bingosnet.co.uk>
Mon, 21 Feb 2011 22:48:18 +0000 (22:48 +0000)
  [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.

Porting/Maintainers.pl
cpan/JSON-PP/lib/JSON/PP.pm
cpan/JSON-PP/t/113_overloaded_eq.t
pod/perldelta.pod

index d9d2423..b90230d 100755 (executable)
@@ -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
index d2e36c2..5b4868b 100644 (file)
@@ -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 },
index 4d2ddce..7b56ab3 100644 (file)
@@ -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;
index 0072e75..765ed01 100644 (file)
@@ -96,7 +96,7 @@ XXX
 
 =item *
 
-XXX
+C<JSON::PP> has been upgraded from version 2.27103 to 2.27104
 
 =back