| 1 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | require Carp; | |||||||||||||||||||||||||||||||||||||||||
| 4 | sub MY () {__PACKAGE__} | ||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | require List::MoreUtils; | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | # $_[0] should be $dist_root/t, which is normally $FindBin::Bin. | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | my $dir = do { | |||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | my $d = $_[0] || $FindBin::Bin or die "bindir is empty!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$_[0] || $FindBin::Bin
MC/DC0%0/2
$_[0] || $FindBin::Bin
$_[0]
$FindBin::Bin
Truth table33%1/3
A || B
A= $_[0]B= $FindBin::Bin
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | $d //= $FindBin::Bin; # To suppress warning. | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$d //= $FindBin::Bin
MC/DC0%0/2
$d //= $FindBin::Bin
$d
$FindBin::Bin
Truth table33%1/3
A //= B
A= $dB= $FindBin::Bin
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | MY->rel2abs(untaint_any($d)); | |||||||||||||||||||||||||||||||||||||||||
| 13 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | ▶ | if (not -e "$FindBin::Bin/t_lib.pl" and not defined $_[0]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-e "$FindBin::Bin/t_lib.pl" or defined $_[0]
MC/DC0%0/2
-e "$FindBin::Bin/t_lib.pl" or defined $_[0]
-e "$FindBin::Bin/t_lib.pl"
defined $_[0]
Truth table33%1/3
A or B
A= -e "$FindBin::Bin/t_lib.pl"B= defined $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | print STDERR "# Subdirectory tests should set \@_ to t_lib.pl\n"; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | exit 1; | |||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 6 | ▶ | sub untaint_any {$_[0] =~ m{(.*)} and $1} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
untaint_any: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 6 | ▶ | use base qw/File::Spec/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | my (@libdir); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | # | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # When the checkout itself is a directory named YATT (with this t/ | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # directly in it), its parent is a library root for YATT::Lite. A YATT | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # directory further up is a different checkout: e.g. `./Build disttest` | ||||||||||||||||||||||||||||||||||||||||||
| 30 | # unpacks YATT-Lite-X.Y/ inside the checkout, and mixing that outer | ||||||||||||||||||||||||||||||||||||||||||
| 31 | # YATT::Lite into the dist's tests is exactly what GH-301 reports. | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # blib/lib and the @INC hook below cover the dist case. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # | ||||||||||||||||||||||||||||||||||||||||||
| 34 | my @d; | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 6 | foreach my $seg (MY->splitdir($dir)) { | |||||||||||||||||||||||||||||||||||||||||
| 36 | # Collapse "." and ".." lexically (callers pass things like | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # "$FindBin::Bin/../../../../t"); no realpath, symlinks stay as spelled. | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ($seg eq '.') { next } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 6 | ▶ | elsif ($seg eq '..' and @d > 1 and $d[-1] ne '..') { pop @d } | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$seg eq ".." and @d > 1 and $d[-1] ne ".."
$seg eq ".." and @d > 1
MC/DC33%1/3
$seg eq ".." and @d > 1 and $d[-1] ne ".."
$seg eq ".."
@d > 1
$d[-1] ne ".."
Truth table50%2/4
A and B and C
A= $seg eq ".."B= @d > 1C= $d[-1] ne ".."
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 48 | else { push @d, $seg } | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 42 | ▶ | my $p = List::MoreUtils::last_index(sub {$_ eq 'YATT'}, @d); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 6 | ▶ | if ($p >= 0 and $p < $#d and $d[$p+1] eq 't') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$p >= 0 and $p < $#d and $d[$p + 1] eq "t"
$p >= 0 and $p < $#d
MC/DC0%0/3
$p >= 0 and $p < $#d and $d[$p + 1] eq "t"
$p >= 0
$p < $#d
$d[$p + 1] eq "t"
Truth table25%1/4
A and B and C
A= $p >= 0B= $p < $#dC= $d[$p + 1] eq "t"
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my @outer_dir = @d[0 .. ($p-1)]; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | push @libdir, MY->catdir(@outer_dir); | |||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ($outer_dir[-1] eq 'lib' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$outer_dir[-1] eq "lib" and -d (my $local_lib = "YATT::Lite::Factory::Sandbox::S1"->catdir(@outer_dir[0 .. $#outer_dir - 1], ("local", "lib", "perl5")))
MC/DC0%0/2
$outer_dir[-1] eq "lib" and -d (my $local_lib = "YATT::Lite::Factory::Sandbox::S1"->catdir(@outer_dir[0 .. $#outer_dir - 1], ("local", "lib", "perl5")))
$outer_dir[-1] eq "lib"
-d (my $local_lib = "YATT::Lite::Factory::Sandbox::S1"->catdir(@outer_dir[0 .. $#outer_dir - 1], ("local", "lib", "perl5")))
Truth table0%0/3
A and B
A= $outer_dir[-1] eq "lib"B= -d (my $local_lib = "YATT::Lite::Factory::Sandbox::S1"->catdir(@outer_dir[0 .. $#outer_dir - 1], ("local", "lib", "perl5")))
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | and -d (my $local_lib = MY->catdir(@outer_dir[0..$#outer_dir-1], qw(local lib perl5)))) { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | push @libdir, $local_lib; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 6 | ▶ | if (-d (my $d = "$dir/../blib/lib")."/YATT") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 6 | push @libdir, $d; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 198 | ▶ | my $hook = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=32.6
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 198 | my ($this, $orig_modfn) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 198 | ▶ | return unless (my $modfn = $orig_modfn) =~ s!^YATT/!!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | Carp::cluck("orig_modfn=$orig_modfn, dir=$dir, modfn=$modfn\n") if $ENV{DEBUG_INC}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | return unless -r (my $realfn = "$dir/../$modfn"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | warn "=> found $realfn" if $ENV{DEBUG_INC}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | open my $fh, '<', $realfn or die "Can't open $realfn:$!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $fh; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 6 | unshift @INC, $hook; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 6 | ▶ | my $ins = $INC[$#INC] eq "." ? $#INC : @INC; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 6 | splice @INC, $ins, 0, $hook, $hook; | |||||||||||||||||||||||||||||||||||||||||
| 70 | # XXX: Why I need to put this into @INC-hook 3times?! | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 6 | require lib; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 6 | ▶ | if (@libdir) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 6 | import lib @libdir; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 6 | ▶ | print STDERR join("\n", @libdir), "\n" if $ENV{DEBUG_INC}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | # Should returns $dist_root | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 6 | return "$dir/.."; | |||||||||||||||||||||||||||||||||||||||||