4 # hide Cpanel::JSON::XS
7 sub { return unless $_[1] eq $m; die "Can't locate $m in \@INC (hidden).\n" };
8 } qw{Cpanel/JSON/XS.pm};
11 use JSON::MaybeXS qw/:legacy/;
13 my $in = '[1, 2, 3, 4]';
15 my $arr = from_json($in);
16 my $j = to_json($arr);
18 is(ref($arr), 'ARRAY');
20 my $json = 'JSON::MaybeXS';
21 diag "using invocant: $json";
23 do { eval { $json->from_json($in) }; $@ },
24 qr/from_json should not be called as a method/,
25 'blessed invocant detected in from_json',
29 do { eval { $json->to_json($arr, { blah => 1 } ) }; $@ },
30 qr/to_json should not be called as a method/,
31 'blessed invocant detected in to_json',
39 $json_text = to_json($perl_scalar)
41 Converts the given Perl data structure to a json string.
43 This function call is functionally identical to:
45 $json_text = JSON()->new->encode($perl_scalar)
48 $perl_scalar = from_json($json_text)
50 The opposite of "to_json": expects a json string and tries to parse it,
51 returning the resulting reference.
53 This function call is functionally identical to:
55 $perl_scalar = JSON()->decode($json_text)