line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Unix::MyPathToInc; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Paper over the general silliness that I've run into in a few odd |
4
|
|
|
|
|
|
|
# cases where you're insane enough to say "please add the place this |
5
|
|
|
|
|
|
|
# executable can be found in to the language's library search path". |
6
|
|
|
|
|
|
|
# As such, this is a special case module: you shouldn't be using it if |
7
|
|
|
|
|
|
|
# you can't figure out how the words "race condition" could apply. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# $Id: MyPathToInc.pm,v 1.1 2005/09/14 00:46:06 hag Exp $ |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
2386
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
12
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
46
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = "0.1"; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#### |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
5
|
use File::Spec; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
26
|
|
19
|
1
|
|
|
1
|
|
12
|
use File::Basename qw(dirname); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
516
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#### |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# XXX import time interface doesn't exactly leave a lot of room for |
24
|
|
|
|
|
|
|
# minor twiddles in the general idea. Reserve all :foo? |
25
|
|
|
|
|
|
|
sub import { |
26
|
6
|
|
|
6
|
|
841
|
my $type = shift; |
27
|
|
|
|
|
|
|
|
28
|
6
|
100
|
|
|
|
18
|
if(@_ == 0) { |
29
|
4
|
|
|
|
|
6
|
add_include(); |
30
|
|
|
|
|
|
|
} else { |
31
|
2
|
|
|
|
|
7
|
map { add_include($_); } @_; |
|
2
|
|
|
|
|
7
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub add_include { |
36
|
6
|
|
|
6
|
0
|
9
|
my $path = shift; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $out_path = sub { |
39
|
|
|
|
|
|
|
# Not the best way of doing this, but prolly good enough. |
40
|
6
|
100
|
|
6
|
|
13
|
if(defined($path)) { |
41
|
2
|
|
|
|
|
5782
|
return($_[0] . "/$path"); |
42
|
|
|
|
|
|
|
} else { |
43
|
4
|
|
|
|
|
11
|
return($_[0]); |
44
|
|
|
|
|
|
|
} |
45
|
6
|
|
|
|
|
27
|
}; |
46
|
|
|
|
|
|
|
|
47
|
6
|
50
|
|
|
|
23
|
die "No hope of converting a -e script to a location for includes" |
48
|
|
|
|
|
|
|
if($0 eq "-e"); |
49
|
|
|
|
|
|
|
|
50
|
6
|
50
|
|
|
|
19
|
if($0 =~ m,^/,) { |
51
|
|
|
|
|
|
|
# Beyond just being the obvious fully qualified path case, |
52
|
|
|
|
|
|
|
# this appears to cover a common perl DWIM, where perl seems |
53
|
|
|
|
|
|
|
# to search PATH for us. POSIX makes no such promise about |
54
|
|
|
|
|
|
|
# argv[0]. |
55
|
0
|
|
|
|
|
0
|
unshift(@INC, &{$out_path}(dirname($0))); |
|
0
|
|
|
|
|
0
|
|
56
|
0
|
|
|
|
|
0
|
return; |
57
|
|
|
|
|
|
|
} |
58
|
6
|
100
|
|
|
|
17
|
if($0 =~ m,/,) { |
59
|
1
|
|
|
|
|
264
|
unshift(@INC, &{$out_path}(File::Spec->rel2abs(dirname($0)))); |
|
1
|
|
|
|
|
11
|
|
60
|
1
|
|
|
|
|
7
|
return; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Blech. Always searching . is nominally reasonable in this case. |
64
|
|
|
|
|
|
|
# I'd prefer to only do it when I knew I had no choice, but there |
65
|
|
|
|
|
|
|
# is no such knowledge. |
66
|
5
|
|
|
|
|
32
|
foreach my $p (split(":", $ENV{PATH}), ".") { |
67
|
40
|
100
|
|
|
|
678
|
if( -x "$p/$0" ) { |
68
|
5
|
|
|
|
|
173
|
unshift(@INC, &{$out_path}(File::Spec->rel2abs($p))); |
|
5
|
|
|
|
|
12
|
|
69
|
5
|
|
|
|
|
11575
|
return; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# The most obvious way to get here is to run a script via perl |
74
|
|
|
|
|
|
|
# foo.pl or some such, where foo.pl is not executable. |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
die "Failed to perform any work; perhaps this script isn't executable?"; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#### |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#### |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |