Skip to content
This repository

Error with JSON::JOM #33

Open
nuba opened this Issue August 13, 2012 · 3 comments

2 participants

Nuba Princigalli Breno G. de Oliveira
Nuba Princigalli
nuba commented August 13, 2012

Just ran into this yesterday:

$ use JSON::JOM qw/from_json/; 
$ use Data::Printer;           
$ use Data::Dumper;            

my test case

$ my $min_json = '{"alpha":1}';
{"alpha":1}

and the output with Data::Dumper

$ Dumper from_json $min_json
$VAR1 = bless( {
                 'alpha' => bless( do{\(my $o = 1)}, 'JSON::JOM::Value' )
               }, 'JSON::JOM::Object' );

and where Data::Printer breaks

$ p from_json $min_json
Use of uninitialized value $ref in exists at /home/nuba/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/Data/Printer.pm line 257.
Use of uninitialized value $ref in exists at /home/nuba/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/Data/Printer.pm line 269.
Runtime error: Package::Stash->new must be passed the name of the package to access at /home/nuba/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/Data/Printer.pm line 703.

versions I have here:

Data::Dumper 2.135_06
JSON::JOM 0.501
Data::Printer 0.32
Breno G. de Oliveira
Owner
garu commented August 13, 2012

Can you help me reproduce? Here it seems to work fine:

$ perl -MDDP -MJSON::JOM=from_json -E 'p from_json q[{"alpha":1}]'
JSON::JOM::Object {
Parents JSON::JOM::Node
public methods (5) : can, new, TO_JSON, toJSON, typeof
private methods (0)
internals: {
alpha JSON::JOM::Value
} (tied to JSON::JOM::Object::Tie)
} (tied to JSON::JOM::Object::Tie) (tied to JSON::JOM::Object::Tie)

Breno G. de Oliveira
Owner
garu commented August 13, 2012

nevermind. Got it!

Nuba Princigalli
nuba commented August 16, 2012

Explored the problem a little more, and It seems the root is in how JSON::JOM::Value uses UNIVERSAL::ref

replacing

sub ref { return }

with

sub ref { return 'JSON::JOM::Value' }

then when loading JSON::JOM first,
Data::Printer outputs (filtered with Data::Printer::Filter::JSON):

\ {
    a   \ false,
    b   \ "lalala",
    c   {
        ca   [
            [0] \ 1,
            [1] \ 2,
            [2] \ 3
        ] (tied to JSON::JOM::Array::Tie)
    } (tied to JSON::JOM::Object::Tie)
} (tied to JSON::JOM::Object::Tie) (tied to JSON::JOM::Object::Tie)

and when loading Data::Printer first, the output is

\ \ {
    a   \ false,
    b   \ "lalala",
    c   \ \ {
        ca   \ \ [
            [0] \ 1,
            [1] \ 2,
            [2] \ 3
        ]
    }
}

hope it helps :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.