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