| 1 | package Perl::CodeMap; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use 5.020; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use Cwd qw(abs_path); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use File::Basename qw(basename dirname); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use File::Find (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use JSON::PP (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 12 | ▶ | use Encode qw(decode FB_DEFAULT); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 12 | ▶ | use IPC::Open3 (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 12 | ▶ | use Symbol qw(gensym); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 12 | our $VERSION = '0.3.2'; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 10 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=16 SCAR=29.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 10 | my ($class, %arg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | 10 | ▶ | my $root = abs_path($arg{root} // '.'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"root"} // "."
MC/DC0%0/1
$arg{"root"} // "."
$arg{"root"}
Truth table50%1/2
A
A= $arg{"root"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 10 | ▶ | die "Source directory does not exist\n" unless defined $root && -d $root; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $root and -d $root
MC/DC0%0/2
defined $root and -d $root
defined $root
-d $root
Truth table33%1/3
A and B
A= defined $rootB= -d $root
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 10 | ▶ | my $mode = $arg{parser} // 'auto'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"parser"} // "auto"
MC/DC0%0/1
$arg{"parser"} // "auto"
$arg{"parser"}
Truth table50%1/2
A
A= $arg{"parser"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 10 | ▶ | die "parser must be one of auto, ppi, lite\n" unless $mode =~ /\A(?:auto|ppi|lite)\z/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 9 | ▶ | my $ppi = eval { require PPI; 1 } ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 9 | ▶ | die "PPI is not installed. Install it using 'cpanm PPI', or use --parser lite\n" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$mode eq "ppi" and not $ppi
MC/DC0%0/2
$mode eq "ppi" and not $ppi
$mode eq "ppi"
not $ppi
Truth table66%2/3
A and not(B)
A= $mode eq "ppi"B= not $ppi
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | if $mode eq 'ppi' && !$ppi; | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 9 | ▶ | my $selected = $mode eq 'auto' ? ($ppi ? 'ppi' : 'lite') : $mode; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 9 | ▶ | my $max_bytes = $arg{max_source_bytes} // 2_000_000; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"max_source_bytes"} // 2000000
MC/DC0%0/1
$arg{"max_source_bytes"} // 2000000
$arg{"max_source_bytes"}
Truth table50%1/2
A
A= $arg{"max_source_bytes"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 9 | ▶ | die "max_source_bytes must be a positive integer\n" unless $max_bytes =~ /\A[1-9][0-9]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | return bless { | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | root => $root, parser => $selected, | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | include_tests => $arg{include_tests} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | embed_source => exists $arg{embed_source} ? ($arg{embed_source} ? 1 : 0) : 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | max_source_bytes => $max_bytes, | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | source_base => $arg{source_base}, name => $arg{name}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 9 | ▶ | warnings => [], | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | ▶ | sub analyze { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
analyze: called CC=30 SCAR=38.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 5 | my $root = $self->{root}; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 5 | my %ignored = map { $_ => 1 } qw(.git .svn .hg .idea .vscode node_modules vendor blib local _build cover_db .cache); | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 5 | ▶ | if (!$self->{include_tests}) { $ignored{$_} = 1 for qw(t xt tests test); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 5 | my @candidates; | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 73 | ▶ | File::Find::find({ no_chdir => 1, follow => 0, wanted => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=11 SCAR=25.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 73 | my $path = $File::Find::name; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | 73 | ▶ | if (-d $path) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 27 | my $base = basename($path); | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 27 | ▶ | $File::Find::prune = 1 if $path ne $root && ($ignored{$base} || $base =~ /^\./); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$path ne $root and $ignored{$base} || $base =~ /^\./u
$ignored{$base} or $base =~ /^\./u
MC/DC66%2/3
$path ne $root and $ignored{$base} || $base =~ /^\./u
$path ne $root
$ignored{$base}
$base =~ /^\./u
Truth table75%3/4
A and B or C
A= $path ne $rootB= $ignored{$base}C= $base =~ /^\./u
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 27 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 46 | ▶ | return unless -f $path && !-l $path; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-f $path and not -l $path
MC/DC0%0/2
-f $path and not -l $path
-f $path
not -l $path
Truth table33%1/3
A and not(B)
A= -f $pathB= not -l $path
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 46 | ▶ | return unless $self->{include_tests} || $path !~ /\.t\z/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"include_tests"} or not $path =~ /\.t\z/u
MC/DC0%0/2
$self->{"include_tests"} or not $path =~ /\.t\z/u
$self->{"include_tests"}
not $path =~ /\.t\z/u
Truth table66%2/3
A or not(B)
A= $self->{"include_tests"}B= not $path =~ /\.t\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 46 | ▶ | return unless $path =~ /\.(?:pm|pl|psgi|t)\z/i || basename($path) !~ /\./; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$path =~ /\.(?:pm|pl|psgi|t)\z/iu or not basename($path) =~ /\./u
MC/DC0%0/2
$path =~ /\.(?:pm|pl|psgi|t)\z/iu or not basename($path) =~ /\./u
$path =~ /\.(?:pm|pl|psgi|t)\z/iu
not basename($path) =~ /\./u
Truth table33%1/3
A or not(B)
A= $path =~ /\.(?:pm|pl|psgi|t)\z/iuB= not basename($path) =~ /\./u
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 46 | push @candidates, $path; | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 5 | } }, $root); | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 5 | @candidates = sort @candidates; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 5 | my (%packages, %sources, $file_count); | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | 5 | $file_count = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | 5 | for my $path (@candidates) { | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 46 | ▶ | open my $fh, '<:raw', $path or do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | push @{$self->{warnings}}, 'Unable to read ' . File::Spec->abs2rel($path, $root); | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 46 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | 46 | my $raw = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 46 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 46 | my $rel = File::Spec->abs2rel($path, $root); | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 46 | $rel =~ s{\\}{/}g; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | 46 | ▶ | next if $rel !~ /\.(?:pm|pl|psgi|t)\z/i && $raw !~ /\A\#![^\n]*\bperl\b/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rel =~ /\.(?:pm|pl|psgi|t)\z/iu or $raw =~ /\A\#![^\n]*\bperl\b/u
MC/DC0%0/2
$rel =~ /\.(?:pm|pl|psgi|t)\z/iu or $raw =~ /\A\#![^\n]*\bperl\b/u
$rel =~ /\.(?:pm|pl|psgi|t)\z/iu
$raw =~ /\A\#![^\n]*\bperl\b/u
Truth table33%1/3
A or B
A= $rel =~ /\.(?:pm|pl|psgi|t)\z/iuB= $raw =~ /\A\#![^\n]*\bperl\b/u
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 46 | $file_count++; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 46 | ▶ | if ($self->{embed_source}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 39 | ▶ | if (length($raw) <= $self->{max_source_bytes}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 39 | $sources{$rel} = decode('UTF-8', $raw, FB_DEFAULT); | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | push @{$self->{warnings}}, "Source exceeds embedding limit: $rel"; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 46 | my $parsed = $self->_parse_file($path, $rel, $raw); | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 46 | my %associated; | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 46 | for my $event (@{$parsed->{events}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | my $pkg = $event->{type} eq 'package' ? $event->{name} | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 218 | ▶ | : _package_at($parsed->{scopes}, $event->{line}, $parsed->{default}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 218 | ▶ | next unless defined $pkg && $pkg =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $pkg and $pkg =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/u
MC/DC0%0/2
defined $pkg and $pkg =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/u
defined $pkg
$pkg =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/u
Truth table33%1/3
A and B
A= defined $pkgB= $pkg =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 218 | $associated{$pkg} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 218 | ▶ | my $p = $packages{$pkg} ||= {path => $pkg, dir => dirname($rel), doc => '', imports => {}, files => {}}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$packages{$pkg} ||= {"path", $pkg, "dir", dirname($rel), "doc", "", "imports", {}, "files", {}}
MC/DC100%1/1
$packages{$pkg} ||= {"path", $pkg, "dir", dirname($rel), "doc", "", "imports", {}, "files", {}}
$packages{$pkg}
Truth table100%2/2
A
A= $packages{$pkg}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 218 | ▶ | my $f = $p->{files}{$rel} ||= {path => $rel, name => basename($rel), lines => $parsed->{lines}, funcs => []}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$p->{"files"}{$rel} ||= {"path", $rel, "name", basename($rel), "lines", $parsed->{"lines"}, "funcs", []}
MC/DC100%1/1
$p->{"files"}{$rel} ||= {"path", $rel, "name", basename($rel), "lines", $parsed->{"lines"}, "funcs", []}
$p->{"files"}{$rel}
Truth table100%2/2
A
A= $p->{"files"}{$rel}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 218 | ▶ | if ($event->{type} eq 'package') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 49 | ▶ | $p->{doc} ||= _preceding_comment($parsed->{raw_lines}, $event->{line}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$p->{"doc"} ||= _preceding_comment($parsed->{"raw_lines"}, $event->{"line"})
MC/DC0%0/2
$p->{"doc"} ||= _preceding_comment($parsed->{"raw_lines"}, $event->{"line"})
$p->{"doc"}
_preceding_comment($parsed->{"raw_lines"}, $event->{"line"})
Truth table33%1/3
A ||= B
A= $p->{"doc"}B= _preceding_comment($parsed->{"raw_lines"}, $event->{"line"})
| |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } elsif ($event->{type} eq 'sub') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 60 | ▶ | push @{$f->{funcs}}, { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | n => $event->{name}, l => $event->{line}, s => $event->{size}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | k => $event->{kind}, e => ($event->{name} !~ /^_/ ? JSON::PP::true : JSON::PP::false), | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 60 | d => _preceding_comment($parsed->{raw_lines}, $event->{line}), | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } elsif ($event->{type} eq 'include') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 109 | for my $target (@{$event->{targets}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 109 | ▶ | $p->{imports}{$target} = 1 if $target ne $pkg; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 46 | ▶ | if (!%associated) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $pkg = $parsed->{default}; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | my $p = $packages{$pkg} ||= {path => $pkg, dir => dirname($rel), doc => '', imports => {}, files => {}}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$packages{$pkg} ||= {"path", $pkg, "dir", dirname($rel), "doc", "", "imports", {}, "files", {}}
MC/DC0%0/1
$packages{$pkg} ||= {"path", $pkg, "dir", dirname($rel), "doc", "", "imports", {}, "files", {}}
$packages{$pkg}
Truth table0%0/2
A
A= $packages{$pkg}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | $p->{files}{$rel} ||= {path => $rel, name => basename($rel), lines => $parsed->{lines}, funcs => []}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$p->{"files"}{$rel} ||= {"path", $rel, "name", basename($rel), "lines", $parsed->{"lines"}, "funcs", []}
MC/DC0%0/1
$p->{"files"}{$rel} ||= {"path", $rel, "name", basename($rel), "lines", $parsed->{"lines"}, "funcs", []}
$p->{"files"}{$rel}
Truth table0%0/2
A
A= $p->{"files"}{$rel}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 5 | my @pkgs; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | 5 | for my $name (sort keys %packages) { | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 51 | my $p = $packages{$name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my @files = sort { $a->{path} cmp $b->{path} } values %{$p->{files}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | 51 | for my $file (@files) { | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 51 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | 9 | ▶ | @{$file->{funcs}} = sort { $a->{l} <=> $b->{l} || $a->{n} cmp $b->{n} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$Perl::CodeMap::a->{'l'} <=> $Perl::CodeMap::b->{'l'} || $Perl::CodeMap::a->{'n'} cmp $Perl::CodeMap::b->{'n'}
MC/DC0%0/2
$Perl::CodeMap::a->{'l'} <=> $Perl::CodeMap::b->{'l'} || $Perl::CodeMap::a->{'n'} cmp $Perl::CodeMap::b->{'n'}
$Perl::CodeMap::a->{'l'} <=> $Perl::CodeMap::b->{'l'}
$Perl::CodeMap::a->{'n'} cmp $Perl::CodeMap::b->{'n'}
Truth table33%1/3
A || B
A= $Perl::CodeMap::a->{'l'} <=> $Perl::CodeMap::b->{'l'}B= $Perl::CodeMap::a->{'n'} cmp $Perl::CodeMap::b->{'n'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 51 | grep { !$seen{join(':', $_->{l}, $_->{n})}++ } @{$file->{funcs}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | push @pkgs, { | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | path => $name, dir => $p->{dir}, doc => $p->{doc}, files => \@files, | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 51 | ▶ | imports => [ sort grep { $_ ne $name && exists $packages{$_} } keys %{$p->{imports}} ], | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_ ne $name && exists $packages{$_}
MC/DC50%1/2
$_ ne $name && exists $packages{$_}
$_ ne $name
exists $packages{$_}
Truth table66%2/3
A && B
A= $_ ne $nameB= exists $packages{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 5 | my ($source, $rev) = $self->_source_info; | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | return { | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | format => 1, name => ($self->{name} // basename($root)), module => $root, | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | parser => $self->{parser}, rev => $rev, source => $source, scanned_files => $file_count, | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 5 | ▶ | pkgs => \@pkgs, sources => \%sources, warnings => [@{$self->{warnings}}], | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"name"} // basename($root)
MC/DC0%0/2
$self->{"name"} // basename($root)
$self->{"name"}
basename($root)
Truth table33%1/3
A // B
A= $self->{"name"}B= basename($root)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 46 | ▶ | sub _parse_file { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_file: called CC=32 SCAR=38.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 46 | my ($self, $path, $rel, $raw) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | 46 | my @lines = split /\n/, $raw, -1; | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | 46 | ▶ | pop @lines if @lines > 1 && $lines[-1] eq ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@lines > 1 and $lines[-1] eq ""
MC/DC0%0/2
@lines > 1 and $lines[-1] eq ""
@lines > 1
$lines[-1] eq ""
Truth table33%1/3
A and B
A= @lines > 1B= $lines[-1] eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 46 | my $default = _inferred_name($rel); | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 46 | my @events; | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | my @scopes; | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 46 | my @lite = _mask_lines(\@lines); | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | 46 | ▶ | if ($self->{parser} eq 'ppi') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 12 | my $doc = eval { PPI::Document->new($path) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 12 | ▶ | if ($doc) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 12 | $doc->index_locations; | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | 12 | ▶ | for my $p (@{$doc->find('PPI::Statement::Package') || []}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$doc->find('PPI::Statement::Package') || []
MC/DC100%1/1
$doc->find('PPI::Statement::Package') || []
$doc->find('PPI::Statement::Package')
Truth table100%2/2
A
A= $doc->find('PPI::Statement::Package')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 12 | my $name = $p->namespace; | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | 12 | my $at = $p->location; | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | 12 | ▶ | next unless $name && $at; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$name and $at
MC/DC0%0/2
$name and $at
$name
$at
Truth table33%1/3
A and B
A= $nameB= $at
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 12 | my $scope = { name => $name, line => $at->[0] }; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 12 | push @scopes, $scope; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 12 | push @events, {type => 'package', name => $name, line => $at->[0]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 12 | ▶ | for my $s (@{$doc->find('PPI::Statement::Sub') || []}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$doc->find('PPI::Statement::Sub') || []
MC/DC0%0/1
$doc->find('PPI::Statement::Sub') || []
$doc->find('PPI::Statement::Sub')
Truth table50%1/2
A
A= $doc->find('PPI::Statement::Sub')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 16 | my $name = $s->name; | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | 16 | my $at = $s->location; | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | 16 | ▶ | next unless $name && $at; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$name and $at
MC/DC0%0/2
$name and $at
$name
$at
Truth table33%1/3
A and B
A= $nameB= $at
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 16 | my $end = $at->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | 16 | my $block = $s->block; | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | 16 | ▶ | if ($block) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 16 | my $last = $block->last_token; | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | 16 | ▶ | my $finish = $last && $last->location; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$last && $last->location
MC/DC0%0/2
$last && $last->location
$last
$last->location
Truth table33%1/3
A && B
A= $lastB= $last->location
| |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 16 | ▶ | $end = $finish->[0] if $finish && $finish->[0] > $end; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$finish and $finish->[0] > $end
MC/DC50%1/2
$finish and $finish->[0] > $end
$finish
$finish->[0] > $end
Truth table66%2/3
A and B
A= $finishB= $finish->[0] > $end
| |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 16 | push @events, {type => 'sub', name => $name, line => $at->[0], | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | size => $end-$at->[0]+1, kind => 'sub'}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 12 | ▶ | for my $s (@{$doc->find('PPI::Statement::Include') || []}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$doc->find('PPI::Statement::Include') || []
MC/DC0%0/1
$doc->find('PPI::Statement::Include') || []
$doc->find('PPI::Statement::Include')
Truth table50%1/2
A
A= $doc->find('PPI::Statement::Include')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 43 | ▶ | next if ($s->type // '') eq 'no'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$s->type // ""
MC/DC0%0/1
$s->type // ""
$s->type
Truth table50%1/2
A
A= $s->type
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 43 | my $name = $s->module; | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | 43 | my $at = $s->location; | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | 43 | ▶ | next unless $at && $name && $name =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$at and $name and $name =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/u
$at and $name
MC/DC0%0/3
$at and $name and $name =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/u
$at
$name
$name =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/u
Truth table25%1/4
A and B and C
A= $atB= $nameC= $name =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 43 | push @events, {type => 'include', line => $at->[0], targets => [$name]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | push @{$self->{warnings}}, "PPI could not parse $rel; using limited parser"; | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | push @events, _lite_events(\@lite, \@lines); | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 34 | push @events, _lite_events(\@lite, \@lines); | |||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # Explicit scopes from literal source also support the optional lite mode; | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # this intentionally does not attempt full lexical Perl semantics. | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 46 | for my $i (0..$#lite) { | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | 415 | ▶ | next unless $lite[$i] =~ /^\s*package\s+([A-Za-z_]\w*(?:::\w+)*)\b/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 49 | my $name = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | 49 | ▶ | next if $self->{parser} eq 'ppi' && grep { $_->{name} eq $name && $_->{line} == $i+1 } @scopes; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$self->{"parser"} eq "ppi" and grep {$_->{"name"} eq $name and $_->{"line"} == $i + 1;} @scopes
$_->{'name'} eq $name && $_->{'line'} == $i + 1
MC/DC50%1/2
$self->{"parser"} eq "ppi" and grep {$_->{"name"} eq $name and $_->{"line"} == $i + 1;} @scopes
$self->{"parser"} eq "ppi"
grep {$_->{"name"} eq $name and $_->{"line"} == $i + 1;} @scopes
MC/DC50%1/2
$_->{'name'} eq $name && $_->{'line'} == $i + 1
$_->{'name'} eq $name
$_->{'line'} == $i + 1
Truth table66%2/3
A and B
A= $self->{"parser"} eq "ppi"B= grep {$_->{"name"} eq $name and $_->{"line"} == $i + 1;} @scopes
Truth table66%2/3
A && B
A= $_->{'name'} eq $nameB= $_->{'line'} == $i + 1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 37 | push @scopes, {name => $name, line => $i+1}; | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | 37 | push @events, {type => 'package', name => $name, line => $i+1}; | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 46 | push @events, _extra_events(\@lite, \@lines); | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 46 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | @events = grep { | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 46 | !$seen{join('|', $_->{type}, $_->{line}, ($_->{name}//''), ($_->{kind}//''), | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | 218 | ▶ | join(',',@{$_->{targets}//[]}))}++ | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$_->{"name"} // ""
$_->{"kind"} // ""
$_->{"targets"} // []
MC/DC100%1/1
$_->{"name"} // ""
$_->{"name"}
MC/DC100%1/1
$_->{"kind"} // ""
$_->{"kind"}
MC/DC100%1/1
$_->{"targets"} // []
$_->{"targets"}
Truth table100%2/2
A
A= $_->{"name"}
Truth table100%2/2
A
A= $_->{"kind"}
Truth table100%2/2
A
A= $_->{"targets"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } @events; | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 46 | @scopes = sort { $a->{line} <=> $b->{line} } @scopes; | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | 46 | return {events => \@events, scopes => \@scopes, default => $default, lines => scalar(@lines), raw_lines => \@lines}; | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 46 | ▶ | sub _inferred_name { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_inferred_name: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 46 | my ($rel) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | 46 | ▶ | if ($rel =~ /(?:^|\/)lib\/(.+)\.pm\z/ || $rel =~ /\A(.+)\.pm\z/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$rel =~ m[(?:^|/)lib/(.+)\.pm\z]u or $rel =~ /\A(.+)\.pm\z/u
MC/DC50%1/2
$rel =~ m[(?:^|/)lib/(.+)\.pm\z]u or $rel =~ /\A(.+)\.pm\z/u
$rel =~ m[(?:^|/)lib/(.+)\.pm\z]u
$rel =~ /\A(.+)\.pm\z/u
Truth table66%2/3
A or B
A= $rel =~ m[(?:^|/)lib/(.+)\.pm\z]uB= $rel =~ /\A(.+)\.pm\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 43 | my $name = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 200 | 43 | $name =~ s{/}{::}g; | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | 43 | ▶ | return $name if $name =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 3 | return 'main'; | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 169 | ▶ | sub _package_at { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_package_at: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 169 | my ($scopes, $line, $default) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | 169 | my $pkg = $default; | |||||||||||||||||||||||||||||||||||||||||||||
| 209 | 169 | for my $p (@$scopes) { | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | 171 | ▶ | last if $p->{line} > $line; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 164 | $pkg = $p->{name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 169 | return $pkg; | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 46 | ▶ | sub _mask_lines { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mask_lines: called CC=20 SCAR=30.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 46 | my ($lines) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | 46 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | 46 | my $pod = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | 46 | my @heredocs; | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | 46 | my $ended = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | 46 | for my $raw (@$lines) { | |||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | if ($ended) { push @out, ""; next; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 415 | ▶ | if (@heredocs) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 6 | push @out, ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 226 | 6 | ▶ | shift @heredocs if $raw =~ /^\Q$heredocs[0]\E\s*;?\s*\z/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 409 | ▶ | if ($pod) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 6 | ▶ | $pod = 0 if $raw =~ /^=cut\b/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 6 | push @out, ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 403 | ▶ | if ($raw =~ /^=(?:pod|head\d|begin|for|item|over|back|encoding)\b/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 3 | $pod = 1; push @out, ''; next; | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | if ($raw =~ /^__(?:DATA|END)__\b/) { $ended = 1; push @out, ''; next; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 400 | my ($out, $quote) = ('',''); | |||||||||||||||||||||||||||||||||||||||||||||
| 239 | 400 | my @chars = split //, $raw; | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | 400 | ▶ | for (my $i=0; $i<@chars; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 5226 | my $char = $chars[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | 5226 | ▶ | if ($quote) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 291 | ▶ | if ($char eq '\\') { $out .= ' '; $i++ if $i+1<@chars; next; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 289 | ▶ | $quote = '' if $char eq $quote; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 289 | $out .= ' '; next; | |||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 4935 | ▶ | last if $char eq '#'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 4901 | ▶ | if ($char eq "'" || $char eq '"' || $char eq '`') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$char eq "'" or $char eq "\"" or $char eq "`"
$char eq "'" or $char eq "\""
MC/DC66%2/3
$char eq "'" or $char eq "\"" or $char eq "`"
$char eq "'"
$char eq "\""
$char eq "`"
Truth table75%3/4
A or B or C
A= $char eq "'"B= $char eq "\""C= $char eq "`"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 28 | $quote = $char; $out .= ' '; next; | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 4873 | $out .= $char; | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 400 | push @out, $out; | |||||||||||||||||||||||||||||||||||||||||||||
| 254 | 400 | ▶ | while ($out =~ /<<\s*([A-Za-z_]\w*)/g) { push @heredocs, $1; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | while ($raw =~ /<<\s*['"]([A-Za-z_]\w*)['"]/g) { push @heredocs, $1; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 46 | return @out; | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 44 | ▶ | sub _block_length { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_block_length: called CC=11 SCAR=25.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 44 | my ($lines,$start) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | 44 | for my $i ($start..$#$lines) { | |||||||||||||||||||||||||||||||||||||||||||||
| 263 | 44 | ▶ | last if $i > $start+30; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 44 | my $offset = index($lines->[$i],'{'); | |||||||||||||||||||||||||||||||||||||||||||||
| 265 | 44 | ▶ | if ($offset >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 44 | my $depth = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | 44 | for my $j ($i..$#$lines) { | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | 86 | my $line = $lines->[$j]; | |||||||||||||||||||||||||||||||||||||||||||||
| 269 | 86 | ▶ | for(my $c=($j==$i?$offset:0); $c<length($line); $c++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 1036 | my $ch = substr($line,$c,1); | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1036 | ▶ | $depth++ if $ch eq '{'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1036 | ▶ | $depth-- if $ch eq '}'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1036 | ▶ | return $j-$start+1 if $depth == 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | return 1 if $lines->[$i] =~ /;/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 34 | ▶ | sub _lite_events { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lite_events: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 34 | my ($masked,$original) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | 34 | my @events; | |||||||||||||||||||||||||||||||||||||||||||||
| 286 | 34 | for my $i (0..$#$masked) { | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | 267 | my $s = $masked->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 288 | 267 | ▶ | if ($s =~ /^\s*(?:(?:my|our|state)\s+)?sub\s+([A-Za-z_]\w*(?:::\w+)*)\b/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 41 | push @events, {type=>'sub',name=>$1,line=>$i+1,size=>_block_length($masked,$i),kind=>'sub'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 267 | ▶ | if ($s =~ /^\s*(?:use|require)\s+([A-Za-z_]\w*(?:::\w+)*)\b/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 55 | push @events, {type=>'include',line=>$i+1,targets=>[$1]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 34 | return @events; | |||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 46 | ▶ | sub _extra_events { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extra_events: called CC=8 SCAR=23.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 46 | my ($masked, $original) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 300 | 46 | my @events; | |||||||||||||||||||||||||||||||||||||||||||||
| 301 | 46 | for my $i (0..$#$masked) { | |||||||||||||||||||||||||||||||||||||||||||||
| 302 | 415 | my $s = $masked->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 303 | 415 | ▶ | if ($s =~ /^\s*method\s+([A-Za-z_]\w*)\b/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 3 | push @events, {type=>'sub',name=>$1,line=>$i+1,size=>_block_length($masked,$i),kind=>'method'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 415 | ▶ | next unless $s =~ /^\s*(?:extends|with|use\s+(?:parent|base))\b/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 11 | my $part=$original->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 308 | 11 | $part =~ s/^\s*(?:extends|with|use\s+(?:parent|base))\s*//; | |||||||||||||||||||||||||||||||||||||||||||||
| 309 | 11 | $part =~ s/\s*;.*\z//; | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | 11 | $part =~ s/^-norequire\s*[,;]?\s*//; | |||||||||||||||||||||||||||||||||||||||||||||
| 311 | 11 | my @names; | |||||||||||||||||||||||||||||||||||||||||||||
| 312 | 11 | ▶ | if ($part =~ /^qw\s*([\(\[\{<\/!#|])/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | my $open=$1; my %close=('('=>')','['=>']','{'=>'}','<'=>'>'); | |||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | my $end=$close{$open}//$open; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$close{$open} // $open
MC/DC0%0/2
$close{$open} // $open
$close{$open}
$open
Truth table0%0/3
A // B
A= $close{$open}B= $open
| |||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | if ($part =~ /\Q$open\E(.*?)\Q$end\E/) { @names=split /\s+/, $1; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 11 | @names=$part =~ /['"]([A-Za-z_]\w*(?:::\w+)*)['"]/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 11 | @names=grep { /\A[A-Za-z_]\w*(?:::\w+)*\z/ } @names; | |||||||||||||||||||||||||||||||||||||||||||||
| 320 | 11 | ▶ | push @events, {type=>'include',line=>$i+1,targets=>\@names} if @names; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 46 | return @events; | |||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 109 | ▶ | sub _preceding_comment { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_preceding_comment: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 109 | my ($lines,$line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | 109 | my @parts; | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | 109 | ▶ | for (my $i=$line-2; $i>=0; $i--) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 97 | ▶ | last unless $lines->[$i] =~ /^\s*#\s?(.*?)\s*\z/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 32 | unshift @parts, $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 109 | my $joined=join(' ',@parts); | |||||||||||||||||||||||||||||||||||||||||||||
| 333 | 109 | $joined =~ s/\s+/ /g; | |||||||||||||||||||||||||||||||||||||||||||||
| 334 | 109 | $joined =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 335 | 109 | ▶ | return length($joined)>180 ? substr($joined,0,177).'...' : $joined; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # Read source paths from a previously generated JSON without trusting paths | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | # that could traverse outside of the specified root (or traverse symlinks). | ||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 2 | ▶ | sub hydrate_sources { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hydrate_sources: called CC=17 SCAR=30.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 2 | my ($self,$data,$dir) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 342 | 2 | ▶ | my $root=abs_path($dir // $self->{root}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$dir // $self->{"root"}
MC/DC0%0/2
$dir // $self->{"root"}
$dir
$self->{"root"}
Truth table33%1/3
A // B
A= $dirB= $self->{"root"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 2 | ▶ | die "Source directory does not exist\n" unless $root && -d $root; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$root and -d $root
MC/DC0%0/2
$root and -d $root
$root
-d $root
Truth table33%1/3
A and B
A= $rootB= -d $root
| |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 13 | my %paths=map { $_->{path} => 1 } | |||||||||||||||||||||||||||||||||||||||||||||
| 345 | 2 | ▶ | map { @{$_->{files} || []} } @{$data->{pkgs} || []}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$_->{'files'} || []
$data->{'pkgs'} || []
MC/DC0%0/1
$_->{'files'} || []
$_->{'files'}
MC/DC0%0/1
$data->{'pkgs'} || []
$data->{'pkgs'}
Truth table50%1/2
A
A= $_->{'files'}
Truth table50%1/2
A
A= $data->{'pkgs'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 2 | ▶ | $data->{sources} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$data->{"sources"} ||= {}
MC/DC0%0/1
$data->{"sources"} ||= {}
$data->{"sources"}
Truth table50%1/2
A
A= $data->{"sources"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 2 | my $count=0; | |||||||||||||||||||||||||||||||||||||||||||||
| 348 | 2 | for my $rel (sort keys %paths) { | |||||||||||||||||||||||||||||||||||||||||||||
| 349 | 12 | ▶ | next if $rel =~ /\0|\\/ || $rel =~ m{\A/} || $rel =~ m{(?:\A|/)\.\.(?:/|\z)}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$rel =~ /\0|\\/u or $rel =~ m[\A/]u or $rel =~ m[(?:\A|/)\.\.(?:/|\z)]u
$rel =~ /\0|\\/u or $rel =~ m[\A/]u
MC/DC66%2/3
$rel =~ /\0|\\/u or $rel =~ m[\A/]u or $rel =~ m[(?:\A|/)\.\.(?:/|\z)]u
$rel =~ /\0|\\/u
$rel =~ m[\A/]u
$rel =~ m[(?:\A|/)\.\.(?:/|\z)]u
Truth table75%3/4
A or B or C
A= $rel =~ /\0|\\/uB= $rel =~ m[\A/]uC= $rel =~ m[(?:\A|/)\.\.(?:/|\z)]u
| |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 9 | my $path=File::Spec->catfile($root,split m{/},$rel); | |||||||||||||||||||||||||||||||||||||||||||||
| 351 | 9 | ▶ | next unless -f $path && !-l $path && -s $path <= $self->{max_source_bytes}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
-f $path and not -l $path and -s $path <= $self->{"max_source_bytes"}
-f $path and not -l $path
MC/DC33%1/3
-f $path and not -l $path and -s $path <= $self->{"max_source_bytes"}
-f $path
not -l $path
-s $path <= $self->{"max_source_bytes"}
Truth table50%2/4
A and not(B) and C
A= -f $pathB= not -l $pathC= -s $path <= $self->{"max_source_bytes"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 8 | my $real=abs_path($path); | |||||||||||||||||||||||||||||||||||||||||||||
| 353 | 8 | ▶ | next unless $real && index($real,"$root/")==0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$real and index($real, "$root/") == 0
MC/DC0%0/2
$real and index($real, "$root/") == 0
$real
index($real, "$root/") == 0
Truth table33%1/3
A and B
A= $realB= index($real, "$root/") == 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 8 | ▶ | open my $fh,'<:raw',$path or next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 8 | my $bytes=do { local $/; <$fh> }; | |||||||||||||||||||||||||||||||||||||||||||||
| 356 | 8 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||
| 357 | 8 | $data->{sources}{$rel}=decode('UTF-8',$bytes,FB_DEFAULT); | |||||||||||||||||||||||||||||||||||||||||||||
| 358 | 8 | $count++; | |||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 2 | return $count; | |||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 5 | ▶ | sub _capture { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_capture: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 5 | my (@command)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 365 | 5 | my ($in,$out); | |||||||||||||||||||||||||||||||||||||||||||||
| 366 | 5 | my $err=gensym; | |||||||||||||||||||||||||||||||||||||||||||||
| 367 | 5 | my $pid=eval { IPC::Open3::open3($in,$out,$err,@command) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 368 | 5 | ▶ | return undef unless $pid; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 5 | close $in; | |||||||||||||||||||||||||||||||||||||||||||||
| 370 | 5 | my $value=do { local $/; <$out> }; | |||||||||||||||||||||||||||||||||||||||||||||
| 371 | 5 | close $out; | |||||||||||||||||||||||||||||||||||||||||||||
| 372 | 5 | my $discard=do { local $/; <$err> }; | |||||||||||||||||||||||||||||||||||||||||||||
| 373 | 5 | close $err; | |||||||||||||||||||||||||||||||||||||||||||||
| 374 | 5 | waitpid($pid,0); | |||||||||||||||||||||||||||||||||||||||||||||
| 375 | 5 | ▶ | return undef if $?; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | $value //= ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$value //= ""
MC/DC0%0/1
$value //= ""
$value
Truth table0%0/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | $value =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 5 | ▶ | sub _source_info { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_source_info: called CC=7 SCAR=30.7
| |||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 5 | my ($self)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 383 | 5 | ▶ | return ($self->{source_base},'') if defined $self->{source_base}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 5 | ▶ | my $rev=_capture('git','-C',$self->{root},'rev-parse','HEAD')//''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
_capture("git", "-C", $self->{"root"}, "rev-parse", "HEAD") // ""
MC/DC0%0/1
_capture("git", "-C", $self->{"root"}, "rev-parse", "HEAD") // ""
_capture("git", "-C", $self->{"root"}, "rev-parse", "HEAD")
Truth table50%1/2
A
A= _capture("git", "-C", $self->{"root"}, "rev-parse", "HEAD")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 5 | ▶ | return ('','') unless $rev =~ /^[a-f0-9]{40}$/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | my $remote=_capture('git','-C',$self->{root},'remote','get-url','origin')//''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
_capture("git", "-C", $self->{"root"}, "remote", "get-url", "origin") // ""
MC/DC0%0/1
_capture("git", "-C", $self->{"root"}, "remote", "get-url", "origin") // ""
_capture("git", "-C", $self->{"root"}, "remote", "get-url", "origin")
Truth table0%0/2
A
A= _capture("git", "-C", $self->{"root"}, "remote", "get-url", "origin")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | my ($owner,$repo)=$remote =~ m{github\.com[:/]([^/\s:]+)/([^/\s]+?)(?:\.git)?\z}; | |||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | return ('',$rev) unless defined $owner; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | my $prefix=_capture('git','-C',$self->{root},'rev-parse','--show-prefix')//''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
_capture("git", "-C", $self->{"root"}, "rev-parse", "--show-prefix") // ""
MC/DC0%0/1
_capture("git", "-C", $self->{"root"}, "rev-parse", "--show-prefix") // ""
_capture("git", "-C", $self->{"root"}, "rev-parse", "--show-prefix")
Truth table0%0/2
A
A= _capture("git", "-C", $self->{"root"}, "rev-parse", "--show-prefix")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | return ("https://github.com/$owner/$repo/blob/$rev/$prefix",$rev); | |||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 3 | ▶ | sub write_report { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_report: called CC=13 SCAR=26.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 3 | my ($self,$data,%opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 395 | 3 | ▶ | my $output=$opts{output}//'perl-code-map.html'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"output"} // "perl-code-map.html"
MC/DC0%0/1
$opts{"output"} // "perl-code-map.html"
$opts{"output"}
Truth table50%1/2
A
A= $opts{"output"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 3 | ▶ | die "Expected data with pkgs array\n" unless ref($data) eq 'HASH' && ref($data->{pkgs}) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $data eq "HASH" and ref $data->{"pkgs"} eq "ARRAY"
MC/DC0%0/2
ref $data eq "HASH" and ref $data->{"pkgs"} eq "ARRAY"
ref $data eq "HASH"
ref $data->{"pkgs"} eq "ARRAY"
Truth table33%1/3
A and B
A= ref $data eq "HASH"B= ref $data->{"pkgs"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 3 | my $encoder=JSON::PP->new->canonical(1)->utf8(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 398 | 3 | my $json=$encoder->encode($data); | |||||||||||||||||||||||||||||||||||||||||||||
| 399 | 3 | ▶ | if ($opts{json}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 2 | ▶ | open my $fh,'>:raw',$opts{json} or die "Cannot write $opts{json}: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 2 | print {$fh} $json; | |||||||||||||||||||||||||||||||||||||||||||||
| 402 | 2 | ▶ | close $fh or die "Cannot close $opts{json}: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 3 | ▶ | my $module_file=$INC{'Perl/CodeMap.pm'} // __FILE__; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$INC{"Perl/CodeMap.pm"} // __FILE__
MC/DC0%0/1
$INC{"Perl/CodeMap.pm"} // __FILE__
$INC{"Perl/CodeMap.pm"}
Truth table50%1/2
A
A= $INC{"Perl/CodeMap.pm"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 3 | my $assets=File::Spec->catdir(dirname($module_file),'CodeMap','assets'); | |||||||||||||||||||||||||||||||||||||||||||||
| 406 | 3 | my %a; | |||||||||||||||||||||||||||||||||||||||||||||
| 407 | 3 | for my $name (qw(template.html app.css app.js prism-core.min.js prism-perl.min.js)) { | |||||||||||||||||||||||||||||||||||||||||||||
| 408 | 15 | ▶ | open my $fh,'<:raw',File::Spec->catfile($assets,$name) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 409 | or die "Missing packaged report asset '$name' ($!)\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 15 | $a{$name}=do { local $/; <$fh> }; | |||||||||||||||||||||||||||||||||||||||||||||
| 411 | 15 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 3 | ▶ | my $title=$data->{name}//'Perl'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$data->{"name"} // "Perl"
MC/DC0%0/1
$data->{"name"} // "Perl"
$data->{"name"}
Truth table50%1/2
A
A= $data->{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 3 | $title =~ s/&/&/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 415 | 3 | $title =~ s/</</g; | |||||||||||||||||||||||||||||||||||||||||||||
| 416 | 3 | $title =~ s/>/>/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 417 | 3 | $title =~ s/"/"/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 418 | 3 | $a{'template.html'} =~ s/\{\{TITLE\}\}/$title/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 419 | 3 | $json =~ s/</\\u003c/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 420 | 3 | $json =~ s/>/\\u003e/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 421 | 3 | $json =~ s/&/\\u0026/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 422 | 3 | ▶ | open my $fh,'>:raw',$output or die "Cannot write $output: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 3 | my $html=$a{'template.html'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 424 | 3 | $html =~ s{<!-- STYLE -->}{'<style>' . $a{'app.css'} . '</style>'}e; | |||||||||||||||||||||||||||||||||||||||||||||
| 425 | 3 | $html =~ s{<!-- JSON -->}{'<script id="data" type="application/json">'.$json.'</script>'}e; | |||||||||||||||||||||||||||||||||||||||||||||
| 426 | 3 | $html =~ s{<!-- JS -->}{'<script>'.$a{'prism-core.min.js'}.'</script><script>'.$a{'prism-perl.min.js'}.'</script><script>'.$a{'app.js'}.'</script>'}e; | |||||||||||||||||||||||||||||||||||||||||||||
| 427 | 3 | print {$fh} $html; | |||||||||||||||||||||||||||||||||||||||||||||
| 428 | 3 | ▶ | close $fh or die "Cannot close $output: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 3 | return $output; | |||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||
| 434 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||