line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Format::Pretty::JSON; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
622
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
319
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(format_pretty); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.10'; # VERSION |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
0
|
1
|
0
|
sub content_type { "application/json" } |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub format_pretty { |
16
|
2
|
|
|
2
|
1
|
2658
|
my ($data, $opts) = @_; |
17
|
2
|
|
50
|
|
|
8
|
$opts //= {}; |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
|
|
4
|
state $json; |
20
|
2
|
|
|
|
|
26
|
my $interactive = (-t STDOUT); |
21
|
2
|
|
100
|
|
|
12
|
my $pretty = $opts->{pretty} // 1; |
22
|
2
|
|
33
|
|
|
26
|
my $color = $opts->{color} // $ENV{COLOR} // $interactive // |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
23
|
|
|
|
|
|
|
$opts->{pretty}; |
24
|
2
|
|
33
|
|
|
19
|
my $linum = $opts->{linum} // $ENV{LINUM} // 0; |
|
|
|
50
|
|
|
|
|
25
|
2
|
50
|
|
|
|
6
|
if ($color) { |
26
|
0
|
|
|
|
|
0
|
require JSON::Color; |
27
|
0
|
|
|
|
|
0
|
JSON::Color::encode_json($data, {pretty=>$pretty, linum=>$linum})."\n"; |
28
|
|
|
|
|
|
|
} else { |
29
|
2
|
100
|
|
|
|
26
|
if (!$json) { |
30
|
1
|
|
|
|
|
17
|
require JSON; |
31
|
1
|
|
|
|
|
25
|
$json = JSON->new->utf8->allow_nonref; |
32
|
|
|
|
|
|
|
} |
33
|
2
|
|
|
|
|
10
|
$json->pretty($pretty); |
34
|
2
|
50
|
|
|
|
29
|
if ($linum) { |
35
|
0
|
|
|
|
|
0
|
require SHARYANTO::String::Util; |
36
|
0
|
|
|
|
|
0
|
SHARYANTO::String::Util::linenum($json->encode($data)); |
37
|
|
|
|
|
|
|
} else { |
38
|
2
|
|
|
|
|
32
|
$json->encode($data); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
# ABSTRACT: Pretty-print data structure as JSON |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |