| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Dist::HomeDir; |
|
2
|
|
|
|
|
|
|
$Dist::HomeDir::VERSION = '0.006'; |
|
3
|
|
|
|
|
|
|
# ABSTRACT: easily find the distribution home directory for code never intended to be installed via a package manager |
|
4
|
2
|
|
|
2
|
|
16563
|
use warnings; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
61
|
|
|
5
|
2
|
|
|
2
|
|
8
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
39
|
|
|
6
|
2
|
|
|
2
|
|
1692
|
use Path::Tiny; |
|
|
2
|
|
|
|
|
33350
|
|
|
|
2
|
|
|
|
|
787
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my $home; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub import { |
|
11
|
4
|
|
|
4
|
|
14934
|
my ($pkg, %libs) = @_; |
|
12
|
4
|
|
|
|
|
6
|
my $libs = $libs{lib}; |
|
13
|
4
|
|
|
|
|
1321
|
require lib; |
|
14
|
4
|
|
|
|
|
1370
|
my $home = dist_home(); |
|
15
|
4
|
|
|
|
|
135
|
$_ = $home->child($_)->stringify for @$libs; |
|
16
|
4
|
|
|
|
|
106
|
lib->import(@$libs); |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub dist_home { |
|
20
|
6
|
100
|
|
6
|
0
|
701
|
return $home if $home; |
|
21
|
2
|
|
|
|
|
7
|
my $caller = [(caller)]; |
|
22
|
2
|
50
|
|
|
|
119
|
if ($caller->[0] eq 'Dist::HomeDir') { |
|
23
|
2
|
|
|
|
|
24
|
$caller = [caller(2)]; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
2
|
|
|
|
|
11
|
my $cwd = path($caller->[1])->parent; |
|
26
|
2
|
|
|
|
|
600
|
$home = _get_dist_home($cwd); |
|
27
|
2
|
|
|
|
|
10
|
return $home->absolute; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _get_dist_home { |
|
31
|
4
|
|
|
4
|
|
90
|
my ($dir) = @_; |
|
32
|
4
|
|
|
|
|
6
|
my @ls; |
|
33
|
4
|
|
|
|
|
12
|
my $itr = $dir->iterator; |
|
34
|
4
|
|
|
|
|
204
|
while (my $f = $itr->() ) { |
|
35
|
36
|
|
|
|
|
1507
|
push @ls, $f; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
4
|
100
|
|
|
|
108
|
if ( grep { $_->basename =~ /^Makefile.PL|Build.PL|dist.ini|cpanfile|lib|blib$/ |
|
|
36
|
100
|
|
|
|
1246
|
|
|
38
|
|
|
|
|
|
|
&& $_->parent->basename !~ /^t|script|bin$/ |
|
39
|
|
|
|
|
|
|
} @ls ) { |
|
40
|
2
|
|
|
|
|
169
|
return $dir; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
else { |
|
43
|
2
|
|
|
|
|
50
|
return _get_dist_home($dir->parent); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
1; |
|
47
|
|
|
|
|
|
|
__END__ |