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

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.

Replies are listed 'Best First'.
Re^10: JSON::XS and blessings
by cshavit (Novice) on Oct 16, 2015 at 02:45 UTC
    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 :)
        This is an excerpt from the running the script:

        Module: Apache2/Response.pm; Path: /usr/lib/perl5/Apache2/Response.pm; + Size: 10086; VERSION: 2.000008 Module: Apache2/ServerUtil.pm; Path: /usr/lib/perl5/Apache2/ServerUtil +.pm; Size: 22344; VERSION: 2.000008 Module: Apache2/XSLoader.pm; Path: /usr/lib/perl5/Apache2/XSLoader.pm; + Size: 1153; VERSION: Module: AutoLoader.pm; Path: /usr/share/perl/5.18/AutoLoader.pm; Size: + 5487; VERSION: 5.73 Module: B.pm; Path: /usr/lib/perl/5.18/B.pm; Size: 27972; VERSION: 1.4 +2_02 Module: B/Hooks/EndOfScope.pm; Path: /usr/local/share/perl/5.18.2/B/Ho +oks/EndOfScope.pm; Size: 3956; VERSION: 0.15 Module: B/Hooks/EndOfScope/XS.pm; Path: /usr/local/share/perl/5.18.2/B +/Hooks/EndOfScope/XS.pm; Size: 2618; VERSION: 0.15 Module: CGI.pm; Path: /usr/local/share/perl/5.18.2/CGI.pm; Size: 12339 +5; VERSION: 4.15

Re^10: JSON::XS and blessings
by cshavit (Novice) on Oct 16, 2015 at 03:26 UTC
    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        

        Interesting!

        As for me, I'd be happy to have a boolAsInt method, such that

        JSON->new()->boolAsInt(1)->decode('[true]')

        would return [1].