line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package lib::projectroot; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: easier loading of a project's local libs |
4
|
|
|
|
|
|
|
our $VERSION = '1.010'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
294858
|
use strict; |
|
7
|
|
|
|
|
53
|
|
|
7
|
|
|
|
|
167
|
|
7
|
7
|
|
|
7
|
|
29
|
use warnings; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
145
|
|
8
|
7
|
|
|
7
|
|
131
|
use 5.010; |
|
7
|
|
|
|
|
18
|
|
9
|
|
|
|
|
|
|
|
10
|
7
|
|
|
7
|
|
2512
|
use FindBin qw(); |
|
7
|
|
|
|
|
6816
|
|
|
7
|
|
|
|
|
154
|
|
11
|
7
|
|
|
7
|
|
78
|
use Carp qw(carp); |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
263
|
|
12
|
7
|
|
|
7
|
|
34
|
use File::Spec::Functions qw(catdir splitdir); |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
227
|
|
13
|
7
|
|
|
7
|
|
3258
|
use local::lib qw(); |
|
7
|
|
|
|
|
36481
|
|
|
7
|
|
|
|
|
145
|
|
14
|
7
|
|
|
7
|
|
41
|
use lib qw(); |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
4041
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $ROOT; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub import { |
19
|
7
|
|
|
7
|
|
57
|
my $class = shift; |
20
|
7
|
|
|
|
|
26
|
my @libdirs; |
21
|
|
|
|
|
|
|
my @locallibs; |
22
|
7
|
|
|
|
|
0
|
my @extra; |
23
|
7
|
|
|
|
|
0
|
my @extra_with_local; |
24
|
7
|
|
|
|
|
19
|
foreach my $d (@_) { |
25
|
11
|
100
|
|
|
|
56
|
if ( $d =~ /^local::lib=([\S]+)/ ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
26
|
2
|
|
|
|
|
8
|
push( @libdirs, $1 ); |
27
|
2
|
|
|
|
|
4
|
push( @locallibs, $1 ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
elsif ( $d =~ /^extra=([\S]+)/ ) { |
30
|
1
|
|
|
|
|
7
|
@extra = split( /[,;]/, $1 ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
elsif ( $d =~ /^extra_with_local=([\S]+)/ ) { |
33
|
0
|
|
|
|
|
0
|
@extra_with_local = split( /[,;]/, $1 ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
8
|
|
|
|
|
22
|
push( @libdirs, $d ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
7
|
|
|
|
|
34
|
my @searchdirs = splitdir("$FindBin::Bin"); |
41
|
|
|
|
|
|
|
|
42
|
7
|
50
|
|
|
|
74
|
unless ($ROOT) { |
43
|
7
|
|
|
|
|
32
|
SEARCH: while (@searchdirs) { |
44
|
31
|
|
|
|
|
48
|
foreach my $dir (@libdirs) { |
45
|
38
|
100
|
|
|
|
702
|
unless ( -d catdir( @searchdirs, $dir ) ) { |
46
|
26
|
|
|
|
|
69
|
pop(@searchdirs); |
47
|
26
|
|
|
|
|
72
|
next SEARCH; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
5
|
|
|
|
|
25
|
$ROOT = catdir(@searchdirs); |
51
|
5
|
|
|
|
|
12
|
last SEARCH; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
7
|
100
|
|
|
|
19
|
if ($ROOT) { |
56
|
5
|
100
|
|
|
|
15
|
local::lib->import( map { catdir( $ROOT, $_ ) } @locallibs ) |
|
1
|
|
|
|
|
8
|
|
57
|
|
|
|
|
|
|
if @locallibs; |
58
|
5
|
50
|
|
|
|
1491
|
lib->import( map { catdir( $ROOT, $_ ) } @libdirs ) if @libdirs; |
|
6
|
|
|
|
|
50
|
|
59
|
5
|
100
|
|
|
|
599
|
__PACKAGE__->load_extra(@extra) if @extra; |
60
|
5
|
50
|
|
|
|
6219
|
__PACKAGE__->load_extra_with_local(@extra_with_local) |
61
|
|
|
|
|
|
|
if @extra_with_local; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
2
|
|
|
|
|
539
|
carp "Could not find root dir containing " . join( ', ', @libdirs ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub load_extra { |
69
|
2
|
|
|
2
|
0
|
75
|
my $class = shift; |
70
|
2
|
|
|
|
|
6
|
my @extras = @_; |
71
|
|
|
|
|
|
|
|
72
|
2
|
|
|
|
|
7
|
my @parts = splitdir($ROOT); |
73
|
2
|
|
|
|
|
14
|
pop(@parts); |
74
|
2
|
|
|
|
|
10
|
my $parent = catdir(@parts); |
75
|
|
|
|
|
|
|
|
76
|
2
|
|
|
|
|
5
|
foreach my $d (@extras) { |
77
|
2
|
|
|
|
|
8
|
my $extra = catdir( $parent, $d, 'lib' ); |
78
|
2
|
50
|
|
|
|
33
|
if ( -d $extra ) { |
79
|
2
|
|
|
|
|
12
|
push( @INC, $extra ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else { |
82
|
0
|
|
|
|
|
|
carp "Cannot load_extra $d, directory $extra does not exist"; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub load_extra_with_local { |
88
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
89
|
0
|
|
|
|
|
|
my @extras = @_; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my @parts = splitdir($ROOT); |
92
|
0
|
|
|
|
|
|
pop(@parts); |
93
|
0
|
|
|
|
|
|
my $parent = catdir(@parts); |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
foreach my $d (@extras) { |
96
|
0
|
|
|
|
|
|
my $extra = catdir( $parent, $d, 'lib' ); |
97
|
0
|
0
|
|
|
|
|
if ( -d $extra ) { |
98
|
0
|
|
|
|
|
|
push( @INC, $extra ); |
99
|
0
|
|
|
|
|
|
my $extra_local = catdir( $parent, $d, 'local' ); |
100
|
0
|
0
|
|
|
|
|
if ( -d $extra_local ) { |
101
|
0
|
|
|
|
|
|
local::lib->import($extra_local); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else { |
104
|
0
|
|
|
|
|
|
carp |
105
|
|
|
|
|
|
|
"Cannot load local::lib in extra $d, directory $extra_local does not exist"; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
else { |
110
|
0
|
|
|
|
|
|
carp "Cannot load_extra $d, directory $extra does not exist"; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
42; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
__END__ |