| 1 | package Data::Format::Pretty::JSON; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | our $DATE = '2016-03-11'; # DATE | |||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | our $VERSION = '0.12'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | our @EXPORT_OK = qw(format_pretty); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub content_type { "application/json" } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | sub format_pretty { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_pretty: called CC=11 SCAR=28.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | my ($data, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | $opts //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts //= {}
MC/DC0%0/1
$opts //= {}
$opts
Truth table50%1/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | state $json; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | my $interactive = (-t STDOUT); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | my $pretty = $opts->{pretty} // 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"pretty"} // 1
MC/DC100%1/1
$opts->{"pretty"} // 1
$opts->{"pretty"}
Truth table100%2/2
A
A= $opts->{"pretty"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | my $color = $opts->{color} // $ENV{COLOR} // $interactive // | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | $opts->{pretty}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%3/9
(($opts->{"color"} // $ENV{"COLOR"}) // $interactive) // $opts->{"pretty"}
($opts->{"color"} // $ENV{"COLOR"}) // $interactive
$opts->{"color"} // $ENV{"COLOR"}
MC/DC0%0/4
(($opts->{"color"} // $ENV{"COLOR"}) // $interactive) // $opts->{"pretty"}
$opts->{"color"}
$ENV{"COLOR"}
$interactive
$opts->{"pretty"}
Truth table20%1/5
A // B // C // D
A= $opts->{"color"}B= $ENV{"COLOR"}C= $interactiveD= $opts->{"pretty"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | my $linum = $opts->{linum} // $ENV{LINUM} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
($opts->{"linum"} // $ENV{"LINUM"}) // 0
$opts->{"linum"} // $ENV{"LINUM"}
MC/DC0%0/2
($opts->{"linum"} // $ENV{"LINUM"}) // 0
$opts->{"linum"}
$ENV{"LINUM"}
Truth table33%1/3
A // B
A= $opts->{"linum"}B= $ENV{"LINUM"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | if ($color) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | require JSON::Color; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | JSON::Color::encode_json($data, {pretty=>$pretty, linum=>$linum})."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | if (!$json) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | require JSON::MaybeXS; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | $json = JSON::MaybeXS->new->utf8->allow_nonref; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | $json->pretty($pretty); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | if ($linum) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | require String::LineNumber; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | String::LineNumber::linenum($json->encode($data)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | $json->encode($data); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # ABSTRACT: Pretty-print data structure as JSON | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||