t/t_lib.pl

filter: Statementstmt 77.3% 41 / 53 Branchbran 37.5% 12 / 32 Conditioncond 37.5% 9 / 24 MC/DCmcdc 7.1% 1 / 14 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 53.8% 70 / 130 CC 7 SCAR 25.5
CC
7
Cov
57%
__ANON__
26.1
untaint_any
2.1
BEGIN
1.0
CRAP 12.8
« blib/lib/YATT/Lite/WebMVC0/DirApp.pm ↑ Summary scripts/libdir.pl »
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
BranchTrueFalseTotal
my $d = $_[0] || $FindBin::Bin or die "bindir is empty!" 6 0 6
Condition33%1/3
$_[0] || $FindBin::Bin
l!l&&r!l&&!r
600
MC/DC0%0/2
$_[0] || $FindBin::Bin
$_[0] $FindBin::Bin
Truth table33%1/3
A || B
A= $_[0]B= $FindBin::Bin
ABresult
1X1
011
000
11 6 ▶ $d //= $FindBin::Bin; # To suppress warning.
Condition33%1/3
$d //= $FindBin::Bin
l!l&&r!l&&!r
600
MC/DC0%0/2
$d //= $FindBin::Bin
$d $FindBin::Bin
Truth table33%1/3
A //= B
A= $dB= $FindBin::Bin
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless (-e "$FindBin::Bin/t_lib.pl" or defined $_[0]) 0 6 6
Condition33%1/3
-e "$FindBin::Bin/t_lib.pl" or defined $_[0]
l!l&&r!l&&!r
060
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]
ABresult
1X1
011
000
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
BranchTrueFalseTotal
$_[0] =~ /(.*)/ and $1 6 0 6
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
BranchTrueFalseTotal
if ($seg eq '.') { } 0 54 54
elsif ($seg eq '..' and @d > 1 and $d[-1] ne '..') { } 6 48 54
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 ".."
!ll&&!rl&&r
4806
$seg eq ".." and @d > 1
!ll&&!rl&&r
4806
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 ".."
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if ($p >= 0 and $p < $#d and $d[$p + 1] eq "t") 0 6 6
Condition33%2/6
$p >= 0 and $p < $#d and $d[$p + 1] eq "t"
!ll&&!rl&&r
600
$p >= 0 and $p < $#d
!ll&&!rl&&r
600
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"
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if ($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")))) 0 0 0
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")))
!ll&&!rl&&r
000
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")))
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (-d (my $d = "$dir/../blib/lib") . '/YATT') 6 0 6
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
BranchTrueFalseTotal
unless (my $modfn = $orig_modfn) =~ s[^YATT/][] 198 0 198
59 0 ▶ Carp::cluck("orig_modfn=$orig_modfn, dir=$dir, modfn=$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/../$modfn");
Branch: 1 branch
BranchTrueFalseTotal
unless -r (my $realfn = "$dir/../$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 6 };
65  
66 6 unshift @INC, $hook;
67  
68 6 ▶my $ins = $INC[$#INC] eq "." ? $#INC : @INC;
Branch: 1 branch
BranchTrueFalseTotal
$INC[$#INC] eq '.' ? : 0 6 6
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
BranchTrueFalseTotal
if (@libdir) 6 0 6
75 6 import lib @libdir;
76  
77 6 ▶ print STDERR join("\n", @libdir), "\n" if $ENV{DEBUG_INC};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DEBUG_INC"} 0 6 6
78 }
79  
80 # Should returns $dist_root
81  
82 6 return "$dir/..";
« blib/lib/YATT/Lite/WebMVC0/DirApp.pm ↑ Summary scripts/libdir.pl »