| 1 | package Data::Format::Pretty::CompactJSON; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our @EXPORT_OK = qw(format_pretty); | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | our $VERSION = '0.12'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub content_type { "application/json" } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub format_pretty { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_pretty: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | my ($data, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | state $json; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | $opts //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts //= {}
MC/DC0%0/1
$opts //= {}
$opts
Truth table0%0/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | if ($opts->{color} // $ENV{COLOR} // (-t STDOUT)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
($opts->{"color"} // $ENV{"COLOR"}) // -t STDOUT
$opts->{"color"} // $ENV{"COLOR"}
MC/DC0%0/3
($opts->{"color"} // $ENV{"COLOR"}) // -t STDOUT
$opts->{"color"}
$ENV{"COLOR"}
-t STDOUT
Truth table0%0/4
A // B // C
A= $opts->{"color"}B= $ENV{"COLOR"}C= -t STDOUT
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | require JSON::Color; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | JSON::Color::encode_json($data, {pretty=>0, linum=>0}); | |||||||||||||||||||||||||||||||||||||||||
| 24 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if (!$json) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | require JSON::MaybeXS; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | $json = JSON::MaybeXS->new->utf8->allow_nonref; | |||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | $json->encode($data); | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 34 | # ABSTRACT: Pretty-print data structure as compact JSON | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | __END__ | ||||||||||||||||||||||||||||||||||||||||||