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