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