e JSON5;
use 5.008001;
use strict;
use warnings;
our $VERSION = "0.01";
use Exporter 'import';
our @EXPORT = qw/decode_json5/;
use JSON::PP;
use JSON5::Parser;
my $JSON5; # cache
sub decode_json5
{ ($JSON5 ||= JSON5->new->utf8)->decode(@_) }
sub new {
my $class = shift;
return bless {
parser => JSON5::Parser->new,
} => $class;
}
sub true;
sub false;
*true = \&JSON::PP::
true;
*false = \&JSON::PP::false;
# define accessors
BEGIN {
for my $attr (qw/utf8 allow_nonref max_size inflate_boolean inflate_nan inflate_null inflate_infinity/) {
my $attr_accessor =
package JSON5::Parser;
use strict;
use warnings;
use utf8;
use Carp qw/croak/;
use JSON::PP;
use Encode;
our $ROOT;
our $POINTER;
sub new {
my $class = shift;
return bless +{
utf8
=> 0,
max_size => 0,
inflate_boolean => sub { $_[0] eq 'true' ? JSON::PP::true : JSON::PP::false },
inflate_nan => sub { 0+'NaN' },
inflate_null => s
= length $content;
$bytes <= $max_size
or croak sprintf 'attempted decode of JSON5 text of %s bytes size, but max_size is set to %s', $bytes, $max_size;
}
if ($self->{utf8