line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::Conditional; |
2
|
14
|
|
|
14
|
|
1014634
|
use 5.006; use strict; use warnings; our $VERSION = '0.05'; |
|
14
|
|
|
14
|
|
175
|
|
|
14
|
|
|
14
|
|
79
|
|
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
485
|
|
|
14
|
|
|
|
|
100
|
|
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
725
|
|
3
|
14
|
|
|
14
|
|
10080
|
use JSON; use base 'Struct::Conditional'; |
|
14
|
|
|
14
|
|
185370
|
|
|
14
|
|
|
|
|
86
|
|
|
14
|
|
|
|
|
2274
|
|
|
14
|
|
|
|
|
30
|
|
|
14
|
|
|
|
|
7843
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $JSON; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
14
|
|
|
14
|
|
71868
|
$JSON = JSON->new->pretty(1)->allow_blessed->convert_blessed; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub encode { |
12
|
1
|
50
|
|
1
|
1
|
4
|
if ($_[2]) { |
13
|
0
|
|
|
|
|
0
|
$_[0]->encode_file($_[1], $_[2]); |
14
|
|
|
|
|
|
|
} |
15
|
1
|
|
|
|
|
13
|
$JSON->encode($_[1]); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub encode_file { |
19
|
0
|
0
|
|
0
|
1
|
0
|
open my $file, '>', $_[2] or die "cannot open file $!"; |
20
|
0
|
|
|
|
|
0
|
print $file $_[0]->encode($_[1]); |
21
|
0
|
|
|
|
|
0
|
close $file; |
22
|
0
|
|
|
|
|
0
|
return $file; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub decode { |
26
|
15
|
50
|
33
|
15
|
1
|
99
|
if ( $_[1] !~ m/\n/ && -f $_[1]) { |
27
|
0
|
|
|
|
|
0
|
$_[0]->decode_file($_[1]); |
28
|
|
|
|
|
|
|
} |
29
|
15
|
|
|
|
|
424
|
$JSON->decode($_[1]); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub decode_file { |
33
|
0
|
0
|
|
0
|
1
|
0
|
open my $file, '<', $_[1] or die "cannot open file $!"; |
34
|
0
|
|
|
|
|
0
|
my $content = do { local $/; <$file> }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
35
|
0
|
|
|
|
|
0
|
close $file; |
36
|
0
|
|
|
|
|
0
|
return $_[0]->decode($content); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub compile { |
40
|
15
|
|
|
15
|
1
|
3531
|
my ($self, $json, $params, $return_struct, $out_file) = @_; |
41
|
15
|
50
|
|
|
|
109
|
$json = $self->decode($json) |
42
|
|
|
|
|
|
|
unless ref $json; |
43
|
15
|
50
|
|
|
|
74
|
$params = $self->decode($params) unless ref $params; |
44
|
15
|
|
|
|
|
103
|
$json = $self->SUPER::compile($json, $params); |
45
|
15
|
100
|
|
|
|
10196
|
return $return_struct |
46
|
|
|
|
|
|
|
? $json |
47
|
|
|
|
|
|
|
: $self->encode($json, $out_file); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
__END__ |