| 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 //= {}
MC/DC0%0/1
$opts //= {}
$opts
Truth table50%1/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | 1 | my $interactive = (-t STDOUT); | |||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | my $color = $opts->{color} // $ENV{COLOR} // $interactive; | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
($opts->{"color"} // $ENV{"COLOR"}) // $interactive
$opts->{"color"} // $ENV{"COLOR"}
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
| |||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | 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 | |||||||||||||||||||||||||||||||||||
| 27 | 1 | my $dump; | |||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | if ($color) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 34 | 0 | my $lines = 0; | |||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | $lines++ while $dump =~ /^/mog; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 36 | 0 | my $fmt; | |||||||||||||||||||||||||||||||||
| 37 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ($color) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||