CompactJSON.pm

filter: Statementstmt 54.1% 13 / 24 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 60.0% 3 / 5 Podpod 100% 2 / 2 totaltotal 38.3% 18 / 47 CC 6 SCAR 32.5
CC
6
Cov
36%
format_pretty
42.0
content_type
2.0
BEGIN
1.0
CRAP 25.7
↑ Summary JSON.pm »
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 //= {}
l!l
00
MC/DC0%0/1
$opts //= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
20  
21 0 ▶ if ($opts->{color} // $ENV{COLOR} // (-t STDOUT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (($opts->{'color'} // $ENV{'COLOR'}) // -t STDOUT) { } 0 0 0
Condition0%0/6
($opts->{"color"} // $ENV{"COLOR"}) // -t STDOUT
l!l&&r!l&&!r
000
$opts->{"color"} // $ENV{"COLOR"}
l!l&&r!l&&!r
000
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
ABCresult
1XX1
01X1
0011
0000
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
BranchTrueFalseTotal
unless ($json) 0 0 0
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__
↑ Summary JSON.pm »