line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
26002
|
use strictures 1; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
38
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# lots of this stuff was sponsored by socialflow.com |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package JSON::Diffable; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
878
|
use JSON::MaybeXS (); |
|
1
|
|
|
|
|
11060
|
|
|
1
|
|
|
|
|
33
|
|
8
|
1
|
|
|
1
|
|
11
|
use Exporter 'import'; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
383
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.000002'; # 0.0.2 |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $real = JSON::MaybeXS->new->relaxed->allow_nonref->utf8; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw( encode_json decode_json ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub encode_json { |
19
|
1
|
|
|
1
|
1
|
25
|
my $data = shift; |
20
|
1
|
|
|
|
|
7
|
return _encode($data, 0); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub decode_json { |
24
|
1
|
|
|
1
|
1
|
624
|
my $str = shift; |
25
|
1
|
|
|
|
|
26
|
return $real->decode($str); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _indent { |
29
|
15
|
|
|
15
|
|
16
|
my $str = shift; |
30
|
15
|
|
|
|
|
76
|
$str =~ s{^}{ }gm; |
31
|
15
|
|
|
|
|
73
|
return $str; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _encode { |
35
|
16
|
|
|
16
|
|
19
|
my $data = shift; |
36
|
16
|
100
|
|
|
|
42
|
if (ref $data eq 'HASH') { |
|
|
100
|
|
|
|
|
|
37
|
9
|
|
|
|
|
33
|
return sprintf "{\n%s}", |
38
|
|
|
|
|
|
|
join '', |
39
|
|
|
|
|
|
|
map { |
40
|
4
|
|
|
|
|
22
|
my $key = $real->encode($_); |
41
|
9
|
|
|
|
|
31
|
my $data = _encode($data->{$_}); |
42
|
9
|
|
|
|
|
23
|
_indent("$key: $data") . ",\n"; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
sort keys %$data; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif (ref $data eq 'ARRAY') { |
47
|
6
|
|
|
|
|
12
|
return sprintf "[\n%s]", |
48
|
|
|
|
|
|
|
join '', |
49
|
|
|
|
|
|
|
map { |
50
|
3
|
|
|
|
|
7
|
_indent(_encode($_)) . ",\n"; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
@$data; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
9
|
|
|
|
|
30
|
return $real->encode($data); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |