blib/lib/Data/Format/Pretty/Perl.pm

filter: Statementstmt 69.7% 30 / 43 Branchbran 25.0% 2 / 8 Conditioncond 38.4% 5 / 13 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 85.7% 6 / 7 Podpod 100% 2 / 2 totaltotal 56.9% 45 / 79 CC 10 SCAR 30.2
CC
10
Cov
58%
format_pretty
32.1
content_type
2.0
BEGIN
1.0
CRAP 20.5
↑ Summary
1 package Data::Format::Pretty::Perl;
2  
3 2 our $DATE = '2018-01-14'; # DATE
4 2 our $VERSION = '0.060'; # 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 ▶use Data::Dump qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Data::Dump::Color qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 require Exporter;
14 2 our @ISA = qw(Exporter);
15 2 our @EXPORT_OK = qw(format_pretty);
16  
17 0 ▶sub content_type { "text/x-perl" }
Subroutine content_type: not called CC=1 SCAR=6.9
Pod documented
18  
19 1 ▶sub format_pretty {
Subroutine format_pretty: called CC=10 SCAR=34.7
Pod documented
20 1 my ($data, $opts) = @_;
21 1 ▶ $opts //= {};
Condition50%1/2
$opts //= {}
l!l
10
MC/DC0%0/1
$opts //= {}
$opts
Truth table50%1/2
A
A= $opts
Aresult
11
00
22  
23 1 my $interactive = (-t STDOUT);
24 1 ▶ my $color = $opts->{color} // $ENV{COLOR} // $interactive;
Condition33%2/6
($opts->{"color"} // $ENV{"COLOR"}) // $interactive
l!l&&r!l&&!r
010
$opts->{"color"} // $ENV{"COLOR"}
l!l&&r!l&&!r
001
MC/DC0%0/3
($opts->{"color"} // $ENV{"COLOR"}) // $interactive
$opts->{"color"} $ENV{"COLOR"} $interactive
Truth table25%1/4
A // B // C
A= $opts->{"color"}B= $ENV{"COLOR"}C= $interactive
ABCresult
1XX1
01X1
0011
0000
25 1 ▶ my $linum = $opts->{linum} // $ENV{LINUM} // 0;
Condition40%2/5
($opts->{"linum"} // $ENV{"LINUM"}) // 0
l!l
01
$opts->{"linum"} // $ENV{"LINUM"}
l!l&&r!l&&!r
001
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  
27 1 my $dump;
28 1 ▶ if ($color) {
Branch: 1 branch
BranchTrueFalseTotal
if ($color) { } 0 1 1
29 0 $dump = Data::Dump::Color::dump($data) . "\n";
30 } else {
31 1 $dump = Data::Dump::dump($data) . "\n";
32 }
33 1 ▶ if ($linum) {
Branch: 1 branch
BranchTrueFalseTotal
if ($linum) 0 1 1
34 0 my $lines = 0;
35 0 ▶ $lines++ while $dump =~ /^/mog;
Branch: 1 branch
BranchTrueFalseTotal
$dump =~ /^/gmo and do { ++$lines } 0 0 0
36 0 my $fmt;
37 0 my $i = 0;
38 0 ▶ if ($color) {
Branch: 1 branch
BranchTrueFalseTotal
if ($color) { } 0 0 0
39 0 $fmt = "%".length($lines)."d";
40 0 $dump =~ s/^/
41 0 "\e[7m" . sprintf($fmt, ++$i) . "\e[0m"
42 /egm;
43 } else {
44 0 $fmt = "%".length($lines)."d|";
45 0 $dump =~ s/^/
46 0 sprintf($fmt, ++$i)
47 /egm;
48 }
49 }
50 1 $dump;
51 }
52  
53 2 1;
54 # ABSTRACT: Pretty-print data structure as Perl code
55  
56 __END__
↑ Summary