line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::Conditional; |
2
|
14
|
|
|
14
|
|
824712
|
use 5.006; use strict; use warnings; our $VERSION = '0.04'; |
|
14
|
|
|
14
|
|
143
|
|
|
14
|
|
|
14
|
|
71
|
|
|
14
|
|
|
|
|
21
|
|
|
14
|
|
|
|
|
371
|
|
|
14
|
|
|
|
|
91
|
|
|
14
|
|
|
|
|
24
|
|
|
14
|
|
|
|
|
601
|
|
3
|
14
|
|
|
14
|
|
7788
|
use JSON; use base 'Struct::Conditional'; |
|
14
|
|
|
14
|
|
146092
|
|
|
14
|
|
|
|
|
72
|
|
|
14
|
|
|
|
|
1765
|
|
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
5753
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $JSON; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
14
|
|
|
14
|
|
57702
|
$JSON = JSON->new->pretty(1)->allow_blessed->convert_blessed; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub encode { |
12
|
1
|
50
|
|
1
|
1
|
3
|
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
|
84
|
if ( $_[1] !~ m/\n/ && -f $_[1]) { |
27
|
0
|
|
|
|
|
0
|
$_[0]->decode_file($_[1]); |
28
|
|
|
|
|
|
|
} |
29
|
15
|
|
|
|
|
292
|
$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
|
10369
|
my ($self, $json, $params, $return_struct, $out_file) = @_; |
41
|
15
|
50
|
|
|
|
84
|
$json = $self->decode($json) |
42
|
|
|
|
|
|
|
unless ref $json; |
43
|
15
|
50
|
|
|
|
58
|
$params = $self->decode($params) unless ref $params; |
44
|
15
|
|
|
|
|
80
|
$json = $self->SUPER::compile($json, $params); |
45
|
15
|
100
|
|
|
|
8491
|
return $return_struct |
46
|
|
|
|
|
|
|
? $json |
47
|
|
|
|
|
|
|
: $self->encode($json, $out_file); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
__END__ |