Spot the error
use Data::Rmap qw(:all);
use JSON;
use Data::Dump;
use Clone;
use boolean;
my $arg = from_json(q{{"1":true,"2":false}});
# convert JSON booleans to boolean's booleans
rmap_all { bless $_,"boolean" if ref($_) =~ /^JSON::(XS|PP)::Boolean$/ }, $arg;
dd $arg;
Hint: it's one character long.
In fact, this piece of code is full of Perl's traps (from Perl's lack of booleans obviously, to less obviously having to clone and rmap not working), it disgusts me.
I say it's the comma after the rmap_all block.
Btw, to avoid some misunderstanding: I did not post about this problem on IRC (I don't hang out at IRC channels), I just found out about Data::Rmap today, and I am not complaining about Perl (instead, of my own piece of code).
@Sawyer: yep.
You are also relying on the internals of both boolean and JSON's boolean values, and breaking them in the process. JSON (PP or XS) uses singleton objects for the booleans, which means you are trying to rebless the constants $JSON::true and $JSON::false. With JSON::XS, this gives errors about modifying read only values. With JSON::PP, it works but breaks the is_bool sub.
A more correct conversion would be:
rmap_all { JSON::is_bool($_) ? ( $_ ? true : false ) : $_ } $arg;
Or actually:
rmap_all { $_ = $_ ? true : false if JSON::is_bool($_) } $arg;
Probably should have checked the docs on Data::Rmap before replying.
@Graham: I rebless instead of assigning to $_ (which should be clearer) because the code was converted from the one that uses Data::Walk. Now that I use Data::Rmap, I can use assignment. Thanks, my code is now improved.