package JSON::Create;
use warnings;
use strict;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw/create_json create_json_strict write_json/;
our %EXPORT_TAGS = (
all => \@EXPORT_OK,
e JSONCreatePP controls whether this runs as
# XS or purely Perl.
$noxs = $ENV{JSONCreatePP};
# Did the XS load OK?
our $xsok;
if (! $noxs) {
eval {
require XSLoader;
XSLoader::load ('JSON::
sok = 1;
};
if ($@) {
$xsok = 0;
}
}
if (! $xsok || $noxs) {
require JSON::Create::PP;
JSON::Create::PP->import (':all');
}
sub set_fformat
{
my ($obj, $fformat) = @_;
i
=head1 NAME
JSON::Create::PP - Pure-Perl version of JSON::Create
=head1 DESCRIPTION
This is a backup module for JSON::Create. JSON::Create is written
using Perl XS, but JSON::Create::PP offers the
to work exactly like
the XS version.
=cut
package JSON::Create::PP;
use parent Exporter;
our @EXPORT_OK = qw/create_json create_json_strict json_escape/;
our %EXPORT_TAGS = (all => \@EXPORT_OK);
us
Unicode::UTF8 qw/decode_utf8 valid_utf8 encode_utf8/;
use B;
our $VERSION = '0.35';
sub create_json
{
my ($input, %options) = @_;
my $jc = bless {
output => '',
};
$jc->{_strict} =
package JSON::Create::Bool;
use warnings;
use strict;
our @ISA = qw!Exporter!;
our @EXPORT = qw!true false!;
our $VERSION = '0.35';
my $t = 1;
my $f = 0;
my $true = bless \$t, __PACKAGE__;
my $fal
ing UTF-8
=head1 NAME
JSON::Create::Bool - Booleans for JSON::Create
=head1 SYNOPSIS
use JSON::Create::Bool;
my %thing = (yes => true, no => false);
print json_create (\%thing);
=hea
This module provides substitute booleans for JSON::Create. These
booleans are intended only to be used for generating C<true> and
C<false> literals in JSON output. They don't work very well for other
/* XS part of JSON::Create. */
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include <stdint.h>
#include "unicode.h"
#include "qsort-r.c"
#include "json-create-perl.c"
\
json_create_status_t jcs; \
jcs = x; \
if (jcs != json_create_ok) { \
warn ("%s:%d: bad status %d from %s", \
__FILE__, __LINE__, jcs, #x); \
} \
}
typedef json_cre
ate_t * JSON__Create;
#define JCSET \
if (items > 1) { \
if ((items - 1) % 2 != 0) { \
warn ("odd number of arguments ignored"); \
} \
else { \
int i; \
#!/usr/bin/env perl
# Benchmark JSON::Create against JSON::XS.
use warnings;
use strict;
use utf8;
use FindBin '$Bin';
use Time::HiRes;
use Text::Table::Tiny 'generate_table';
use Getopt::Long;
my
ib '/home/ben/projects/json-create/blib/lib';
use lib '/home/ben/projects/json-create/blib/arch';
# Contenders
use JSON::Create 'create_json';
use JSON::XS ();
use Cpanel::JSON::XS ();
# Number of
$count = 100;
$times = 20;
}
print "Versions used:\n";
my @modules = qw/Cpanel::JSON::XS JSON::Create JSON::XS/;
my @mvp;
for my $module (@modules) {
my $abbrev = $module;
$abbrev =~ s/
ncoding UTF-8
=head1 NAME
JSON::Create - Create JSON
=head1 SYNOPSIS
use JSON::Create 'create_json';
my %hash = (a => 'b', c => 'd');
print create_json (\%hash);
produces o
is.pl>|https://fastapi.metacpan.org/source/BKB/JSON-Create-0.35/examples/synopsis.pl> in the distribution.)
=head1 VERSION
This document describes JSON::Create version 0.35,
corresponding to L<git
k/json-create/commit/ffe5ce4b3304dac8f668133563a276f831966bbe> at Fri Jul 16 07:42:12 2021 +0900.
=head1 DESCRIPTION
JSON::Create encodes Perl variables into JSON. The basic routine
L</create_json>