[Xml-compile] $_[0] + 0.0 for sloppy floats
Mark Overmeer
mark at overmeer.net
Tue Dec 16 16:57:45 GMT 2014
* Chase Whitener (cwhitener at gmail.com) [141216 16:17]:
> Sorry about that, I could have provided a more useful link to where the
> conversation started: http://irclog.perlgeek.de/mojo/2014-11-27#i_9730172
> >
> > perl -Mojo -E 'my $true_scalar = "1"; my $false_scalar = "0"; say j([1,
> > "1", \1, Mojo::JSON->true, \$true_scalar, 0, "0", \0, Mojo::JSON->false,
> > \$false_scalar])'
> >
> > perl -Mojo -E 'say j([1, \1, Mojo::JSON->true])'
I think this leads to a clean interface:
package My::Clean::Interface;
my @boolean_fields = qw/is_success need_more/;
my (@float_field, @int_fields);
sub send_data($) # extern we do not tell in which format
{ my $data = Data::Dumper::DeepCopy(shift);
$data->{$_} = $data->{$_} ? JSON::true : JSON::false
for @boolean_fields;
$data->{$_} += 0
for @float_fields, @int_fields; # avoid "3.14"
print json_encode $data;
}
--
Regards,
MarkOv
------------------------------------------------------------------------
Mark Overmeer MSc MARKOV Solutions
Mark at Overmeer.net solutions at overmeer.net
http://Mark.Overmeer.net http://solutions.overmeer.net
More information about the Xml-compile
mailing list