line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#line 1 |
2
|
|
|
|
|
|
|
# FindBin.pm |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Copyright (c) 1995 Graham Barr & Nick Ing-Simmons. All rights reserved. |
5
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify it |
6
|
|
|
|
|
|
|
# under the same terms as Perl itself. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#line 92 |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package FindBin; |
11
|
|
|
|
|
|
|
use Carp; |
12
|
|
|
|
|
|
|
require 5.000; |
13
|
|
|
|
|
|
|
require Exporter; |
14
|
|
|
|
|
|
|
use Cwd qw(getcwd cwd abs_path); |
15
|
|
|
|
|
|
|
use File::Basename; |
16
|
|
|
|
|
|
|
use File::Spec; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
@EXPORT_OK = qw($Bin $Script $RealBin $RealScript $Dir $RealDir); |
19
|
|
|
|
|
|
|
%EXPORT_TAGS = (ALL => [qw($Bin $Script $RealBin $RealScript $Dir $RealDir)]); |
20
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$VERSION = "1.50"; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# needed for VMS-specific filename translation |
26
|
|
|
|
|
|
|
if( $^O eq 'VMS' ) { |
27
|
|
|
|
|
|
|
require VMS::Filespec; |
28
|
|
|
|
|
|
|
VMS::Filespec->import; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub cwd2 { |
32
|
|
|
|
|
|
|
my $cwd = getcwd(); |
33
|
|
|
|
|
|
|
# getcwd might fail if it hasn't access to the current directory. |
34
|
|
|
|
|
|
|
# try harder. |
35
|
|
|
|
|
|
|
defined $cwd or $cwd = cwd(); |
36
|
|
|
|
|
|
|
$cwd; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub init |
40
|
|
|
|
|
|
|
{ |
41
|
|
|
|
|
|
|
*Dir = \$Bin; |
42
|
|
|
|
|
|
|
*RealDir = \$RealBin; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
if($0 eq '-e' || $0 eq '-') |
45
|
|
|
|
|
|
|
{ |
46
|
|
|
|
|
|
|
# perl invoked with -e or script is on C |
47
|
|
|
|
|
|
|
$Script = $RealScript = $0; |
48
|
|
|
|
|
|
|
$Bin = $RealBin = cwd2(); |
49
|
|
|
|
|
|
|
$Bin = VMS::Filespec::unixify($Bin) if $^O eq 'VMS'; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else |
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
my $script = $0; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
if ($^O eq 'VMS') |
56
|
|
|
|
|
|
|
{ |
57
|
|
|
|
|
|
|
($Bin,$Script) = VMS::Filespec::rmsexpand($0) =~ /(.*[\]>\/]+)(.*)/s; |
58
|
|
|
|
|
|
|
# C |
59
|
|
|
|
|
|
|
($Bin = VMS::Filespec::unixify($Bin)) =~ s/\/\z//; |
60
|
|
|
|
|
|
|
($RealBin,$RealScript) = ($Bin,$Script); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else |
63
|
|
|
|
|
|
|
{ |
64
|
|
|
|
|
|
|
my $dosish = ($^O eq 'MSWin32' or $^O eq 'os2'); |
65
|
|
|
|
|
|
|
unless(($script =~ m#/# || ($dosish && $script =~ m#\\#)) |
66
|
|
|
|
|
|
|
&& -f $script) |
67
|
|
|
|
|
|
|
{ |
68
|
|
|
|
|
|
|
my $dir; |
69
|
|
|
|
|
|
|
foreach $dir (File::Spec->path) |
70
|
|
|
|
|
|
|
{ |
71
|
|
|
|
|
|
|
my $scr = File::Spec->catfile($dir, $script); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# $script can been found via PATH but perl could have |
74
|
|
|
|
|
|
|
# been invoked as 'perl file'. Do a dumb check to see |
75
|
|
|
|
|
|
|
# if $script is a perl program, if not then keep $script = $0 |
76
|
|
|
|
|
|
|
# |
77
|
|
|
|
|
|
|
# well we actually only check that it is an ASCII file |
78
|
|
|
|
|
|
|
# we know its executable so it is probably a script |
79
|
|
|
|
|
|
|
# of some sort. |
80
|
|
|
|
|
|
|
if(-f $scr && -r _ && ($dosish || -x _) && -s _ && -T _) |
81
|
|
|
|
|
|
|
{ |
82
|
|
|
|
|
|
|
$script = $scr; |
83
|
|
|
|
|
|
|
last; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
croak("Cannot find current script '$0'") unless(-f $script); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# Ensure $script contains the complete path in case we C |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$script = File::Spec->catfile(cwd2(), $script) |
93
|
|
|
|
|
|
|
unless File::Spec->file_name_is_absolute($script); |
94
|
2
|
|
|
2
|
|
1841
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
175
|
|
95
|
|
|
|
|
|
|
($Script,$Bin) = fileparse($script); |
96
|
|
|
|
|
|
|
|
97
|
2
|
|
|
2
|
|
85
|
# Resolve $script if it is a link |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
100
|
|
98
|
2
|
|
|
2
|
|
10
|
while(1) |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
167
|
|
99
|
2
|
|
|
2
|
|
11
|
{ |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1358
|
|
100
|
|
|
|
|
|
|
my $linktext = readlink($script); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
($RealScript,$RealBin) = fileparse($script); |
103
|
|
|
|
|
|
|
last unless defined $linktext; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$script = (File::Spec->file_name_is_absolute($linktext)) |
106
|
|
|
|
|
|
|
? $linktext |
107
|
|
|
|
|
|
|
: File::Spec->catfile($RealBin, $linktext); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# Get absolute paths to directories |
111
|
|
|
|
|
|
|
if ($Bin) { |
112
|
|
|
|
|
|
|
my $BinOld = $Bin; |
113
|
|
|
|
|
|
|
$Bin = abs_path($Bin); |
114
|
|
|
|
|
|
|
defined $Bin or $Bin = File::Spec->canonpath($BinOld); |
115
|
2
|
|
|
2
|
0
|
23
|
} |
116
|
|
|
|
|
|
|
$RealBin = abs_path($RealBin) if($RealBin); |
117
|
|
|
|
|
|
|
} |
118
|
2
|
50
|
|
|
|
8
|
} |
119
|
2
|
|
|
|
|
35
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
BEGIN { init } |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
*again = \&init; |
124
|
2
|
|
|
2
|
0
|
5
|
|
125
|
2
|
|
|
|
|
7
|
1; # Keep require happy |