package Perlito5::JSON;
sub ast_dumper {
my $seen = {};
my $level = '';
my $pos = '[TODO - recursive structure is not supported]';
return _dumper( $_[0], $level, $seen, $pos );
}
age JSON;
use Perlito5::JSON;
# use strict;
sub import {
my $pkg = shift;
my $callpkg = caller(0);
*{ $callpkg . "::encode_json" } = \&encode_json;
*{ $callpkg . "::decode_json" }
= \&decode_json;
return;
}
sub encode_json {
Perlito5::JSON::ast_dumper($_[0]);
}
sub _string_loop {
my $s = "";
while (1) {
if ($_[0] =~ /\G"[ \t\r\n]*/gc) {
#
$_[0] =~ /\G([0-9a-fA-F]{4})/gc
or die "unexpected end of string while parsing JSON string, at character offset " . pos($_[0]);
my $uni = hex($1);
if
package JSON::PP;
# JSON-2.0
use 5.005;
use strict;
use Exporter ();
BEGIN { @JSON::PP::ISA = ('Exporter') }
use overload ();
use JSON::PP::Boolean;
use Carp ();
#use Devel::Peek;
$JSON::PP::VER
SION = '2.97001';
@JSON::PP::EXPORT = qw(encode_json decode_json from_json to_json);
# instead of hash-access, i tried index-access for speed.
# but this method is not faster than what i expected. s
ndling is enabled?
# Helper module sets @JSON::PP::_properties.
if ( OLD_PERL ) {
my $helper = $] >= 5.006 ? 'JSON::PP::Compat5006' : 'JSON::PP::Compat5005';
eval qq| require $
package JSON;
use strict;
package Java::Json { import => "javax.json.Json" }
package Java::JsonParser { import => "javax.json.stream.JsonParser" }
package Java::JsonParser::Event { import => "j
m.JsonParser.Event" }
package String {};
package StringReader { import => "java.io.StringReader" }
sub parse {
my $str = shift;
my $result;
my Java::JsonParser $parser = Java::Json-
arser->hasNext()) {
my Java::JsonParser::Event $event = $parser->next();
my $ev = $event;
say "event $ev";
#if ($event == Java::JsonParser::START_ARRAY) {
#
package JSON::MaybeXS;
use strict;
use warnings FATAL => 'all';
use base qw(Exporter);
our $VERSION = '1.003009';
$VERSION = eval $VERSION;
sub _choose_json_module {
return 'Cpanel::JSON::XS' i
l/JSON/XS.pm'};
return 'JSON::XS' if $INC{'JSON/XS.pm'};
my @err;
return 'Cpanel::JSON::XS' if eval { require Cpanel::JSON::XS; 1; };
push @err, "Error loading Cpanel::JSON::
return 'JSON::XS' if eval { require JSON::XS; 1; };
push @err, "Error loading JSON::XS: $@";
return 'JSON::PP' if eval { require JSON::PP; 1 };
push @err, "Error loading JSON::PP: $@";
package JSON::PP::Boolean;
use strict;
use overload (
"0+" => sub { ${$_[0]} },
"++" => sub { $_[0] = ${$_[0]} + 1 },
"--" => sub { $_[0] = ${$_[0]} - 1 },
fallback => 1,
);
$JSON::PP::Boolean::VERSION = '2.97001';
1;
__END__
=head1 NAME
JSON::PP::Boolean - dummy module providing JSON::PP::Boolean
=head1 SYNOPSIS
# do not "use" yourself
=head1 DESCRIPTION
Thi
verload resolution for Storable and similar modules. See
L<JSON::PP> for more info about this class.
=head1 AUTHOR
This idea is from L<JSON::XS::Boolean> written by Marc Lehmann <schmorp[at]schmorp.
m_json {
my $class = shift;
my %p = @_;
my $event_pkg = delete $p{__PACKAGE__};
require(pkg_to_file($event_pkg));
if (exists $p{trace}) {
$p{trace} = Test2::Util::Trace->from_json(%
|| []}) {
push @subevents, Test2::Event->from_json(%$subevent);
}
$p{subevents} = \@subevents;
}
return $event_pkg->new(%p);
}
sub TO_JSON {
my $self = shift;
return {%$self, __P
->TO_JSON
This returns a hashref suitable for passing to the C<< Test2::Event->from_json
>> constructor. It is intended for use with the L<JSON> family of modules,
which will look for a C<TO_JSON> me
}
sub from_json {
my $class = shift;
my %p = @_;
my $trace_pkg = delete $p{__PACKAGE__};
require(pkg_to_file($trace_pkg));
return $trace_pkg->new(%p);
}
sub TO_JSON {
my $se
O_JSON
This returns a hashref suitable for passing to the C<<
Test2::Util::Trace->from_json >> constructor. It is intended for use with the
L<JSON> family of modules, which will look for a C<TO_JSON>
n
C<convert_blessed> is true.
=item $t = Test2::Util::Trace->from_json(%$hashref)
Given the hash of data returned by C<< $t->TO_JSON >>, this method returns a
new trace object of the appropriate sub