line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Harness::Util::JSON; |
2
|
3
|
|
|
3
|
|
142945
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
69
|
|
3
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
262
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.001007'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
3
|
|
|
3
|
|
10
|
local $@ = undef; |
9
|
3
|
|
|
|
|
6
|
my $ok = eval { |
10
|
3
|
|
|
|
|
707
|
require JSON::MaybeXS; |
11
|
3
|
|
|
|
|
11761
|
JSON::MaybeXS->import('JSON'); |
12
|
3
|
|
|
|
|
8
|
1; |
13
|
|
|
|
|
|
|
}; |
14
|
|
|
|
|
|
|
|
15
|
3
|
50
|
|
|
|
136
|
unless($ok) { |
16
|
0
|
|
|
|
|
0
|
require JSON::PP; |
17
|
0
|
|
|
|
|
0
|
*JSON = sub() { 'JSON::PP' }; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @EXPORT = qw{JSON encode_json decode_json encode_pretty_json encode_canon_json}; |
22
|
3
|
|
|
3
|
|
17
|
BEGIN { require Exporter; our @ISA = qw(Exporter) } |
|
3
|
|
|
|
|
503
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $json = JSON->new->utf8(1)->convert_blessed(1)->allow_nonref(1); |
25
|
|
|
|
|
|
|
my $canon = JSON->new->utf8(1)->canonical(1)->convert_blessed(1)->allow_nonref(1); |
26
|
|
|
|
|
|
|
my $pretty = JSON->new->utf8(1)->pretty(1)->canonical(1)->convert_blessed(1)->allow_nonref(1); |
27
|
|
|
|
|
|
|
|
28
|
4
|
|
|
4
|
0
|
1198
|
sub encode_json { $json->encode(@_) } |
29
|
2
|
|
|
2
|
0
|
301
|
sub encode_canon_json { $canon->encode(@_) } |
30
|
2
|
|
|
2
|
0
|
320
|
sub encode_pretty_json { $pretty->encode(@_) } |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub decode_json { |
33
|
8
|
|
|
8
|
0
|
18
|
my ($input) = @_; |
34
|
8
|
|
|
|
|
14
|
my $data; |
35
|
8
|
|
|
|
|
13
|
my $ok = eval { $data = $json->decode($input); 1 }; |
|
8
|
|
|
|
|
27
|
|
|
8
|
|
|
|
|
16
|
|
36
|
8
|
|
|
|
|
12
|
my $error = $@; |
37
|
8
|
50
|
|
|
|
66
|
return $data if $ok; |
38
|
0
|
|
|
|
|
|
die "JSON decode error: $error$input\n"; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |