| 1 | package Data::Printer::Filter::CODE; | ||||||||||||||||||||||||||||
| 2 | 35 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 35 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 35 | ▶ | use Data::Printer::Filter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 35 | ▶ | use Data::Printer::Common; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 35 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 35 | ▶ | use Fcntl; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 35 | filter 'CODE' => \&parse; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 6 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=6 SCAR=21.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 6 | my ($subref, $ddp) = @_; | |||||||||||||||||||||||||||
| 14 | 6 | my $string; | |||||||||||||||||||||||||||
| 15 | 6 | my $color = 'code'; | |||||||||||||||||||||||||||
| 16 | 6 | ▶ | if ($ddp->deparse) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 17 | 2 | $string = _deparse($subref, $ddp); | |||||||||||||||||||||||||||
| 18 | 2 | ▶ | if ($ddp->coderef_undefined && $string =~ /\A\s*sub\s*;\s*\z/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ddp->coderef_undefined and $string =~ /\A\s*sub\s*;\s*\z/
MC/DC0%0/2
$ddp->coderef_undefined and $string =~ /\A\s*sub\s*;\s*\z/
$ddp->coderef_undefined
$string =~ /\A\s*sub\s*;\s*\z/
Truth table33%1/3
A and B
A= $ddp->coderef_undefinedB= $string =~ /\A\s*sub\s*;\s*\z/
| |||||||||||||||||||||||||||||
| 19 | 0 | $string = $ddp->coderef_undefined; | |||||||||||||||||||||||||||
| 20 | 0 | $color = 'undef'; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | ▶ | elsif ($ddp->coderef_undefined && !_subref_is_reachable($subref)) { | |||||||||||||||||||||||||||
|
Condition33%1/3
$ddp->coderef_undefined and not _subref_is_reachable($subref)
MC/DC0%0/2
$ddp->coderef_undefined and not _subref_is_reachable($subref)
$ddp->coderef_undefined
not _subref_is_reachable($subref)
Truth table33%1/3
A and not(B)
A= $ddp->coderef_undefinedB= not _subref_is_reachable($subref)
| |||||||||||||||||||||||||||||
| 24 | 0 | $string = $ddp->coderef_undefined; | |||||||||||||||||||||||||||
| 25 | 0 | $color = 'undef'; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | else { | ||||||||||||||||||||||||||||
| 28 | 4 | $string = $ddp->coderef_stub; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | 6 | return $ddp->maybe_colorize($string, $color); | |||||||||||||||||||||||||||
| 31 | }; | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | ####################################### | ||||||||||||||||||||||||||||
| 34 | ### Private auxiliary helpers below ### | ||||||||||||||||||||||||||||
| 35 | ####################################### | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 2 | ▶ | sub _deparse { | ||||||||||||||||||||||||||
|
Subroutine
_deparse: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 2 | my ($subref, $ddp) = @_; | |||||||||||||||||||||||||||
| 39 | 2 | require B::Deparse; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # FIXME: line below breaks encapsulation on Data::Printer::Object | ||||||||||||||||||||||||||||
| 42 | 2 | my $i = $ddp->{indent} + $ddp->{_array_padding}; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 2 | my $deparseopts = ["-sCi${i}v'Useless const omitted'"]; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 2 | my $sub = 'sub ' . B::Deparse->new($deparseopts)->coderef2text($subref); | |||||||||||||||||||||||||||
| 47 | 2 | my $pad = $ddp->newline; | |||||||||||||||||||||||||||
| 48 | 2 | $sub =~ s/\n/$pad/gse; | |||||||||||||||||||||||||||
| 49 | 2 | return $sub; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 4 | ▶ | sub _subref_is_reachable { | ||||||||||||||||||||||||||
|
Subroutine
_subref_is_reachable: called CC=2 SCAR=7.9
| |||||||||||||||||||||||||||||
| 53 | 4 | my ($subref) = @_; | |||||||||||||||||||||||||||
| 54 | 4 | require B; | |||||||||||||||||||||||||||
| 55 | 4 | my $cv = B::svref_2object($subref); | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | return !(B::class($cv->ROOT) eq 'NULL' && !${ $cv->const_sv }); | ||||||||||||||||||||||||||
|
Condition33%1/3
B::class($cv->ROOT) eq 'NULL' && !${$cv->const_sv;}
MC/DC0%0/2
B::class($cv->ROOT) eq 'NULL' && !${$cv->const_sv;}
B::class($cv->ROOT) eq 'NULL'
!${$cv->const_sv;}
Truth table33%1/3
A && not(B)
A= B::class($cv->ROOT) eq 'NULL'B= !${$cv->const_sv;}
| |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 35 | 1; | |||||||||||||||||||||||||||