Install/Deps.pm

filter: Statementstmt 68.1% 60 / 88 Branchbran 27.5% 11 / 40 Conditioncond 20.0% 2 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 4 totaltotal 51.9% 82 / 158 CC 31 SCAR 37.6
CC
31
Cov
53%
_find_header_deps
111.2
getfile
12.0
find_header_deps
9.0
CRAP 43.1
« Install/Util.pm ↑ Summary Install/FrozenShit/Typemaps.pm »
1 package
2 XS::Install::Deps;
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Cwd 'abs_path';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 31 ▶sub find_header_deps {
Subroutine find_header_deps: called CC=8 SCAR=22.0
Pod undocumented
9 31 my $p = shift;
10 31 ▶ my $headers = [ grep {$_} map { abs_path($_) } @{$p->{headers} || []} ];
Condition50%1/2
$p->{'headers'} || []
l!l
310
MC/DC0%0/1
$p->{'headers'} || []
$p->{'headers'}
Truth table50%1/2
A
A= $p->{'headers'}
Aresult
11
00
11 0 ▶ my $inc = [ grep {$_} map { abs_path($_) } @{$p->{inc} || []} ];
Condition50%1/2
$p->{'inc'} || []
l!l
310
MC/DC0%0/1
$p->{'inc'} || []
$p->{'inc'}
Truth table50%1/2
A
A= $p->{'inc'}
Aresult
11
00
12 31 my $cache = {};
13 31 ▶ $headers = undef unless @$headers;
Branch: 1 branch
BranchTrueFalseTotal
unless @$headers 0 31 31
14
15 31 my %ret;
16 31 foreach my $file (@{$p->{files}}) {
17 179 ▶ my $absfile = eval { abs_path($file) } or next;
Branch: 1 branch
BranchTrueFalseTotal
my $absfile = eval { do { abs_path($file) } } or next 179 0 179
18 179 ▶ next unless -f $absfile;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $absfile 0 179 179
19 179 ▶ my $deps = _find_header_deps($absfile, $cache, $inc, $headers) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $deps = _find_header_deps($absfile, $cache, $inc, $headers) or next 179 0 179
20 179 $ret{$file} = [keys %$deps];
21 }
22
23 31 return \%ret;
24 }
25  
26 179 ▶sub _find_header_deps {
Subroutine _find_header_deps: called CC=14 SCAR=47.1
27 179 my ($file, $cache, $inc, $headers) = @_;
28 179 ▶ return $cache->{$file} if exists $cache->{$file};
Branch: 1 branch
BranchTrueFalseTotal
if exists $cache->{$file} 0 179 179
29
30 179 my $deps = $cache->{$file} = {};
31 179 my $content = readfile($file);
32 179 my $dir = $file;
33 179 $dir =~ s#[^/\\]+$##;
34
35 179 ▶ while ($content =~ /^\s*#\s*include\s*("|<)([^">]+)(?:"|>)/mg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /^\s*#\s*include\s*("|<)([^">]+)(?:"|>)/gm) 0 179 179
36 0 my ($type, $dep) = ($1, $2);
37 0 my $absdep;
38 0 ▶ if ($type eq '"') { # try to find locally first
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "\"") 0 0 0
39 0 $absdep = getfile($dir.$dep);
40 }
41 0 ▶ unless ($absdep) { # try to find globally
Branch: 1 branch
BranchTrueFalseTotal
unless ($absdep) 0 0 0
42 0 foreach my $dir (@$inc) {
43 0 $absdep = getfile($dir.'/'.$dep);
44 0 ▶ last if $absdep;
Branch: 1 branch
BranchTrueFalseTotal
if $absdep 0 0 0
45 }
46 }
47 0 ▶ if ($absdep and $headers) { # if supplied, ignore everything that is outside of specified dirs
Branch: 1 branch
BranchTrueFalseTotal
if ($absdep and $headers) 0 0 0
Condition0%0/3
$absdep and $headers
!ll&&!rl&&r
000
MC/DC0%0/2
$absdep and $headers
$absdep $headers
Truth table0%0/3
A and B
A= $absdepB= $headers
ABresult
0X0
100
111
48 0 my $found;
49 0 foreach my $dir (@$headers) {
50 0 ▶ next unless index($absdep, $dir) == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless index($absdep, $dir) == 0 0 0 0
51 0 $found = 1;
52 0 last;
53 }
54 0 ▶ $absdep = undef unless $found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 0 0 0
55 }
56 0 ▶ next unless $absdep;
Branch: 1 branch
BranchTrueFalseTotal
unless $absdep 0 0 0
57
58 0 $deps->{File::Spec->abs2rel($absdep)}++;
59 0 my $subdeps = _find_header_deps($absdep, $cache, $inc, $headers);
60 0 $deps->{$_}++ for keys %$subdeps;
61 }
62
63 179 return $deps;
64 }
65  
66 77 ▶sub find_xsi_deps {
Subroutine find_xsi_deps: called CC=5 SCAR=16.6
Pod undocumented
67 77 my $files = shift;
68 77 my %ret;
69 77 foreach my $file (@$files) {
70 77 ▶ my $absfile = abs_path($file) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $absfile = abs_path($file) or next 77 0 77
71 77 ▶ next unless -f $absfile;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $absfile 0 77 77
72 77 ▶ my $deps = _find_xsi_deps($absfile) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $deps = _find_xsi_deps($absfile) or next 77 0 77
73 77 $ret{$file} = [keys %$deps];
74 }
75 77 return \%ret;
76 }
77  
78 77 ▶sub _find_xsi_deps {
Subroutine _find_xsi_deps: called CC=4 SCAR=17.3
79 77 my $file = shift;
80
81 77 my $content = readfile($file);
82 77 my $dir = $file;
83 77 $dir =~ s#[^/\\]+$##;
84  
85 77 my $deps = {};
86 77 ▶ while ($content =~ /^\s*INCLUDE\s*:\s*(.+)/mg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /^\s*INCLUDE\s*:\s*(.+)/gm) 0 77 77
87 0 ▶ my $xsi = getfile($dir.$1) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $xsi = getfile($dir . $1) or next 0 0 0
88 0 $deps->{File::Spec->abs2rel($xsi)}++;
89 0 my $subdeps = _find_xsi_deps($xsi);
90 0 $deps->{$_}++ for keys %$subdeps;
91 }
92
93 77 return $deps;
94 }
95  
96 0 ▶sub getfile {
Subroutine getfile: not called CC=3 SCAR=24.8
Pod undocumented
97 0 my $f = abs_path($_[0]);
98 0 ▶ return undef unless $f and -f $f;
Branch: 1 branch
BranchTrueFalseTotal
unless $f and -f $f 0 0 0
Condition0%0/3
$f and -f $f
!ll&&!rl&&r
000
MC/DC0%0/2
$f and -f $f
$f -f $f
Truth table0%0/3
A and B
A= $fB= -f $f
ABresult
0X0
100
111
99 0 return $f;
100 }
101  
102 256 ▶sub readfile {
Subroutine readfile: called CC=2 SCAR=7.0
Pod undocumented
103 256 my $file = shift;
104 256 ▶ open my $fh, '<', $file or die "cannot open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "cannot open ${file}: $!" 256 0 256
105 256 local $/ = undef;
106 256 my $content = <$fh>;
107 256 close $fh;
108 256 return $content;
109 }
110  
111 11 1;
« Install/Util.pm ↑ Summary Install/FrozenShit/Typemaps.pm »