clean up module hiding in tests
[p5sagit/JSON-MaybeXS.git] / t / legacy.t
CommitLineData
ebf1e433 1use strict;
4e1fb2f8 2use warnings;
ebf1e433 3
b4d74169 4# hide Cpanel::JSON::XS
5use lib map {
7c484eb9 6 my $m = $_;
7 sub { return unless $_[1] eq $m; die "Can't locate $m in \@INC (hidden).\n" };
b4d74169 8} qw{Cpanel/JSON/XS.pm};
9
2c67ae64 10use Test::More 0.88;
ebf1e433 11use JSON::MaybeXS qw/:legacy/;
12
ebf1e433 13my $in = '[1, 2, 3, 4]';
14
ebf1e433 15my $arr = from_json($in);
16my $j = to_json($arr);
17is($j, '[1,2,3,4]');
18is(ref($arr), 'ARRAY');
19
c397f194 20my $json = 'JSON::MaybeXS';
21diag "using invocant: $json";
22like(
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',
26);
27
28like(
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',
32);
33
ebf1e433 34done_testing;
35
36__END__
37
38 to_json
39 $json_text = to_json($perl_scalar)
40
41 Converts the given Perl data structure to a json string.
42
43 This function call is functionally identical to:
44
20f884e2 45 $json_text = JSON()->new->encode($perl_scalar)
ebf1e433 46
47 from_json
48 $perl_scalar = from_json($json_text)
49
50 The opposite of "to_json": expects a json string and tries to parse it,
51 returning the resulting reference.
52
53 This function call is functionally identical to:
54
20f884e2 55 $perl_scalar = JSON()->decode($json_text)