lib/Perl/CodeMap.pm

filter: Statementstmt 91.3% 357 / 391 Branchbran 72.5% 135 / 186 Conditioncond 50.6% 76 / 150 MC/DCmcdc 20.6% 18 / 87 Subroutinesub 100% 26 / 26 Podpod 100% 4 / 4 totaltotal 72.9% 616 / 844 CC 170 SCAR 31.8
CC
170
Cov
78%
analyze
46.1
_parse_file
45.0
_source_info
21.5
CRAP 24.1
↑ Summary bin/perl-codemap »
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"} // "."
l!l
100
MC/DC0%0/1
$arg{"root"} // "."
$arg{"root"}
Truth table50%1/2
A
A= $arg{"root"}
Aresult
11
00
19 10 ▶ die "Source directory does not exist\n" unless defined $root && -d $root;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $root and -d $root 0 10 10
Condition33%1/3
defined $root and -d $root
!ll&&!rl&&r
0010
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
ABresult
0X0
100
111
20 10 ▶ my $mode = $arg{parser} // 'auto';
Condition50%1/2
$arg{"parser"} // "auto"
l!l
100
MC/DC0%0/1
$arg{"parser"} // "auto"
$arg{"parser"}
Truth table50%1/2
A
A= $arg{"parser"}
Aresult
11
00
21 10 ▶ die "parser must be one of auto, ppi, lite\n" unless $mode =~ /\A(?:auto|ppi|lite)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $mode =~ /\A(?:auto|ppi|lite)\z/u 1 9 10
22 9 ▶ my $ppi = eval { require PPI; 1 } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require PPI; 1 } } ? : 9 0 9
23 9 ▶ die "PPI is not installed. Install it using 'cpanm PPI', or use --parser lite\n"
Branch: 1 branch
BranchTrueFalseTotal
if $mode eq "ppi" and not $ppi 0 9 9
Condition66%2/3
$mode eq "ppi" and not $ppi
!ll&&!rl&&r
810
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
ABresult
0X0
100
111
24 if $mode eq 'ppi' && !$ppi;
25 9 ▶ my $selected = $mode eq 'auto' ? ($ppi ? 'ppi' : 'lite') : $mode;
Branch: 2 branches
BranchTrueFalseTotal
$mode eq 'auto' ? : 1 8 9
$ppi ? : 1 0 1
26 9 ▶ my $max_bytes = $arg{max_source_bytes} // 2_000_000;
Condition50%1/2
$arg{"max_source_bytes"} // 2000000
l!l
09
MC/DC0%0/1
$arg{"max_source_bytes"} // 2000000
$arg{"max_source_bytes"}
Truth table50%1/2
A
A= $arg{"max_source_bytes"}
Aresult
11
00
27 9 ▶ die "max_source_bytes must be a positive integer\n" unless $max_bytes =~ /\A[1-9][0-9]*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $max_bytes =~ /\A[1-9][0-9]*\z/u 0 9 9
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
BranchTrueFalseTotal
$arg{'include_tests'} ? : 1 8 9
exists $arg{'embed_source'} ? : 3 6 9
$arg{'embed_source'} ? : 1 2 3
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
BranchTrueFalseTotal
unless ($self->{"include_tests"}) 4 1 5
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
BranchTrueFalseTotal
if (-d $path) 27 46 73
47 27 my $base = basename($path);
48 27 ▶ $File::Find::prune = 1 if $path ne $root && ($ignored{$base} || $base =~ /^\./);
Branch: 1 branch
BranchTrueFalseTotal
if $path ne $root and $ignored{$base} || $base =~ /^\./u 7 20 27
Condition83%5/6
$path ne $root and $ignored{$base} || $base =~ /^\./u
!ll&&!rl&&r
5157
$ignored{$base} or $base =~ /^\./u
l!l&&r!l&&!r
7015
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
ABCresult
0XX0
1000
11X1
1011
49 27 return;
50 }
51 46 ▶ return unless -f $path && !-l $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $path and not -l $path 0 46 46
Condition33%1/3
-f $path and not -l $path
!ll&&!rl&&r
0046
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
ABresult
0X0
100
111
52 46 ▶ return unless $self->{include_tests} || $path !~ /\.t\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"include_tests"} or not $path =~ /\.t\z/u 0 46 46
Condition66%2/3
$self->{"include_tests"} or not $path =~ /\.t\z/u
l!l&&r!l&&!r
8380
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
ABresult
1X1
011
000
53 46 ▶ return unless $path =~ /\.(?:pm|pl|psgi|t)\z/i || basename($path) !~ /\./;
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ /\.(?:pm|pl|psgi|t)\z/iu or not basename($path) =~ /\./u 0 46 46
Condition33%1/3
$path =~ /\.(?:pm|pl|psgi|t)\z/iu or not basename($path) =~ /\./u
l!l&&r!l&&!r
4600
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
open my $fh, "<:raw", $path or do { push @{$$self{"warnings"};}, 'Unable to read ' . "File::Spec"->abs2rel($path, $root); next } 46 0 46
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
BranchTrueFalseTotal
unless $rel =~ /\.(?:pm|pl|psgi|t)\z/iu or $raw =~ /\A\#![^\n]*\bperl\b/u 0 46 46
Condition33%1/3
$rel =~ /\.(?:pm|pl|psgi|t)\z/iu or $raw =~ /\A\#![^\n]*\bperl\b/u
l!l&&r!l&&!r
4600
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
ABresult
1X1
011
000
70 46 $file_count++;
71 46 ▶ if ($self->{embed_source}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"embed_source"}) 39 7 46
72 39 ▶ if (length($raw) <= $self->{max_source_bytes}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $raw <= $self->{'max_source_bytes'}) { } 39 0 39
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
BranchTrueFalseTotal
$event->{'type'} eq 'package' ? : 49 169 218
83 218 ▶ next unless defined $pkg && $pkg =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pkg and $pkg =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/u 0 218 218
Condition33%1/3
defined $pkg and $pkg =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/u
!ll&&!rl&&r
00218
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
ABresult
0X0
100
111
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", {}}
l!l
16751
MC/DC100%1/1
$packages{$pkg} ||= {"path", $pkg, "dir", dirname($rel), "doc", "", "imports", {}, "files", {}}
$packages{$pkg}
Truth table100%2/2
A
A= $packages{$pkg}
Aresult
11
00
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", []}
l!l
16751
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}
Aresult
11
00
87 218 ▶ if ($event->{type} eq 'package') {
Branch: 3 branches
BranchTrueFalseTotal
if ($event->{'type'} eq 'package') { } 49 169 218
elsif ($event->{'type'} eq 'sub') { } 60 109 169
elsif ($event->{'type'} eq 'include') { } 109 0 109
88 49 ▶ $p->{doc} ||= _preceding_comment($parsed->{raw_lines}, $event->{line});
Condition33%1/3
$p->{"doc"} ||= _preceding_comment($parsed->{"raw_lines"}, $event->{"line"})
l!l&&r!l&&!r
0049
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"})
ABresult
1X1
011
000
89 } elsif ($event->{type} eq 'sub') {
90 60 ▶ push @{$f->{funcs}}, {
Branch: 1 branch
BranchTrueFalseTotal
!($event->{'name'} =~ /^_/u) ? : 57 3 60
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
BranchTrueFalseTotal
if $target ne $pkg 109 0 109
98 }
99 }
100 }
101 46 ▶ if (!%associated) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%associated) 0 46 46
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", {}}
l!l
00
MC/DC0%0/1
$packages{$pkg} ||= {"path", $pkg, "dir", dirname($rel), "doc", "", "imports", {}, "files", {}}
$packages{$pkg}
Truth table0%0/2
A
A= $packages{$pkg}
Aresult
11
00
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", []}
l!l
00
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}
Aresult
11
00
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'}
l!l&&r!l&&!r
900
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'}
ABresult
1X1
011
000
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{$_}
!ll&&!rl&&r
05653
MC/DC50%1/2
$_ ne $name && exists $packages{$_}
$_ ne $name exists $packages{$_}
Truth table66%2/3
A && B
A= $_ ne $nameB= exists $packages{$_}
ABresult
0X0
100
111
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)
l!l&&r!l&&!r
050
MC/DC0%0/2
$self->{"name"} // basename($root)
$self->{"name"} basename($root)
Truth table33%1/3
A // B
A= $self->{"name"}B= basename($root)
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if @lines > 1 and $lines[-1] eq "" 46 0 46
Condition33%1/3
@lines > 1 and $lines[-1] eq ""
!ll&&!rl&&r
0046
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 ""
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($self->{'parser'} eq 'ppi') { } 12 34 46
138 12 my $doc = eval { PPI::Document->new($path) };
139 12 ▶ if ($doc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doc) { } 12 0 12
140 12 $doc->index_locations;
141 12 ▶ for my $p (@{$doc->find('PPI::Statement::Package') || []}) {
Condition100%2/2
$doc->find('PPI::Statement::Package') || []
l!l
111
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')
Aresult
11
00
142 12 my $name = $p->namespace;
143 12 my $at = $p->location;
144 12 ▶ next unless $name && $at;
Branch: 1 branch
BranchTrueFalseTotal
unless $name and $at 0 12 12
Condition33%1/3
$name and $at
!ll&&!rl&&r
0012
MC/DC0%0/2
$name and $at
$name $at
Truth table33%1/3
A and B
A= $nameB= $at
ABresult
0X0
100
111
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') || []
l!l
120
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')
Aresult
11
00
150 16 my $name = $s->name;
151 16 my $at = $s->location;
152 16 ▶ next unless $name && $at;
Branch: 1 branch
BranchTrueFalseTotal
unless $name and $at 0 16 16
Condition33%1/3
$name and $at
!ll&&!rl&&r
0016
MC/DC0%0/2
$name and $at
$name $at
Truth table33%1/3
A and B
A= $nameB= $at
ABresult
0X0
100
111
153 16 my $end = $at->[0];
154 16 my $block = $s->block;
155 16 ▶ if ($block) {
Branch: 1 branch
BranchTrueFalseTotal
if ($block) 16 0 16
156 16 my $last = $block->last_token;
157 16 ▶ my $finish = $last && $last->location;
Condition33%1/3
$last && $last->location
!ll&&!rl&&r
0016
MC/DC0%0/2
$last && $last->location
$last $last->location
Truth table33%1/3
A && B
A= $lastB= $last->location
ABresult
0X0
100
111
158 16 ▶ $end = $finish->[0] if $finish && $finish->[0] > $end;
Branch: 1 branch
BranchTrueFalseTotal
if $finish and $finish->[0] > $end 14 2 16
Condition66%2/3
$finish and $finish->[0] > $end
!ll&&!rl&&r
0214
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
ABresult
0X0
100
111
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') || []
l!l
120
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')
Aresult
11
00
164 43 ▶ next if ($s->type // '') eq 'no';
Branch: 1 branch
BranchTrueFalseTotal
if ($s->type // "") eq "no" 0 43 43
Condition50%1/2
$s->type // ""
l!l
430
MC/DC0%0/1
$s->type // ""
$s->type
Truth table50%1/2
A
A= $s->type
Aresult
11
00
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
BranchTrueFalseTotal
unless $at and $name and $name =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/u 0 43 43
Condition33%2/6
$at and $name and $name =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/u
!ll&&!rl&&r
0043
$at and $name
!ll&&!rl&&r
0043
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
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
unless $lite[$i] =~ /^\s*package\s+([A-Za-z_]\w*(?:::\w+)*)\b/u 366 49 415
181 49 my $name = $1;
182 49 ▶ next if $self->{parser} eq 'ppi' && grep { $_->{name} eq $name && $_->{line} == $i+1 } @scopes;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"parser"} eq "ppi" and grep {$_->{"name"} eq $name and $_->{"line"} == $i + 1;} @scopes 12 37 49
Condition66%4/6
$self->{"parser"} eq "ppi" and grep {$_->{"name"} eq $name and $_->{"line"} == $i + 1;} @scopes
!ll&&!rl&&r
37012
$_->{'name'} eq $name && $_->{'line'} == $i + 1
!ll&&!rl&&r
2012
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
ABresult
0X0
100
111
Truth table66%2/3
A && B
A= $_->{'name'} eq $nameB= $_->{'line'} == $i + 1
ABresult
0X0
100
111
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"} // ""
l!l
109109
$_->{"kind"} // ""
l!l
60158
$_->{"targets"} // []
l!l
109109
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"}
Aresult
11
00
Truth table100%2/2
A
A= $_->{"kind"}
Aresult
11
00
Truth table100%2/2
A
A= $_->{"targets"}
Aresult
11
00
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
BranchTrueFalseTotal
if ($rel =~ m[(?:^|/)lib/(.+)\.pm\z]u or $rel =~ /\A(.+)\.pm\z/u) 43 3 46
Condition66%2/3
$rel =~ m[(?:^|/)lib/(.+)\.pm\z]u or $rel =~ /\A(.+)\.pm\z/u
l!l&&r!l&&!r
4303
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if $name =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/u 43 0 43
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
BranchTrueFalseTotal
if $p->{"line"} > $line 7 164 171
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
BranchTrueFalseTotal
if ($ended) 0 415 415
224 415 ▶ if (@heredocs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@heredocs) 6 409 415
225 6 push @out, '';
226 6 ▶ shift @heredocs if $raw =~ /^\Q$heredocs[0]\E\s*;?\s*\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $raw =~ /^\Q$heredocs[0]\E\s*;?\s*\z/u 3 3 6
227 6 next;
228 }
229 409 ▶ if ($pod) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pod) 6 403 409
230 6 ▶ $pod = 0 if $raw =~ /^=cut\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $raw =~ /^=cut\b/u 3 3 6
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
BranchTrueFalseTotal
if ($raw =~ /^=(?:pod|head\d|begin|for|item|over|back|encoding)\b/u) 3 400 403
235 3 $pod = 1; push @out, ''; next;
236 }
237 0 ▶ if ($raw =~ /^__(?:DATA|END)__\b/) { $ended = 1; push @out, ''; next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($raw =~ /^__(?:DATA|END)__\b/u) 0 400 400
238 400 my ($out, $quote) = ('','');
239 400 my @chars = split //, $raw;
240 400 ▶ for (my $i=0; $i<@chars; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @chars) 5226 366 5592
241 5226 my $char = $chars[$i];
242 5226 ▶ if ($quote) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote) 291 4935 5226
243 291 ▶ if ($char eq '\\') { $out .= ' '; $i++ if $i+1<@chars; next; }
Branch: 2 branches
BranchTrueFalseTotal
if ($char eq "\\") 2 289 291
if $i + 1 < @chars 2 0 2
244 289 ▶ $quote = '' if $char eq $quote;
Branch: 1 branch
BranchTrueFalseTotal
if $char eq $quote 28 261 289
245 289 $out .= ' '; next;
246 }
247 4935 ▶ last if $char eq '#';
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "#" 34 4901 4935
248 4901 ▶ if ($char eq "'" || $char eq '"' || $char eq '`') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "'" or $char eq "\"" or $char eq "`") 28 4873 4901
Condition83%5/6
$char eq "'" or $char eq "\"" or $char eq "`"
l!l&&r!l&&!r
2804873
$char eq "'" or $char eq "\""
l!l&&r!l&&!r
2444873
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 "`"
ABCresult
1XX1
01X1
0011
0000
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
BranchTrueFalseTotal
if ($out =~ /<<\s*([A-Za-z_]\w*)/gu) 3 400 403
255 0 ▶ while ($raw =~ /<<\s*['"]([A-Za-z_]\w*)['"]/g) { push @heredocs, $1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($raw =~ /<<\s*['"]([A-Za-z_]\w*)['"]/gu) 0 400 400
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
BranchTrueFalseTotal
if $i > $start + 30 0 44 44
264 44 my $offset = index($lines->[$i],'{');
265 44 ▶ if ($offset >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset >= 0) 44 0 44
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
BranchTrueFalseTotal
$j == $i ? : 44 42 86
if ($c < length $line) 1036 42 1078
270 1036 my $ch = substr($line,$c,1);
271 1036 ▶ $depth++ if $ch eq '{';
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq "{" 48 988 1036
272 1036 ▶ $depth-- if $ch eq '}';
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq "}" 48 988 1036
273 1036 ▶ return $j-$start+1 if $depth == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $depth == 0 44 992 1036
274 }
275 }
276 0 return 1;
277 }
278 0 ▶ return 1 if $lines->[$i] =~ /;/;
Branch: 1 branch
BranchTrueFalseTotal
if $lines->[$i] =~ /;/u 0 0 0
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
BranchTrueFalseTotal
if ($s =~ /^\s*(?:(?:my|our|state)\s+)?sub\s+([A-Za-z_]\w*(?:::\w+)*)\b/u) 41 226 267
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
BranchTrueFalseTotal
if ($s =~ /^\s*(?:use|require)\s+([A-Za-z_]\w*(?:::\w+)*)\b/u) 55 212 267
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
BranchTrueFalseTotal
if ($s =~ /^\s*method\s+([A-Za-z_]\w*)\b/u) 3 412 415
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
BranchTrueFalseTotal
unless $s =~ /^\s*(?:extends|with|use\s+(?:parent|base))\b/u 404 11 415
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
BranchTrueFalseTotal
if ($part =~ m"^qw\s*([\(\[\{</!#|])"u) { } 0 11 11
313 0 my $open=$1; my %close=('('=>')','['=>']','{'=>'}','<'=>'>');
314 0 ▶ my $end=$close{$open}//$open;
Condition0%0/3
$close{$open} // $open
l!l&&r!l&&!r
000
MC/DC0%0/2
$close{$open} // $open
$close{$open} $open
Truth table0%0/3
A // B
A= $close{$open}B= $open
ABresult
1X1
011
000
315 0 ▶ if ($part =~ /\Q$open\E(.*?)\Q$end\E/) { @names=split /\s+/, $1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($part =~ /\Q$open\E(.*?)\Q$end\E/u) 0 0 0
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
BranchTrueFalseTotal
if @names 11 0 11
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
BranchTrueFalseTotal
if ($i >= 0) 97 44 141
329 97 ▶ last unless $lines->[$i] =~ /^\s*#\s?(.*?)\s*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $lines->[$i] =~ /^\s*#\s?(.*?)\s*\z/u 65 32 97
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
BranchTrueFalseTotal
length $joined > 180 ? : 0 109 109
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"}
l!l&&r!l&&!r
200
MC/DC0%0/2
$dir // $self->{"root"}
$dir $self->{"root"}
Truth table33%1/3
A // B
A= $dirB= $self->{"root"}
ABresult
1X1
011
000
343 2 ▶ die "Source directory does not exist\n" unless $root && -d $root;
Branch: 1 branch
BranchTrueFalseTotal
unless $root and -d $root 0 2 2
Condition33%1/3
$root and -d $root
!ll&&!rl&&r
002
MC/DC0%0/2
$root and -d $root
$root -d $root
Truth table33%1/3
A and B
A= $rootB= -d $root
ABresult
0X0
100
111
344 13 my %paths=map { $_->{path} => 1 }
345 2 ▶ map { @{$_->{files} || []} } @{$data->{pkgs} || []};
Condition50%2/4
$_->{'files'} || []
l!l
90
$data->{'pkgs'} || []
l!l
20
MC/DC0%0/1
$_->{'files'} || []
$_->{'files'}
MC/DC0%0/1
$data->{'pkgs'} || []
$data->{'pkgs'}
Truth table50%1/2
A
A= $_->{'files'}
Aresult
11
00
Truth table50%1/2
A
A= $data->{'pkgs'}
Aresult
11
00
346 2 ▶ $data->{sources} ||= {};
Condition50%1/2
$data->{"sources"} ||= {}
l!l
20
MC/DC0%0/1
$data->{"sources"} ||= {}
$data->{"sources"}
Truth table50%1/2
A
A= $data->{"sources"}
Aresult
11
00
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
BranchTrueFalseTotal
if $rel =~ /\0|\\/u or $rel =~ m[\A/]u or $rel =~ m[(?:\A|/)\.\.(?:/|\z)]u 3 9 12
Condition83%5/6
$rel =~ /\0|\\/u or $rel =~ m[\A/]u or $rel =~ m[(?:\A|/)\.\.(?:/|\z)]u
l!l&&r!l&&!r
129
$rel =~ /\0|\\/u or $rel =~ m[\A/]u
l!l&&r!l&&!r
0111
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
ABCresult
1XX1
01X1
0011
0000
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
BranchTrueFalseTotal
unless -f $path and not -l $path and -s $path <= $self->{"max_source_bytes"} 1 8 9
Condition66%4/6
-f $path and not -l $path and -s $path <= $self->{"max_source_bytes"}
!ll&&!rl&&r
108
-f $path and not -l $path
!ll&&!rl&&r
018
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"}
ABCresult
0XX0
10X0
1100
1111
352 8 my $real=abs_path($path);
353 8 ▶ next unless $real && index($real,"$root/")==0;
Branch: 1 branch
BranchTrueFalseTotal
unless $real and index($real, "$root/") == 0 0 8 8
Condition33%1/3
$real and index($real, "$root/") == 0
!ll&&!rl&&r
008
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
ABresult
0X0
100
111
354 8 ▶ open my $fh,'<:raw',$path or next;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $path or next 8 0 8
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
BranchTrueFalseTotal
unless $pid 0 5 5
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
BranchTrueFalseTotal
if $? 5 0 5
376 0 ▶ $value //= '';
Condition0%0/2
$value //= ""
l!l
00
MC/DC0%0/1
$value //= ""
$value
Truth table0%0/2
A
A= $value
Aresult
11
00
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
BranchTrueFalseTotal
if defined $self->{"source_base"} 0 5 5
384 5 ▶ my $rev=_capture('git','-C',$self->{root},'rev-parse','HEAD')//'';
Condition50%1/2
_capture("git", "-C", $self->{"root"}, "rev-parse", "HEAD") // ""
l!l
05
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")
Aresult
11
00
385 5 ▶ return ('','') unless $rev =~ /^[a-f0-9]{40}$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $rev =~ /^[a-f0-9]{40}$/u 5 0 5
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") // ""
l!l
00
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")
Aresult
11
00
387 0 my ($owner,$repo)=$remote =~ m{github\.com[:/]([^/\s:]+)/([^/\s]+?)(?:\.git)?\z};
388 0 ▶ return ('',$rev) unless defined $owner;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $owner 0 0 0
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") // ""
l!l
00
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")
Aresult
11
00
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"
l!l
30
MC/DC0%0/1
$opts{"output"} // "perl-code-map.html"
$opts{"output"}
Truth table50%1/2
A
A= $opts{"output"}
Aresult
11
00
396 3 ▶ die "Expected data with pkgs array\n" unless ref($data) eq 'HASH' && ref($data->{pkgs}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" and ref $data->{"pkgs"} eq "ARRAY" 0 3 3
Condition33%1/3
ref $data eq "HASH" and ref $data->{"pkgs"} eq "ARRAY"
!ll&&!rl&&r
003
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($opts{"json"}) 2 1 3
400 2 ▶ open my $fh,'>:raw',$opts{json} or die "Cannot write $opts{json}: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:raw", $opts{"json"} or die qq[Cannot write $opts{"json"}: $!\n] 2 0 2
401 2 print {$fh} $json;
402 2 ▶ close $fh or die "Cannot close $opts{json}: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die qq[Cannot close $opts{"json"}: $!\n] 2 0 2
403 }
404 3 ▶ my $module_file=$INC{'Perl/CodeMap.pm'} // __FILE__;
Condition50%1/2
$INC{"Perl/CodeMap.pm"} // __FILE__
l!l
30
MC/DC0%0/1
$INC{"Perl/CodeMap.pm"} // __FILE__
$INC{"Perl/CodeMap.pm"}
Truth table50%1/2
A
A= $INC{"Perl/CodeMap.pm"}
Aresult
11
00
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
BranchTrueFalseTotal
open my $fh, "<:raw", "File::Spec"->catfile($assets, $name) or die "Missing packaged report asset '${name}' ($!)\n" 15 0 15
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"
l!l
30
MC/DC0%0/1
$data->{"name"} // "Perl"
$data->{"name"}
Truth table50%1/2
A
A= $data->{"name"}
Aresult
11
00
414 3 $title =~ s/&/&amp;/g;
415 3 $title =~ s/</&lt;/g;
416 3 $title =~ s/>/&gt;/g;
417 3 $title =~ s/"/&quot;/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
BranchTrueFalseTotal
open my $fh, ">:raw", $output or die "Cannot write ${output}: $!\n" 3 0 3
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
BranchTrueFalseTotal
close $fh or die "Cannot close ${output}: $!\n" 3 0 3
429 3 return $output;
430 }
431  
432 12 1;
433  
434 __END__
↑ Summary bin/perl-codemap »