line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::Conditional; |
2
|
14
|
|
|
14
|
|
812964
|
use 5.006; use strict; use warnings; our $VERSION = '1.00'; |
|
14
|
|
|
14
|
|
151
|
|
|
14
|
|
|
14
|
|
67
|
|
|
14
|
|
|
|
|
20
|
|
|
14
|
|
|
|
|
369
|
|
|
14
|
|
|
|
|
78
|
|
|
14
|
|
|
|
|
23
|
|
|
14
|
|
|
|
|
625
|
|
3
|
14
|
|
|
14
|
|
7930
|
use JSON; use base 'Struct::Conditional'; |
|
14
|
|
|
14
|
|
149947
|
|
|
14
|
|
|
|
|
80
|
|
|
14
|
|
|
|
|
1954
|
|
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
6273
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $JSON; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
14
|
|
|
14
|
|
57866
|
$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
|
|
|
|
|
12
|
$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
|
82
|
if ( $_[1] !~ m/\n/ && -f $_[1]) { |
27
|
0
|
|
|
|
|
0
|
$_[0]->decode_file($_[1]); |
28
|
|
|
|
|
|
|
} |
29
|
15
|
|
|
|
|
287
|
$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
|
2794
|
my ($self, $json, $params, $return_struct, $out_file) = @_; |
41
|
15
|
50
|
|
|
|
87
|
$json = $self->decode($json) |
42
|
|
|
|
|
|
|
unless ref $json; |
43
|
15
|
50
|
|
|
|
65
|
$params = $self->decode($params) unless ref $params; |
44
|
15
|
|
|
|
|
97
|
$json = $self->SUPER::compile($json, $params); |
45
|
15
|
100
|
|
|
|
8361
|
return $return_struct |
46
|
|
|
|
|
|
|
? $json |
47
|
|
|
|
|
|
|
: $self->encode($json, $out_file); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
__END__ |