scripts/libdir.pl

filter: Statementstmt 82.6% 43 / 52 Branchbran 41.1% 14 / 34 Conditioncond 50.0% 7 / 14 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 63.4% 73 / 115 CC 7 SCAR 25.5
CC
7
Cov
64%
__ANON__
26.1
untaint_any
2.1
BEGIN
1.0
CRAP 12.8
« t/t_lib.pl ↑ Summary blib/lib/YATT/Lite/Types.pm »
1 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 14 my @dir = do {
7 14 ▶ if ($ENV{DEBUG_INC}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"DEBUG_INC"}) 0 14 14
8 0 print STDERR "\$0=$0, rel2abs->", File::Spec->rel2abs($0), "\n";
9 }
10 14 ▶ my @d = (
Branch: 1 branch
BranchTrueFalseTotal
-r $0 && -l $0 ? : 0 14 14
Condition33%1/3
-r $0 and -l $0
!ll&&!rl&&r
0140
MC/DC0%0/2
-r $0 and -l $0
-r $0 -l $0
Truth table33%1/3
A and B
A= -r $0B= -l $0
ABresult
0X0
100
111
11 $_[0],
12 dirname(File::Spec->rel2abs($0)),
13 (-r $0 and -l $0) ? (
14 dirname(File::Spec->rel2abs(readlink($0), dirname($0))),
15 ) : (),
16 $FindBin::Bin,
17 $FindBin::Bin, # Just to avoid warning.
18 );
19 0 ▶ Carp::cluck("d=".join(", ", map {$_ // 'undef'} @d)) if $ENV{DEBUG_INC};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DEBUG_INC"} 0 14 14
Condition0%0/2
$_ // "undef"
l!l
00
MC/DC0%0/1
$_ // "undef"
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
20 14 my %dup;
21 14 ▶ map {defined $_ && -d $_ && !$dup{$_}++ ? untaint_any($_) : ()} @d;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && -d $_ && !$dup{$_}++ ? : 25 31 56
Condition83%5/6
defined $_ and -d $_ and not $dup{$_}++
!ll&&!rl&&r
141725
defined $_ and -d $_
!ll&&!rl&&r
14042
MC/DC66%2/3
defined $_ and -d $_ and not $dup{$_}++
defined $_ -d $_ not $dup{$_}++
Truth table75%3/4
A and B and not(C)
A= defined $_B= -d $_C= not $dup{$_}++
ABCresult
0XX0
10X0
1100
1111
22 };
23  
24 14 ▶unless (@dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@dir) 0 14 14
25 0 Carp::croak("Can't find bindir!");
26 }
27  
28 14 ▶Carp::cluck("dir=@dir\n") if $ENV{DEBUG_INC};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DEBUG_INC"} 0 14 14
29  
30 31 ▶sub untaint_any {$_[0] =~ m{(.*)} and $1}
Subroutine untaint_any: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /(.*)/ and $1 31 0 31
31 14 ▶use base qw/File::Spec/;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 14 my (@libdir, @blib);
34  
35 #
36 # The checkout is a directory named YATT with this scripts/ directly in
37 # it; only then is its parent a library root for YATT::Lite. A YATT
38 # directory further up is a different checkout (e.g. the one around a
39 # `./Build disttest` dir) and must not be mixed in (GH-301).
40 # Source roots go before blib/lib, so that a stale blib/ left in the
41 # checkout by ./Build is never preferred over the source (t/t_lib.pl
42 # orders them the same way).
43 #
44 14 foreach my $dir (@dir) {
45 25 my @d = File::Spec->splitdir($dir);
46 25 ▶ if (@d >= 2 and $d[-2] eq 'YATT') {
Branch: 1 branch
BranchTrueFalseTotal
if (@d >= 2 and $d[-2] eq "YATT") 0 25 25
Condition33%1/3
@d >= 2 and $d[-2] eq "YATT"
!ll&&!rl&&r
0250
MC/DC0%0/2
@d >= 2 and $d[-2] eq "YATT"
@d >= 2 $d[-2] eq "YATT"
Truth table33%1/3
A and B
A= @d >= 2B= $d[-2] eq "YATT"
ABresult
0X0
100
111
47 0 push @libdir, dirname(dirname($dir));
48 }
49  
50 25 ▶ if (-d (my $d = "$dir/../blib/lib")."/YATT") {
Branch: 1 branch
BranchTrueFalseTotal
if (-d (my $d = "$dir/../blib/lib") . '/YATT') 25 0 25
51 25 push @blib, $d;
52 }
53 }
54 14 push @libdir, @blib;
55  
56 972 ▶my $hook = sub {
Subroutine __ANON__: called CC=6 SCAR=32.6
57 972 my ($this, $orig_modfn) = @_;
58 972 ▶ return unless (my $modfn = $orig_modfn) =~ s!^YATT/!!;
Branch: 1 branch
BranchTrueFalseTotal
unless (my $modfn = $orig_modfn) =~ s[^YATT/][] 972 0 972
59 0 ▶ Carp::cluck("orig_modfn=$orig_modfn\n") if $ENV{DEBUG_INC};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DEBUG_INC"} 0 0 0
60 0 ▶ return unless -r (my $realfn = "$dir[0]/../$modfn");
Branch: 1 branch
BranchTrueFalseTotal
unless -r (my $realfn = "$dir[0]/../$modfn") 0 0 0
61 0 ▶ warn "=> found $realfn" if $ENV{DEBUG_INC};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DEBUG_INC"} 0 0 0
62 0 ▶ open my $fh, '<', $realfn or die "Can't open $realfn:$!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $realfn or die "Can't open ${realfn}:$!" 0 0 0
63 0 $fh;
64 14 };
65  
66 14 unshift @INC, $hook;
67  
68 14 ▶my $ins = $INC[$#INC] eq "." ? $#INC : @INC;
Branch: 1 branch
BranchTrueFalseTotal
$INC[$#INC] eq '.' ? : 14 0 14
69 14 splice @INC, $ins, 0, $hook, $hook;
70 # XXX: Why I need to put this into @INC-hook 3times?!
71  
72 14 require lib;
73  
74 14 ▶if (@libdir) {
Branch: 1 branch
BranchTrueFalseTotal
if (@libdir) 14 0 14
75 14 import lib @libdir;
76  
77 14 ▶ print STDERR join("\n", @libdir), "\n" if $ENV{DEBUG_INC};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DEBUG_INC"} 0 14 14
78 }
79  
80 # Should returns $dist_root
81  
82 14 return "$dir[0]/..";
« t/t_lib.pl ↑ Summary blib/lib/YATT/Lite/Types.pm »