JSON.pm

filter: Statementstmt 84.8% 28 / 33 Branchbran 66.6% 4 / 6 Conditioncond 44.4% 8 / 18 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 80.0% 4 / 5 Podpod 100% 2 / 2 totaltotal 65.2% 47 / 72 CC 11 SCAR 25.9
CC
11
Cov
70%
format_pretty
17.7
content_type
2.0
BEGIN
1.0
CRAP 13.3
« CompactJSON.pm ↑ Summary
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 //= {}
l!l
20
MC/DC0%0/1
$opts //= {}
$opts
Truth table50%1/2
A
A= $opts
Aresult
11
00
19  
20 2 state $json;
21 2 my $interactive = (-t STDOUT);
22 2 ▶ my $pretty = $opts->{pretty} // 1;
Condition100%2/2
$opts->{"pretty"} // 1
l!l
11
MC/DC100%1/1
$opts->{"pretty"} // 1
$opts->{"pretty"}
Truth table100%2/2
A
A= $opts->{"pretty"}
Aresult
11
00
23 my $color = $opts->{color} // $ENV{COLOR} // $interactive //
24 2 ▶ $opts->{pretty};
Condition33%3/9
(($opts->{"color"} // $ENV{"COLOR"}) // $interactive) // $opts->{"pretty"}
l!l&&r!l&&!r
200
($opts->{"color"} // $ENV{"COLOR"}) // $interactive
l!l&&r!l&&!r
020
$opts->{"color"} // $ENV{"COLOR"}
l!l&&r!l&&!r
002
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"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
25 2 ▶ my $linum = $opts->{linum} // $ENV{LINUM} // 0;
Condition40%2/5
($opts->{"linum"} // $ENV{"LINUM"}) // 0
l!l
02
$opts->{"linum"} // $ENV{"LINUM"}
l!l&&r!l&&!r
002
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"}
ABresult
1X1
011
000
26 2 ▶ if ($color) {
Branch: 1 branch
BranchTrueFalseTotal
if ($color) { } 0 2 2
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
BranchTrueFalseTotal
unless ($json) 1 1 2
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
BranchTrueFalseTotal
if ($linum) { } 0 2 2
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__
« CompactJSON.pm ↑ Summary