rurban / Cpanel-JSON-XS

Improved fork of JSON-XS

Home Page:http://search.cpan.org/dist/Cpanel-JSON-XS/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

documentation for unblessed_bool is incorrect/outdated

karenetheridge opened this issue · comments

The documentation says:

       $json = $json->unblessed_bool ([$enable])
       $enabled = $json->get_unblessed_bool
               $json = $json->unblessed_bool([$enable])

           If $enable is true (or missing), then "decode" will return Perl non-object boolean variables (1 and 0) for JSON booleans ("true" and "false"). If $enable is false, then "decode" will return "Cpanel::JSON::XS::Boolean"
           objects for JSON booleans.

This is not correct:

  1. blessed booleans are JSON::PP::Boolean objects now, not Cpanel::JSON::XS::Boolean
    2. unblessed_bool defaults to false.
: $; perl -MData::Dumper -MCpanel::JSON::XS -wle'print Dumper(Cpanel::JSON::XS->new->unblessed_bool->decode("[true]"))'
$VAR1 = [
          1
        ];

: $; perl -MData::Dumper -MCpanel::JSON::XS -wle'print Dumper(Cpanel::JSON::XS->new->unblessed_bool(0)->decode("[true]"))'
$VAR1 = [
          bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' )
        ];

: $; perl -MData::Dumper -MCpanel::JSON::XS -wle'print Dumper(Cpanel::JSON::XS->new->decode("[true]"))'
$VAR1 = [
          bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' )
        ];

The "or missing" does not indicate the default, it indicates that it will set the option true if you call it without passing a value (like the others).

Oops, thanks.

#164 actually closed this issue more than #163, oops.

Fixed with the PR #164