in reply to Re^7: JSON::XS and blessings
in thread JSON::XS and blessings

Haha, yes. Except that in this case it's totally repeatable. One virtual server always has a live cat, the other always has a dead cat.

Replies are listed 'Best First'.
Re^9: JSON::XS and blessings
by Corion (Patriarch) on Oct 15, 2015 at 13:40 UTC

    You have already stated that the problem only occurs when Apache is involved.

    Have you stopped and restarted Apache?

    Does the problem persist when the Perl script is run as a CGI program instead of being run as a mod_perl script?

    Check the versions of all modules loaded into mod_perl and compare them between the two machines:

    for my $module (sort keys %INC) { (my $namespace = $module) =~ s!/!::!g; $namespace =~ s/\.pm$//; print sprintf "Module: %s; Path: %s; Size: %d; VERSION: %s\n", $module, $INC{$module}, -s($INC{$module}), $namespace->VERSION +; }

    Note that you need to run the above output from within Apache, because when run from the shell everything seems to be OK for you.

      Thanks! It was a great idea to compare the %INC of the two virtual servers. I did, and unfortunately they are identical. %INC in both has about 350 keys, and the outputs including version numbers are identical.

      And yes, I restarted apache several times while debugging this.

      Back to the original problem: my understanding is that decode_json('{"a":true}')returns a ref to a hash with key 'a' and value true which isa JSON:PP:Boolean. If there a way to print attributes of decode_json('{"a":true}')->{a} such that I can compare them between the two servers?

        %INC is supposed to contain paths :)
      Running on both virtual server apache servers,

      my $json = '{"a":true}'; $d = decode_json($json); printf "Dumper: %s<br>\n",Dumper($d);

      prints the same: Dumper: $VAR1 = { 'a' => bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' ) };

      Yet encode_json($d) fails on one and works correctly on the other.

        In checking what I thought were reasonable assumptions, I found that JSON::PP's handling of booleans and JSON::XS's handling of booleans are simply incompatible.

        use JSON::XS(); use JSON::PP(); JSON::XS->new()->encode( JSON::PP->new()->decode('[true]') ); __END__ encountered object '1', but neither allow_blessed nor convert_blessed +settings are enabled

        Note that even enabling convert_blessed() won't help as JSON::PP generates booleans that don't even have a TO_JSON() method. [And enabling allow_blessed() would just turn true/false into null.]

        Both modules could use some work on dealing with booleans.

        - tye