1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use JSON ();
use JSON::PP ();
use JSON::XS ();
use Cpanel::JSON::XS ();
require Mojolicious;
use Mojo::JSON ();
use B ();
use Text::Table;
my @classes = qw/ JSON JSON::PP JSON::XS Cpanel::JSON::XS Mojo::JSON /;
my $t = Text::Table->new(
qw/
Class
Version
3 IV NV PV
3.140 IV NV PV
3.00 IV NV PV
0.3e3 IV NV PV
encode
/,
);
my $json = <<'EOM';
[ 3, 3.140, 3.00, 0.3e3 ]
EOM
my @rows;
for my $class (@classes) {
my $version = $class eq 'Mojo::JSON' ? Mojolicious->VERSION : $class->VERSION;
my @row = ( $class, $version );
my $decode = $class->can("decode_json");
my $encode = $class->can("encode_json");
my $data = $decode->($json);
for my $num (@$data) {
my $flags = B::svref_2object(\$num)->FLAGS;
my $int = $flags & B::SVp_IOK ? 1 : 0;
my $float = $flags & B::SVp_NOK ? 1 : 0;
my $str = $flags & B::SVp_POK ? 1 : 0;
push @row, '', $int, $float, $str;
}
my $enc = $encode->($data);
push @row, $enc;
push @rows, \@row;
}
say "Input: $json";
$t->load(@rows);
say $t;
|