Filename | /usr/lib/perl/5.18/File/Spec/Unix.pm |
Statements | Executed 69 statements in 1.83ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
4 | 2 | 1 | 57µs | 69µs | canonpath | File::Spec::Unix::
3 | 3 | 1 | 16µs | 63µs | catdir | File::Spec::Unix::
1 | 1 | 1 | 14µs | 28µs | BEGIN@3 | File::Spec::Unix::
1 | 1 | 1 | 12µs | 42µs | rel2abs | File::Spec::Unix::
24 | 6 | 1 | 12µs | 12µs | CORE:subst (opcode) | File::Spec::Unix::
1 | 1 | 1 | 11µs | 26µs | BEGIN@65 | File::Spec::Unix::
1 | 1 | 1 | 7µs | 27µs | BEGIN@4 | File::Spec::Unix::
1 | 1 | 1 | 6µs | 8µs | file_name_is_absolute | File::Spec::Unix::
1 | 1 | 1 | 2µs | 2µs | CORE:match (opcode) | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | _collapse | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | _cwd | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | _same | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | _tmpdir | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | abs2rel | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | case_tolerant | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | catfile | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | catpath | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | curdir | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | devnull | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | join | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | no_upwards | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | path | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | rootdir | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | splitdir | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | splitpath | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | tmpdir | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | updir | File::Spec::Unix::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package File::Spec::Unix; | ||||
2 | |||||
3 | 2 | 32µs | 2 | 42µs | # spent 28µs (14+14) within File::Spec::Unix::BEGIN@3 which was called:
# once (14µs+14µs) by local::lib::BEGIN@9 at line 3 # spent 28µs making 1 call to File::Spec::Unix::BEGIN@3
# spent 14µs making 1 call to strict::import |
4 | 2 | 420µs | 2 | 48µs | # spent 27µs (7+21) within File::Spec::Unix::BEGIN@4 which was called:
# once (7µs+21µs) by local::lib::BEGIN@9 at line 4 # spent 27µs making 1 call to File::Spec::Unix::BEGIN@4
# spent 21µs making 1 call to vars::import |
5 | |||||
6 | 1 | 800ns | $VERSION = '3.40'; | ||
7 | 1 | 600ns | $VERSION =~ tr/_//; | ||
8 | |||||
9 | sub canonpath { | ||||
10 | 4 | 2µs | my ($self,$path) = @_; | ||
11 | 4 | 1µs | return unless defined $path; | ||
12 | |||||
13 | # Handle POSIX-style node names beginning with double slash (qnx, nto) | ||||
14 | # (POSIX says: "a pathname that begins with two successive slashes | ||||
15 | # may be interpreted in an implementation-defined manner, although | ||||
16 | # more than two leading slashes shall be treated as a single slash.") | ||||
17 | 4 | 800ns | my $node = ''; | ||
18 | 4 | 4µs | my $double_slashes_special = $^O eq 'qnx' || $^O eq 'nto'; | ||
19 | |||||
20 | 4 | 600ns | if ( $double_slashes_special | ||
21 | && ( $path =~ s{^(//[^/]+)/?\z}{}s || $path =~ s{^(//[^/]+)/}{/}s ) ) { | ||||
22 | $node = $1; | ||||
23 | } | ||||
24 | # This used to be | ||||
25 | # $path =~ s|/+|/|g unless ($^O eq 'cygwin'); | ||||
26 | # but that made tests 29, 30, 35, 46, and 213 (as of #13272) to fail | ||||
27 | # (Mainly because trailing "" directories didn't get stripped). | ||||
28 | # Why would cygwin avoid collapsing multiple slashes into one? --jhi | ||||
29 | 4 | 13µs | 4 | 3µs | $path =~ s|/{2,}|/|g; # xx////xx -> xx/xx # spent 3µs making 4 calls to File::Spec::Unix::CORE:subst, avg 675ns/call |
30 | 4 | 7µs | 4 | 1µs | $path =~ s{(?:/\.)+(?:/|\z)}{/}g; # xx/././xx -> xx/xx # spent 1µs making 4 calls to File::Spec::Unix::CORE:subst, avg 275ns/call |
31 | 4 | 8µs | 4 | 1µs | $path =~ s|^(?:\./)+||s unless $path eq "./"; # ./xx -> xx # spent 1µs making 4 calls to File::Spec::Unix::CORE:subst, avg 250ns/call |
32 | 4 | 7µs | 4 | 1µs | $path =~ s|^/(?:\.\./)+|/|; # /../../xx -> xx # spent 1µs making 4 calls to File::Spec::Unix::CORE:subst, avg 250ns/call |
33 | 4 | 7µs | 4 | 900ns | $path =~ s|^/\.\.$|/|; # /.. -> / # spent 900ns making 4 calls to File::Spec::Unix::CORE:subst, avg 225ns/call |
34 | 4 | 12µs | 4 | 5µs | $path =~ s|/\z|| unless $path eq "/"; # xx/ -> xx # spent 5µs making 4 calls to File::Spec::Unix::CORE:subst, avg 1µs/call |
35 | 4 | 16µs | return "$node$path"; | ||
36 | } | ||||
37 | |||||
38 | # spent 63µs (16+47) within File::Spec::Unix::catdir which was called 3 times, avg 21µs/call:
# once (7µs+16µs) by local::lib::setup_local_lib_for at line 240 of local/lib.pm
# once (6µs+17µs) by local::lib::install_base_perl_path at line 258 of local/lib.pm
# once (3µs+14µs) by local::lib::install_base_bin_path at line 253 of local/lib.pm | ||||
39 | 3 | 1µs | my $self = shift; | ||
40 | |||||
41 | 3 | 14µs | 3 | 47µs | $self->canonpath(join('/', @_, '')); # '' because need a trailing '/' # spent 47µs making 3 calls to File::Spec::Unix::canonpath, avg 16µs/call |
42 | } | ||||
43 | |||||
44 | sub catfile { | ||||
45 | my $self = shift; | ||||
46 | my $file = $self->canonpath(pop @_); | ||||
47 | return $file unless @_; | ||||
48 | my $dir = $self->catdir(@_); | ||||
49 | $dir .= "/" unless substr($dir,-1) eq "/"; | ||||
50 | return $dir.$file; | ||||
51 | } | ||||
52 | |||||
53 | sub curdir { '.' } | ||||
54 | |||||
55 | sub devnull { '/dev/null' } | ||||
56 | |||||
57 | sub rootdir { '/' } | ||||
58 | |||||
59 | 1 | 200ns | my $tmpdir; | ||
60 | sub _tmpdir { | ||||
61 | return $tmpdir if defined $tmpdir; | ||||
62 | my $self = shift; | ||||
63 | my @dirlist = @_; | ||||
64 | { | ||||
65 | 2 | 1.26ms | 2 | 40µs | # spent 26µs (11+14) within File::Spec::Unix::BEGIN@65 which was called:
# once (11µs+14µs) by local::lib::BEGIN@9 at line 65 # spent 26µs making 1 call to File::Spec::Unix::BEGIN@65
# spent 14µs making 1 call to strict::unimport |
66 | if (${"\cTAINT"}) { # Check for taint mode on perl >= 5.8.0 | ||||
67 | require Scalar::Util; | ||||
68 | @dirlist = grep { ! Scalar::Util::tainted($_) } @dirlist; | ||||
69 | } | ||||
70 | elsif ($] < 5.007) { # No ${^TAINT} before 5.8 | ||||
71 | @dirlist = grep { eval { eval('1'.substr $_,0,0) } } @dirlist; | ||||
72 | } | ||||
73 | } | ||||
74 | foreach (@dirlist) { | ||||
75 | next unless defined && -d && -w _; | ||||
76 | $tmpdir = $_; | ||||
77 | last; | ||||
78 | } | ||||
79 | $tmpdir = $self->curdir unless defined $tmpdir; | ||||
80 | $tmpdir = defined $tmpdir && $self->canonpath($tmpdir); | ||||
81 | return $tmpdir; | ||||
82 | } | ||||
83 | |||||
84 | sub tmpdir { | ||||
85 | return $tmpdir if defined $tmpdir; | ||||
86 | $tmpdir = $_[0]->_tmpdir( $ENV{TMPDIR}, "/tmp" ); | ||||
87 | } | ||||
88 | |||||
89 | sub updir { '..' } | ||||
90 | |||||
91 | sub no_upwards { | ||||
92 | my $self = shift; | ||||
93 | return grep(!/^\.{1,2}\z/s, @_); | ||||
94 | } | ||||
95 | |||||
96 | sub case_tolerant { 0 } | ||||
97 | |||||
98 | # spent 8µs (6+2) within File::Spec::Unix::file_name_is_absolute which was called:
# once (6µs+2µs) by File::Spec::Unix::rel2abs at line 236 | ||||
99 | 1 | 500ns | my ($self,$file) = @_; | ||
100 | 1 | 9µs | 1 | 2µs | return scalar($file =~ m:^/:s); # spent 2µs making 1 call to File::Spec::Unix::CORE:match |
101 | } | ||||
102 | |||||
103 | sub path { | ||||
104 | return () unless exists $ENV{PATH}; | ||||
105 | my @path = split(':', $ENV{PATH}); | ||||
106 | foreach (@path) { $_ = '.' if $_ eq '' } | ||||
107 | return @path; | ||||
108 | } | ||||
109 | |||||
110 | sub join { | ||||
111 | my $self = shift; | ||||
112 | return $self->catfile(@_); | ||||
113 | } | ||||
114 | |||||
115 | sub splitpath { | ||||
116 | my ($self,$path, $nofile) = @_; | ||||
117 | |||||
118 | my ($volume,$directory,$file) = ('','',''); | ||||
119 | |||||
120 | if ( $nofile ) { | ||||
121 | $directory = $path; | ||||
122 | } | ||||
123 | else { | ||||
124 | $path =~ m|^ ( (?: .* / (?: \.\.?\z )? )? ) ([^/]*) |xs; | ||||
125 | $directory = $1; | ||||
126 | $file = $2; | ||||
127 | } | ||||
128 | |||||
129 | return ($volume,$directory,$file); | ||||
130 | } | ||||
131 | |||||
132 | sub splitdir { | ||||
133 | return split m|/|, $_[1], -1; # Preserve trailing fields | ||||
134 | } | ||||
135 | |||||
136 | sub catpath { | ||||
137 | my ($self,$volume,$directory,$file) = @_; | ||||
138 | |||||
139 | if ( $directory ne '' && | ||||
140 | $file ne '' && | ||||
141 | substr( $directory, -1 ) ne '/' && | ||||
142 | substr( $file, 0, 1 ) ne '/' | ||||
143 | ) { | ||||
144 | $directory .= "/$file" ; | ||||
145 | } | ||||
146 | else { | ||||
147 | $directory .= $file ; | ||||
148 | } | ||||
149 | |||||
150 | return $directory ; | ||||
151 | } | ||||
152 | |||||
153 | sub abs2rel { | ||||
154 | my($self,$path,$base) = @_; | ||||
155 | $base = $self->_cwd() unless defined $base and length $base; | ||||
156 | |||||
157 | ($path, $base) = map $self->canonpath($_), $path, $base; | ||||
158 | |||||
159 | my $path_directories; | ||||
160 | my $base_directories; | ||||
161 | |||||
162 | if (grep $self->file_name_is_absolute($_), $path, $base) { | ||||
163 | ($path, $base) = map $self->rel2abs($_), $path, $base; | ||||
164 | |||||
165 | my ($path_volume) = $self->splitpath($path, 1); | ||||
166 | my ($base_volume) = $self->splitpath($base, 1); | ||||
167 | |||||
168 | # Can't relativize across volumes | ||||
169 | return $path unless $path_volume eq $base_volume; | ||||
170 | |||||
171 | $path_directories = ($self->splitpath($path, 1))[1]; | ||||
172 | $base_directories = ($self->splitpath($base, 1))[1]; | ||||
173 | |||||
174 | # For UNC paths, the user might give a volume like //foo/bar that | ||||
175 | # strictly speaking has no directory portion. Treat it as if it | ||||
176 | # had the root directory for that volume. | ||||
177 | if (!length($base_directories) and $self->file_name_is_absolute($base)) { | ||||
178 | $base_directories = $self->rootdir; | ||||
179 | } | ||||
180 | } | ||||
181 | else { | ||||
182 | my $wd= ($self->splitpath($self->_cwd(), 1))[1]; | ||||
183 | $path_directories = $self->catdir($wd, $path); | ||||
184 | $base_directories = $self->catdir($wd, $base); | ||||
185 | } | ||||
186 | |||||
187 | # Now, remove all leading components that are the same | ||||
188 | my @pathchunks = $self->splitdir( $path_directories ); | ||||
189 | my @basechunks = $self->splitdir( $base_directories ); | ||||
190 | |||||
191 | if ($base_directories eq $self->rootdir) { | ||||
192 | return $self->curdir if $path_directories eq $self->rootdir; | ||||
193 | shift @pathchunks; | ||||
194 | return $self->canonpath( $self->catpath('', $self->catdir( @pathchunks ), '') ); | ||||
195 | } | ||||
196 | |||||
197 | my @common; | ||||
198 | while (@pathchunks && @basechunks && $self->_same($pathchunks[0], $basechunks[0])) { | ||||
199 | push @common, shift @pathchunks ; | ||||
200 | shift @basechunks ; | ||||
201 | } | ||||
202 | return $self->curdir unless @pathchunks || @basechunks; | ||||
203 | |||||
204 | # @basechunks now contains the directories the resulting relative path | ||||
205 | # must ascend out of before it can descend to $path_directory. If there | ||||
206 | # are updir components, we must descend into the corresponding directories | ||||
207 | # (this only works if they are no symlinks). | ||||
208 | my @reverse_base; | ||||
209 | while( defined(my $dir= shift @basechunks) ) { | ||||
210 | if( $dir ne $self->updir ) { | ||||
211 | unshift @reverse_base, $self->updir; | ||||
212 | push @common, $dir; | ||||
213 | } | ||||
214 | elsif( @common ) { | ||||
215 | if( @reverse_base && $reverse_base[0] eq $self->updir ) { | ||||
216 | shift @reverse_base; | ||||
217 | pop @common; | ||||
218 | } | ||||
219 | else { | ||||
220 | unshift @reverse_base, pop @common; | ||||
221 | } | ||||
222 | } | ||||
223 | } | ||||
224 | my $result_dirs = $self->catdir( @reverse_base, @pathchunks ); | ||||
225 | return $self->canonpath( $self->catpath('', $result_dirs, '') ); | ||||
226 | } | ||||
227 | |||||
228 | sub _same { | ||||
229 | $_[1] eq $_[2]; | ||||
230 | } | ||||
231 | |||||
232 | # spent 42µs (12+30) within File::Spec::Unix::rel2abs which was called:
# once (12µs+30µs) by local::lib::resolve_relative_path at line 192 of local/lib.pm | ||||
233 | 1 | 700ns | my ($self,$path,$base ) = @_; | ||
234 | |||||
235 | # Clean up $path | ||||
236 | 1 | 3µs | 1 | 8µs | if ( ! $self->file_name_is_absolute( $path ) ) { # spent 8µs making 1 call to File::Spec::Unix::file_name_is_absolute |
237 | # Figure out the effective $base and clean it up. | ||||
238 | if ( !defined( $base ) || $base eq '' ) { | ||||
239 | $base = $self->_cwd(); | ||||
240 | } | ||||
241 | elsif ( ! $self->file_name_is_absolute( $base ) ) { | ||||
242 | $base = $self->rel2abs( $base ) ; | ||||
243 | } | ||||
244 | else { | ||||
245 | $base = $self->canonpath( $base ) ; | ||||
246 | } | ||||
247 | |||||
248 | # Glom them together | ||||
249 | $path = $self->catdir( $base, $path ) ; | ||||
250 | } | ||||
251 | |||||
252 | 1 | 6µs | 1 | 22µs | return $self->canonpath( $path ) ; # spent 22µs making 1 call to File::Spec::Unix::canonpath |
253 | } | ||||
254 | |||||
255 | # Internal routine to File::Spec, no point in making this public since | ||||
256 | # it is the standard Cwd interface. Most of the platform-specific | ||||
257 | # File::Spec subclasses use this. | ||||
258 | sub _cwd { | ||||
259 | require Cwd; | ||||
260 | Cwd::getcwd(); | ||||
261 | } | ||||
262 | |||||
263 | # Internal method to reduce xx\..\yy -> yy | ||||
264 | sub _collapse { | ||||
265 | my($fs, $path) = @_; | ||||
266 | |||||
267 | my $updir = $fs->updir; | ||||
268 | my $curdir = $fs->curdir; | ||||
269 | |||||
270 | my($vol, $dirs, $file) = $fs->splitpath($path); | ||||
271 | my @dirs = $fs->splitdir($dirs); | ||||
272 | pop @dirs if @dirs && $dirs[-1] eq ''; | ||||
273 | |||||
274 | my @collapsed; | ||||
275 | foreach my $dir (@dirs) { | ||||
276 | if( $dir eq $updir and # if we have an updir | ||||
277 | @collapsed and # and something to collapse | ||||
278 | length $collapsed[-1] and # and its not the rootdir | ||||
279 | $collapsed[-1] ne $updir and # nor another updir | ||||
280 | $collapsed[-1] ne $curdir # nor the curdir | ||||
281 | ) | ||||
282 | { # then | ||||
283 | pop @collapsed; # collapse | ||||
284 | } | ||||
285 | else { # else | ||||
286 | push @collapsed, $dir; # just hang onto it | ||||
287 | } | ||||
288 | } | ||||
289 | |||||
290 | return $fs->catpath($vol, | ||||
291 | $fs->catdir(@collapsed), | ||||
292 | $file | ||||
293 | ); | ||||
294 | } | ||||
295 | |||||
296 | 1 | 3µs | 1; | ||
# spent 2µs within File::Spec::Unix::CORE:match which was called:
# once (2µs+0s) by File::Spec::Unix::file_name_is_absolute at line 100 | |||||
# spent 12µs within File::Spec::Unix::CORE:subst which was called 24 times, avg 488ns/call:
# 4 times (5µs+0s) by File::Spec::Unix::canonpath at line 34, avg 1µs/call
# 4 times (3µs+0s) by File::Spec::Unix::canonpath at line 29, avg 675ns/call
# 4 times (1µs+0s) by File::Spec::Unix::canonpath at line 30, avg 275ns/call
# 4 times (1µs+0s) by File::Spec::Unix::canonpath at line 32, avg 250ns/call
# 4 times (1µs+0s) by File::Spec::Unix::canonpath at line 31, avg 250ns/call
# 4 times (900ns+0s) by File::Spec::Unix::canonpath at line 33, avg 225ns/call |