line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package lib::gitroot; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.003'; # VERSION |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
103460
|
use Modern::Perl; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
17
|
|
6
|
3
|
|
|
3
|
|
316
|
use File::Spec; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
60
|
|
7
|
3
|
|
|
3
|
|
2548
|
use lib (); |
|
3
|
|
|
|
|
2155
|
|
|
3
|
|
|
|
|
949
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $_GIT_ROOT = undef; |
10
|
|
|
|
|
|
|
|
11
|
7
|
|
|
7
|
0
|
43
|
sub GIT_ROOT { $_GIT_ROOT }; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %_default_values = ( lib => 'lib' ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# :set_root |
16
|
|
|
|
|
|
|
# :lib (implies :set_root, same as lib => 'lib') |
17
|
|
|
|
|
|
|
# lib => library path |
18
|
|
|
|
|
|
|
# use_base_dir => 'somedir_or_filename' |
19
|
|
|
|
|
|
|
sub import |
20
|
|
|
|
|
|
|
{ |
21
|
9
|
100
|
100
|
9
|
|
28203
|
my ($class, %args) = map { /^:(.*)$/ ? ($1 => $_default_values{$1} || 1) : $_ } @_; |
|
23
|
|
|
|
|
117
|
|
22
|
9
|
100
|
|
|
|
35
|
$args{set_root} = 1 if defined $args{lib}; |
23
|
|
|
|
|
|
|
|
24
|
9
|
|
|
|
|
23
|
my ($module, $filename) = caller; |
25
|
9
|
100
|
|
|
|
27
|
$filename = $args{use_base_dir} if defined $args{use_base_dir}; |
26
|
|
|
|
|
|
|
|
27
|
9
|
50
|
|
|
|
20
|
if ($args{set_root}) { |
28
|
|
|
|
|
|
|
|
29
|
9
|
100
|
|
|
|
15
|
if (defined $_GIT_ROOT) { |
30
|
3
|
100
|
|
|
|
30
|
die "Git Root already set" unless $args{once}; |
31
|
|
|
|
|
|
|
} else { |
32
|
6
|
|
33
|
|
|
14
|
$filename //= $args{path}; |
33
|
6
|
|
|
|
|
23
|
my $absfilename = File::Spec->rel2abs($filename); |
34
|
6
|
|
|
|
|
1414
|
$_GIT_ROOT = _find_git_dir( $absfilename, _is_dir($filename) ); |
35
|
6
|
100
|
66
|
|
|
17758
|
lib->import($_GIT_ROOT.'/'.$args{lib}) if defined $args{lib} and defined $_GIT_ROOT; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
3
|
|
|
3
|
|
17
|
no strict 'refs'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
83
|
|
41
|
3
|
|
|
3
|
|
13
|
no warnings 'redefine'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
869
|
|
42
|
7
|
|
|
|
|
4959
|
*{"$module\::GIT_ROOT"} = \&GIT_ROOT; |
|
7
|
|
|
|
|
43
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _is_dir |
46
|
|
|
|
|
|
|
{ |
47
|
0
|
|
|
0
|
|
0
|
-d shift(); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _find_git_dir |
51
|
|
|
|
|
|
|
{ |
52
|
16
|
|
|
16
|
|
14230
|
my ($abspath, $is_dir) = @_; |
53
|
16
|
|
|
|
|
128
|
my @dirs = File::Spec->splitdir ( $abspath ); |
54
|
16
|
100
|
|
|
|
39
|
pop @dirs unless $is_dir; |
55
|
16
|
|
|
|
|
37
|
while (@dirs) { |
56
|
37
|
|
|
|
|
249
|
my $gitdir = File::Spec->catdir(@dirs, '.git'); |
57
|
37
|
100
|
|
|
|
96
|
if (_is_dir($gitdir)) { |
58
|
12
|
|
|
|
|
4201
|
return File::Spec->catdir(@dirs); |
59
|
|
|
|
|
|
|
} |
60
|
25
|
|
|
|
|
8775
|
pop @dirs; |
61
|
|
|
|
|
|
|
} |
62
|
4
|
|
|
|
|
15
|
return; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |