Interesting, I like it also. Let's see what makemaka says 2015-04-20 6:27 GMT+02:00 Michael R. Davis via Houston <[email protected]>: > Reini, > I added the TO_JSON_WITH_TYPE API to my JSON fork on Github. Let me know > what you think. I like this API much better than the TO_JSON API. It > supports BOOLEAN out of the box as well. It's just a better all around API. > I coded it so if the object has both TO_JSON and TO_JSON_WITH_TYPE the "with > type" method will be selected first so we can have backwards compatibility > too. > Thanks, > Mike > > https://github.com/makamaka/JSON/compare/master...mrdvt92:master > > perl -e ' > use strict; > use warnings; > use blib; > BEGIN { $ENV{PERL_JSON_BACKEND} = "JSON::backportPP"; } > use JSON; > use Data::Dumper qw{Dumper}; > use Hash::Ordered qw{}; > sub Hash::Ordered::TO_JSON_WITH_TYPE {HASH=>[shift->as_list]}; > my $oh=Hash::Ordered->new(a => 1, b=>2, c=>3, d=>4, e=>5); > #print Dumper($oh); > #print join(",", @{$oh->TO_JSON_WITH_TYPE()}), "\n"; > my $coder = JSON->new->allow_blessed->convert_blessed; > print $coder->encode({myhash=>$oh}), "\n"; > ' > > {"myhash":{"a":1,"b":2,"c":3,"d":4,"e":5}} > > > > _______________________________________________ > Houston mailing list > [email protected] > http://mail.pm.org/mailman/listinfo/houston > Website: http://houston.pm.org/
-- Reini Urban http://cpanel.net/ http://www.perl-compiler.org/ _______________________________________________ Houston mailing list [email protected] http://mail.pm.org/mailman/listinfo/houston Website: http://houston.pm.org/
