Filename | /usr/lib64/perl5/vendor_perl/5.16.0/x86_64-linux/File/Spec/Unix.pm |
Statements | Executed 3893333 statements in 57.8s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
154873 | 6 | 1 | 19.0s | 21.8s | canonpath | File::Spec::Unix::
19016 | 1 | 1 | 18.8s | 47.1s | abs2rel | File::Spec::Unix::
51617 | 2 | 2 | 4.87s | 18.9s | rel2abs | File::Spec::Unix::
103235 | 4 | 2 | 3.28s | 3.86s | file_name_is_absolute | File::Spec::Unix::
929238 | 6 | 1 | 2.83s | 2.83s | CORE:subst (opcode) | File::Spec::Unix::
222360 | 2 | 1 | 2.37s | 2.37s | _same | File::Spec::Unix::
38032 | 2 | 1 | 1.85s | 1.85s | splitdir | File::Spec::Unix::
78628 | 5 | 2 | 1.62s | 1.69s | splitpath | File::Spec::Unix::
32615 | 8 | 2 | 1.24s | 6.32s | catdir | File::Spec::Unix::
105799 | 2 | 1 | 654ms | 654ms | CORE:match (opcode) | File::Spec::Unix::
19016 | 1 | 1 | 477ms | 477ms | catpath | File::Spec::Unix::
19017 | 2 | 2 | 200ms | 200ms | rootdir | File::Spec::Unix::
5152 | 2 | 1 | 47.2ms | 47.2ms | updir | File::Spec::Unix::
8 | 3 | 3 | 621µs | 2.80ms | catfile | File::Spec::Unix::
1 | 1 | 1 | 77µs | 172µs | BEGIN@3 | File::Spec::Unix::
1 | 1 | 1 | 59µs | 146µs | BEGIN@149 | File::Spec::Unix::
1 | 1 | 1 | 52µs | 190µs | BEGIN@4 | 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 | _tmpdir | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | case_tolerant | 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 | tmpdir | File::Spec::Unix::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package File::Spec::Unix; | ||||
2 | |||||
3 | 2 | 232µs | 2 | 266µs | # spent 172µs (77+94) within File::Spec::Unix::BEGIN@3 which was called:
# once (77µs+94µs) by FindBin::BEGIN@85 at line 3 # spent 172µs making 1 call to File::Spec::Unix::BEGIN@3
# spent 94µs making 1 call to strict::import |
4 | 2 | 2.26ms | 2 | 328µs | # spent 190µs (52+138) within File::Spec::Unix::BEGIN@4 which was called:
# once (52µs+138µs) by FindBin::BEGIN@85 at line 4 # spent 190µs making 1 call to File::Spec::Unix::BEGIN@4
# spent 138µs making 1 call to vars::import |
5 | |||||
6 | 1 | 4µs | $VERSION = '3.40'; | ||
7 | 1 | 3µs | $VERSION =~ tr/_//; | ||
8 | |||||
9 | =head1 NAME | ||||
10 | |||||
11 | File::Spec::Unix - File::Spec for Unix, base for other File::Spec modules | ||||
12 | |||||
13 | =head1 SYNOPSIS | ||||
14 | |||||
15 | require File::Spec::Unix; # Done automatically by File::Spec | ||||
16 | |||||
17 | =head1 DESCRIPTION | ||||
18 | |||||
19 | Methods for manipulating file specifications. Other File::Spec | ||||
20 | modules, such as File::Spec::Mac, inherit from File::Spec::Unix and | ||||
21 | override specific methods. | ||||
22 | |||||
23 | =head1 METHODS | ||||
24 | |||||
25 | =over 2 | ||||
26 | |||||
27 | =item canonpath() | ||||
28 | |||||
29 | No physical check on the filesystem, but a logical cleanup of a | ||||
30 | path. On UNIX eliminates successive slashes and successive "/.". | ||||
31 | |||||
32 | $cpath = File::Spec->canonpath( $path ) ; | ||||
33 | |||||
34 | Note that this does *not* collapse F<x/../y> sections into F<y>. This | ||||
35 | is by design. If F</foo> on your system is a symlink to F</bar/baz>, | ||||
36 | then F</foo/../quux> is actually F</bar/quux>, not F</quux> as a naive | ||||
37 | F<../>-removal would give you. If you want to do this kind of | ||||
38 | processing, you probably want C<Cwd>'s C<realpath()> function to | ||||
39 | actually traverse the filesystem cleaning up paths like this. | ||||
40 | |||||
41 | =cut | ||||
42 | |||||
43 | # spent 21.8s (19.0+2.83) within File::Spec::Unix::canonpath which was called 154873 times, avg 141µs/call:
# 51617 times (6.09s+867ms) by File::Spec::Unix::rel2abs at line 490, avg 135µs/call
# 38032 times (4.85s+609ms) by File::Spec::Unix::abs2rel at line 369, avg 143µs/call
# 32615 times (4.21s+875ms) by File::Spec::Unix::catdir at line 86, avg 156µs/call
# 19016 times (2.18s+226ms) by File::Spec::Unix::abs2rel at line 437, avg 127µs/call
# 13585 times (1.66s+252ms) by File::Spec::Unix::rel2abs at line 483, avg 141µs/call
# 8 times (835µs+113µs) by File::Spec::Unix::catfile at line 98, avg 118µs/call | ||||
44 | 154873 | 499ms | my ($self,$path) = @_; | ||
45 | 154873 | 141ms | return unless defined $path; | ||
46 | |||||
47 | # Handle POSIX-style node names beginning with double slash (qnx, nto) | ||||
48 | # (POSIX says: "a pathname that begins with two successive slashes | ||||
49 | # may be interpreted in an implementation-defined manner, although | ||||
50 | # more than two leading slashes shall be treated as a single slash.") | ||||
51 | 154873 | 182ms | my $node = ''; | ||
52 | 154873 | 854ms | my $double_slashes_special = $^O eq 'qnx' || $^O eq 'nto'; | ||
53 | |||||
54 | |||||
55 | 154873 | 92.4ms | if ( $double_slashes_special | ||
56 | && ( $path =~ s{^(//[^/]+)/?\z}{}s || $path =~ s{^(//[^/]+)/}{/}s ) ) { | ||||
57 | $node = $1; | ||||
58 | } | ||||
59 | # This used to be | ||||
60 | # $path =~ s|/+|/|g unless ($^O eq 'cygwin'); | ||||
61 | # but that made tests 29, 30, 35, 46, and 213 (as of #13272) to fail | ||||
62 | # (Mainly because trailing "" directories didn't get stripped). | ||||
63 | # Why would cygwin avoid collapsing multiple slashes into one? --jhi | ||||
64 | 154873 | 3.41s | 154873 | 602ms | $path =~ s|/{2,}|/|g; # xx////xx -> xx/xx # spent 602ms making 154873 calls to File::Spec::Unix::CORE:subst, avg 4µs/call |
65 | 154873 | 3.06s | 154873 | 594ms | $path =~ s{(?:/\.)+(?:/|\z)}{/}g; # xx/././xx -> xx/xx # spent 594ms making 154873 calls to File::Spec::Unix::CORE:subst, avg 4µs/call |
66 | 154873 | 2.83s | 154873 | 347ms | $path =~ s|^(?:\./)+||s unless $path eq "./"; # ./xx -> xx # spent 347ms making 154873 calls to File::Spec::Unix::CORE:subst, avg 2µs/call |
67 | 154873 | 2.67s | 154873 | 342ms | $path =~ s|^/(?:\.\./)+|/|; # /../../xx -> xx # spent 342ms making 154873 calls to File::Spec::Unix::CORE:subst, avg 2µs/call |
68 | 154873 | 2.58s | 154873 | 291ms | $path =~ s|^/\.\.$|/|; # /.. -> / # spent 291ms making 154873 calls to File::Spec::Unix::CORE:subst, avg 2µs/call |
69 | 154873 | 3.24s | 154873 | 654ms | $path =~ s|/\z|| unless $path eq "/"; # xx/ -> xx # spent 654ms making 154873 calls to File::Spec::Unix::CORE:subst, avg 4µs/call |
70 | 154873 | 3.92s | return "$node$path"; | ||
71 | } | ||||
72 | |||||
73 | =item catdir() | ||||
74 | |||||
75 | Concatenate two or more directory names to form a complete path ending | ||||
76 | with a directory. But remove the trailing slash from the resulting | ||||
77 | string, because it doesn't look good, isn't necessary and confuses | ||||
78 | OS2. Of course, if this is the root directory, don't cut off the | ||||
79 | trailing slash :-) | ||||
80 | |||||
81 | =cut | ||||
82 | |||||
83 | # spent 6.32s (1.24+5.08) within File::Spec::Unix::catdir which was called 32615 times, avg 194µs/call:
# 19016 times (715ms+2.80s) by File::Spec::Unix::abs2rel at line 436, avg 185µs/call
# 13585 times (526ms+2.28s) by File::Spec::Unix::rel2abs at line 487, avg 207µs/call
# 8 times (285µs+949µs) by File::Spec::Unix::catfile at line 100, avg 154µs/call
# 2 times (57µs+200µs) by File::MimeInfo::Magic::BEGIN@7 at line 43 of File/BaseDir.pm, avg 128µs/call
# once (27µs+160µs) by File::MimeInfo::Magic::BEGIN@7 at line 49 of File/BaseDir.pm
# once (37µs+127µs) by File::MimeInfo::Magic::BEGIN@7 at line 42 of File/BaseDir.pm
# once (27µs+99µs) by File::MimeInfo::Magic::BEGIN@7 at line 48 of File/BaseDir.pm
# once (27µs+97µs) by File::MimeInfo::Magic::BEGIN@7 at line 47 of File/BaseDir.pm | ||||
84 | 32615 | 76.0ms | my $self = shift; | ||
85 | |||||
86 | 32615 | 1.27s | 32615 | 5.08s | $self->canonpath(join('/', @_, '')); # '' because need a trailing '/' # spent 5.08s making 32615 calls to File::Spec::Unix::canonpath, avg 156µs/call |
87 | } | ||||
88 | |||||
89 | =item catfile | ||||
90 | |||||
91 | Concatenate one or more directory names and a filename to form a | ||||
92 | complete path ending with a filename | ||||
93 | |||||
94 | =cut | ||||
95 | |||||
96 | # spent 2.80ms (621µs+2.18) within File::Spec::Unix::catfile which was called 8 times, avg 350µs/call:
# 6 times (442µs+1.61ms) by File::BaseDir::_find_files at line 111 of File/BaseDir.pm, avg 343µs/call
# once (113µs+329µs) by FindBin::init at line 137 of FindBin.pm
# once (66µs+239µs) by XML::SAX::load_parsers at line 61 of XML/SAX.pm | ||||
97 | 8 | 24µs | my $self = shift; | ||
98 | 8 | 165µs | 8 | 947µs | my $file = $self->canonpath(pop @_); # spent 947µs making 8 calls to File::Spec::Unix::canonpath, avg 118µs/call |
99 | 8 | 16µs | return $file unless @_; | ||
100 | 8 | 166µs | 8 | 1.23ms | my $dir = $self->catdir(@_); # spent 1.23ms making 8 calls to File::Spec::Unix::catdir, avg 154µs/call |
101 | 8 | 56µs | $dir .= "/" unless substr($dir,-1) eq "/"; | ||
102 | 8 | 191µs | return $dir.$file; | ||
103 | } | ||||
104 | |||||
105 | =item curdir | ||||
106 | |||||
107 | Returns a string representation of the current directory. "." on UNIX. | ||||
108 | |||||
109 | =cut | ||||
110 | |||||
111 | sub curdir { '.' } | ||||
112 | |||||
113 | =item devnull | ||||
114 | |||||
115 | Returns a string representation of the null device. "/dev/null" on UNIX. | ||||
116 | |||||
117 | =cut | ||||
118 | |||||
119 | sub devnull { '/dev/null' } | ||||
120 | |||||
121 | =item rootdir | ||||
122 | |||||
123 | Returns a string representation of the root directory. "/" on UNIX. | ||||
124 | |||||
125 | =cut | ||||
126 | |||||
127 | 19017 | 347ms | # spent 200ms within File::Spec::Unix::rootdir which was called 19017 times, avg 10µs/call:
# 19016 times (200ms+0s) by File::Spec::Unix::abs2rel at line 403, avg 10µs/call
# once (18µs+0s) by File::MimeInfo::Magic::BEGIN@7 at line 29 of File/BaseDir.pm | ||
128 | |||||
129 | =item tmpdir | ||||
130 | |||||
131 | Returns a string representation of the first writable directory from | ||||
132 | the following list or the current directory if none from the list are | ||||
133 | writable: | ||||
134 | |||||
135 | $ENV{TMPDIR} | ||||
136 | /tmp | ||||
137 | |||||
138 | If running under taint mode, and if $ENV{TMPDIR} | ||||
139 | is tainted, it is not used. | ||||
140 | |||||
141 | =cut | ||||
142 | |||||
143 | 1 | 1µs | my $tmpdir; | ||
144 | sub _tmpdir { | ||||
145 | return $tmpdir if defined $tmpdir; | ||||
146 | my $self = shift; | ||||
147 | my @dirlist = @_; | ||||
148 | { | ||||
149 | 2 | 6.88ms | 2 | 232µs | # spent 146µs (59+86) within File::Spec::Unix::BEGIN@149 which was called:
# once (59µs+86µs) by FindBin::BEGIN@85 at line 149 # spent 146µs making 1 call to File::Spec::Unix::BEGIN@149
# spent 86µs making 1 call to strict::unimport |
150 | if (${"\cTAINT"}) { # Check for taint mode on perl >= 5.8.0 | ||||
151 | require Scalar::Util; | ||||
152 | @dirlist = grep { ! Scalar::Util::tainted($_) } @dirlist; | ||||
153 | } | ||||
154 | elsif ($] < 5.007) { # No ${^TAINT} before 5.8 | ||||
155 | @dirlist = grep { eval { eval('1'.substr $_,0,0) } } @dirlist; | ||||
156 | } | ||||
157 | } | ||||
158 | foreach (@dirlist) { | ||||
159 | next unless defined && -d && -w _; | ||||
160 | $tmpdir = $_; | ||||
161 | last; | ||||
162 | } | ||||
163 | $tmpdir = $self->curdir unless defined $tmpdir; | ||||
164 | $tmpdir = defined $tmpdir && $self->canonpath($tmpdir); | ||||
165 | return $tmpdir; | ||||
166 | } | ||||
167 | |||||
168 | sub tmpdir { | ||||
169 | return $tmpdir if defined $tmpdir; | ||||
170 | $tmpdir = $_[0]->_tmpdir( $ENV{TMPDIR}, "/tmp" ); | ||||
171 | } | ||||
172 | |||||
173 | =item updir | ||||
174 | |||||
175 | Returns a string representation of the parent directory. ".." on UNIX. | ||||
176 | |||||
177 | =cut | ||||
178 | |||||
179 | 5152 | 96.7ms | sub updir { '..' } | ||
180 | |||||
181 | =item no_upwards | ||||
182 | |||||
183 | Given a list of file names, strip out those that refer to a parent | ||||
184 | directory. (Does not strip symlinks, only '.', '..', and equivalents.) | ||||
185 | |||||
186 | =cut | ||||
187 | |||||
188 | sub no_upwards { | ||||
189 | my $self = shift; | ||||
190 | return grep(!/^\.{1,2}\z/s, @_); | ||||
191 | } | ||||
192 | |||||
193 | =item case_tolerant | ||||
194 | |||||
195 | Returns a true or false value indicating, respectively, that alphabetic | ||||
196 | is not or is significant when comparing file specifications. | ||||
197 | |||||
198 | =cut | ||||
199 | |||||
200 | sub case_tolerant { 0 } | ||||
201 | |||||
202 | =item file_name_is_absolute | ||||
203 | |||||
204 | Takes as argument a path and returns true if it is an absolute path. | ||||
205 | |||||
206 | This does not consult the local filesystem on Unix, Win32, OS/2 or Mac | ||||
207 | OS (Classic). It does consult the working environment for VMS (see | ||||
208 | L<File::Spec::VMS/file_name_is_absolute>). | ||||
209 | |||||
210 | =cut | ||||
211 | |||||
212 | # spent 3.86s (3.28+582ms) within File::Spec::Unix::file_name_is_absolute which was called 103235 times, avg 37µs/call:
# 51617 times (1.57s+242ms) by File::Spec::Unix::rel2abs at line 474, avg 35µs/call
# 38032 times (1.22s+251ms) by File::Spec::Unix::abs2rel at line 374, avg 39µs/call
# 13585 times (498ms+88.4ms) by File::Spec::Unix::rel2abs at line 476, avg 43µs/call
# once (64µs+6µs) by FindBin::init at line 137 of FindBin.pm | ||||
213 | 103235 | 316ms | my ($self,$file) = @_; | ||
214 | 103235 | 5.05s | 103235 | 582ms | return scalar($file =~ m:^/:s); # spent 582ms making 103235 calls to File::Spec::Unix::CORE:match, avg 6µs/call |
215 | } | ||||
216 | |||||
217 | =item path | ||||
218 | |||||
219 | Takes no argument, returns the environment variable PATH as an array. | ||||
220 | |||||
221 | =cut | ||||
222 | |||||
223 | sub path { | ||||
224 | return () unless exists $ENV{PATH}; | ||||
225 | my @path = split(':', $ENV{PATH}); | ||||
226 | foreach (@path) { $_ = '.' if $_ eq '' } | ||||
227 | return @path; | ||||
228 | } | ||||
229 | |||||
230 | =item join | ||||
231 | |||||
232 | join is the same as catfile. | ||||
233 | |||||
234 | =cut | ||||
235 | |||||
236 | sub join { | ||||
237 | my $self = shift; | ||||
238 | return $self->catfile(@_); | ||||
239 | } | ||||
240 | |||||
241 | =item splitpath | ||||
242 | |||||
243 | ($volume,$directories,$file) = File::Spec->splitpath( $path ); | ||||
244 | ($volume,$directories,$file) = File::Spec->splitpath( $path, | ||||
245 | $no_file ); | ||||
246 | |||||
247 | Splits a path into volume, directory, and filename portions. On systems | ||||
248 | with no concept of volume, returns '' for volume. | ||||
249 | |||||
250 | For systems with no syntax differentiating filenames from directories, | ||||
251 | assumes that the last file is a path unless $no_file is true or a | ||||
252 | trailing separator or /. or /.. is present. On Unix this means that $no_file | ||||
253 | true makes this return ( '', $path, '' ). | ||||
254 | |||||
255 | The directory portion may or may not be returned with a trailing '/'. | ||||
256 | |||||
257 | The results can be passed to L</catpath()> to get back a path equivalent to | ||||
258 | (usually identical to) the original path. | ||||
259 | |||||
260 | =cut | ||||
261 | |||||
262 | # spent 1.69s (1.62+72.0ms) within File::Spec::Unix::splitpath which was called 78628 times, avg 22µs/call:
# 19016 times (433ms+0s) by File::Spec::Unix::abs2rel at line 377, avg 23µs/call
# 19016 times (341ms+0s) by File::Spec::Unix::abs2rel at line 378, avg 18µs/call
# 19016 times (334ms+0s) by File::Spec::Unix::abs2rel at line 384, avg 18µs/call
# 19016 times (328ms+0s) by File::Spec::Unix::abs2rel at line 383, avg 17µs/call
# 2564 times (182ms+72.0ms) by File::MimeInfo::globs at line 69 of File/MimeInfo.pm, avg 99µs/call | ||||
263 | 78628 | 299ms | my ($self,$path, $nofile) = @_; | ||
264 | |||||
265 | 78628 | 177ms | my ($volume,$directory,$file) = ('','',''); | ||
266 | |||||
267 | 78628 | 101ms | if ( $nofile ) { | ||
268 | $directory = $path; | ||||
269 | } | ||||
270 | else { | ||||
271 | 2564 | 136ms | 2564 | 72.0ms | $path =~ m|^ ( (?: .* / (?: \.\.?\z )? )? ) ([^/]*) |xs; # spent 72.0ms making 2564 calls to File::Spec::Unix::CORE:match, avg 28µs/call |
272 | 2564 | 26.5ms | $directory = $1; | ||
273 | 2564 | 13.8ms | $file = $2; | ||
274 | } | ||||
275 | |||||
276 | 78628 | 1.99s | return ($volume,$directory,$file); | ||
277 | } | ||||
278 | |||||
279 | |||||
280 | =item splitdir | ||||
281 | |||||
282 | The opposite of L</catdir()>. | ||||
283 | |||||
284 | @dirs = File::Spec->splitdir( $directories ); | ||||
285 | |||||
286 | $directories must be only the directory portion of the path on systems | ||||
287 | that have the concept of a volume or that have path syntax that differentiates | ||||
288 | files from directories. | ||||
289 | |||||
290 | Unlike just splitting the directories on the separator, empty | ||||
291 | directory names (C<''>) can be returned, because these are significant | ||||
292 | on some OSs. | ||||
293 | |||||
294 | On Unix, | ||||
295 | |||||
296 | File::Spec->splitdir( "/a/b//c/" ); | ||||
297 | |||||
298 | Yields: | ||||
299 | |||||
300 | ( '', 'a', 'b', '', 'c', '' ) | ||||
301 | |||||
302 | =cut | ||||
303 | |||||
304 | sub splitdir { | ||||
305 | 38032 | 2.31s | return split m|/|, $_[1], -1; # Preserve trailing fields | ||
306 | } | ||||
307 | |||||
308 | |||||
309 | =item catpath() | ||||
310 | |||||
311 | Takes volume, directory and file portions and returns an entire path. Under | ||||
312 | Unix, $volume is ignored, and directory and file are concatenated. A '/' is | ||||
313 | inserted if needed (though if the directory portion doesn't start with | ||||
314 | '/' it is not added). On other OSs, $volume is significant. | ||||
315 | |||||
316 | =cut | ||||
317 | |||||
318 | # spent 477ms within File::Spec::Unix::catpath which was called 19016 times, avg 25µs/call:
# 19016 times (477ms+0s) by File::Spec::Unix::abs2rel at line 437, avg 25µs/call | ||||
319 | 19016 | 109ms | my ($self,$volume,$directory,$file) = @_; | ||
320 | |||||
321 | 19016 | 88.1ms | if ( $directory ne '' && | ||
322 | $file ne '' && | ||||
323 | substr( $directory, -1 ) ne '/' && | ||||
324 | substr( $file, 0, 1 ) ne '/' | ||||
325 | ) { | ||||
326 | $directory .= "/$file" ; | ||||
327 | } | ||||
328 | else { | ||||
329 | 19016 | 60.6ms | $directory .= $file ; | ||
330 | } | ||||
331 | |||||
332 | 19016 | 472ms | return $directory ; | ||
333 | } | ||||
334 | |||||
335 | =item abs2rel | ||||
336 | |||||
337 | Takes a destination path and an optional base path returns a relative path | ||||
338 | from the base path to the destination path: | ||||
339 | |||||
340 | $rel_path = File::Spec->abs2rel( $path ) ; | ||||
341 | $rel_path = File::Spec->abs2rel( $path, $base ) ; | ||||
342 | |||||
343 | If $base is not present or '', then L<cwd()|Cwd> is used. If $base is | ||||
344 | relative, then it is converted to absolute form using | ||||
345 | L</rel2abs()>. This means that it is taken to be relative to | ||||
346 | L<cwd()|Cwd>. | ||||
347 | |||||
348 | On systems that have a grammar that indicates filenames, this ignores the | ||||
349 | $base filename. Otherwise all path components are assumed to be | ||||
350 | directories. | ||||
351 | |||||
352 | If $path is relative, it is converted to absolute form using L</rel2abs()>. | ||||
353 | This means that it is taken to be relative to L<cwd()|Cwd>. | ||||
354 | |||||
355 | No checks against the filesystem are made, so the result may not be correct if | ||||
356 | C<$base> contains symbolic links. (Apply | ||||
357 | L<Cwd::abs_path()|Cwd/abs_path> beforehand if that | ||||
358 | is a concern.) On VMS, there is interaction with the working environment, as | ||||
359 | logicals and macros are expanded. | ||||
360 | |||||
361 | Based on code written by Shigio Yamaguchi. | ||||
362 | |||||
363 | =cut | ||||
364 | |||||
365 | # spent 47.1s (18.8+28.3) within File::Spec::Unix::abs2rel which was called 19016 times, avg 2.48ms/call:
# 19016 times (18.8s+28.3s) by File::Spec::Functions::__ANON__[/usr/lib64/perl5/vendor_perl/5.16.0/x86_64-linux/File/Spec/Functions.pm:43] at line 43 of File/Spec/Functions.pm, avg 2.48ms/call | ||||
366 | 19016 | 98.6ms | my($self,$path,$base) = @_; | ||
367 | 19016 | 109ms | $base = $self->_cwd() unless defined $base and length $base; | ||
368 | |||||
369 | 19016 | 981ms | 38032 | 5.46s | ($path, $base) = map $self->canonpath($_), $path, $base; # spent 5.46s making 38032 calls to File::Spec::Unix::canonpath, avg 143µs/call |
370 | |||||
371 | 19016 | 17.0ms | my $path_directories; | ||
372 | 19016 | 12.8ms | my $base_directories; | ||
373 | |||||
374 | 19016 | 746ms | 38032 | 1.47s | if (grep $self->file_name_is_absolute($_), $path, $base) { # spent 1.47s making 38032 calls to File::Spec::Unix::file_name_is_absolute, avg 39µs/call |
375 | 19016 | 870ms | 38032 | 9.06s | ($path, $base) = map $self->rel2abs($_), $path, $base; # spent 9.06s making 38032 calls to File::Spec::Unix::rel2abs, avg 238µs/call |
376 | |||||
377 | 19016 | 402ms | 19016 | 433ms | my ($path_volume) = $self->splitpath($path, 1); # spent 433ms making 19016 calls to File::Spec::Unix::splitpath, avg 23µs/call |
378 | 19016 | 336ms | 19016 | 341ms | my ($base_volume) = $self->splitpath($base, 1); # spent 341ms making 19016 calls to File::Spec::Unix::splitpath, avg 18µs/call |
379 | |||||
380 | # Can't relativize across volumes | ||||
381 | 19016 | 31.7ms | return $path unless $path_volume eq $base_volume; | ||
382 | |||||
383 | 19016 | 331ms | 19016 | 328ms | $path_directories = ($self->splitpath($path, 1))[1]; # spent 328ms making 19016 calls to File::Spec::Unix::splitpath, avg 17µs/call |
384 | 19016 | 318ms | 19016 | 334ms | $base_directories = ($self->splitpath($base, 1))[1]; # spent 334ms making 19016 calls to File::Spec::Unix::splitpath, avg 18µs/call |
385 | |||||
386 | # For UNC paths, the user might give a volume like //foo/bar that | ||||
387 | # strictly speaking has no directory portion. Treat it as if it | ||||
388 | # had the root directory for that volume. | ||||
389 | 19016 | 143ms | if (!length($base_directories) and $self->file_name_is_absolute($base)) { | ||
390 | $base_directories = $self->rootdir; | ||||
391 | } | ||||
392 | } | ||||
393 | else { | ||||
394 | my $wd= ($self->splitpath($self->_cwd(), 1))[1]; | ||||
395 | $path_directories = $self->catdir($wd, $path); | ||||
396 | $base_directories = $self->catdir($wd, $base); | ||||
397 | } | ||||
398 | |||||
399 | # Now, remove all leading components that are the same | ||||
400 | 19016 | 581ms | 19016 | 791ms | my @pathchunks = $self->splitdir( $path_directories ); # spent 791ms making 19016 calls to File::Spec::Unix::splitdir, avg 42µs/call |
401 | 19016 | 474ms | 19016 | 1.06s | my @basechunks = $self->splitdir( $base_directories ); # spent 1.06s making 19016 calls to File::Spec::Unix::splitdir, avg 55µs/call |
402 | |||||
403 | 19016 | 358ms | 19016 | 200ms | if ($base_directories eq $self->rootdir) { # spent 200ms making 19016 calls to File::Spec::Unix::rootdir, avg 10µs/call |
404 | return $self->curdir if $path_directories eq $self->rootdir; | ||||
405 | shift @pathchunks; | ||||
406 | return $self->canonpath( $self->catpath('', $self->catdir( @pathchunks ), '') ); | ||||
407 | } | ||||
408 | |||||
409 | 19016 | 22.0ms | my @common; | ||
410 | 19016 | 411ms | 19016 | 231ms | while (@pathchunks && @basechunks && $self->_same($pathchunks[0], $basechunks[0])) { # spent 231ms making 19016 calls to File::Spec::Unix::_same, avg 12µs/call |
411 | 219784 | 722ms | push @common, shift @pathchunks ; | ||
412 | 219784 | 3.91s | 203344 | 2.14s | shift @basechunks ; # spent 2.14s making 203344 calls to File::Spec::Unix::_same, avg 11µs/call |
413 | } | ||||
414 | 19016 | 25.0ms | return $self->curdir unless @pathchunks || @basechunks; | ||
415 | |||||
416 | # @basechunks now contains the directories the resulting relative path | ||||
417 | # must ascend out of before it can descend to $path_directory. If there | ||||
418 | # are updir components, we must descend into the corresponding directories | ||||
419 | # (this only works if they are no symlinks). | ||||
420 | 19016 | 18.3ms | my @reverse_base; | ||
421 | 19016 | 96.5ms | while( defined(my $dir= shift @basechunks) ) { | ||
422 | 2576 | 48.1ms | 2576 | 25.6ms | if( $dir ne $self->updir ) { # spent 25.6ms making 2576 calls to File::Spec::Unix::updir, avg 10µs/call |
423 | 2576 | 47.1ms | 2576 | 21.7ms | unshift @reverse_base, $self->updir; # spent 21.7ms making 2576 calls to File::Spec::Unix::updir, avg 8µs/call |
424 | 2576 | 11.2ms | push @common, $dir; | ||
425 | } | ||||
426 | elsif( @common ) { | ||||
427 | if( @reverse_base && $reverse_base[0] eq $self->updir ) { | ||||
428 | shift @reverse_base; | ||||
429 | pop @common; | ||||
430 | } | ||||
431 | else { | ||||
432 | unshift @reverse_base, pop @common; | ||||
433 | } | ||||
434 | } | ||||
435 | } | ||||
436 | 19016 | 349ms | 19016 | 3.51s | my $result_dirs = $self->catdir( @reverse_base, @pathchunks ); # spent 3.51s making 19016 calls to File::Spec::Unix::catdir, avg 185µs/call |
437 | 19016 | 1.32s | 38032 | 2.89s | return $self->canonpath( $self->catpath('', $result_dirs, '') ); # spent 2.41s making 19016 calls to File::Spec::Unix::canonpath, avg 127µs/call
# spent 477ms making 19016 calls to File::Spec::Unix::catpath, avg 25µs/call |
438 | } | ||||
439 | |||||
440 | sub _same { | ||||
441 | 222360 | 4.96s | $_[1] eq $_[2]; | ||
442 | } | ||||
443 | |||||
444 | =item rel2abs() | ||||
445 | |||||
446 | Converts a relative path to an absolute path. | ||||
447 | |||||
448 | $abs_path = File::Spec->rel2abs( $path ) ; | ||||
449 | $abs_path = File::Spec->rel2abs( $path, $base ) ; | ||||
450 | |||||
451 | If $base is not present or '', then L<cwd()|Cwd> is used. If $base is | ||||
452 | relative, then it is converted to absolute form using | ||||
453 | L</rel2abs()>. This means that it is taken to be relative to | ||||
454 | L<cwd()|Cwd>. | ||||
455 | |||||
456 | On systems that have a grammar that indicates filenames, this ignores | ||||
457 | the $base filename. Otherwise all path components are assumed to be | ||||
458 | directories. | ||||
459 | |||||
460 | If $path is absolute, it is cleaned up and returned using L</canonpath()>. | ||||
461 | |||||
462 | No checks against the filesystem are made. On VMS, there is | ||||
463 | interaction with the working environment, as logicals and | ||||
464 | macros are expanded. | ||||
465 | |||||
466 | Based on code written by Shigio Yamaguchi. | ||||
467 | |||||
468 | =cut | ||||
469 | |||||
470 | # spent 18.9s (4.87+14.1) within File::Spec::Unix::rel2abs which was called 51617 times, avg 367µs/call:
# 38032 times (2.59s+6.46s) by File::Spec::Unix::abs2rel at line 375, avg 238µs/call
# 13585 times (2.28s+7.61s) by File::Spec::Functions::__ANON__[/usr/lib64/perl5/vendor_perl/5.16.0/x86_64-linux/File/Spec/Functions.pm:43] at line 43 of File/Spec/Functions.pm, avg 728µs/call | ||||
471 | 51617 | 213ms | my ($self,$path,$base ) = @_; | ||
472 | |||||
473 | # Clean up $path | ||||
474 | 51617 | 819ms | 51617 | 1.81s | if ( ! $self->file_name_is_absolute( $path ) ) { # spent 1.81s making 51617 calls to File::Spec::Unix::file_name_is_absolute, avg 35µs/call |
475 | # Figure out the effective $base and clean it up. | ||||
476 | 13585 | 274ms | 13585 | 587ms | if ( !defined( $base ) || $base eq '' ) { # spent 587ms making 13585 calls to File::Spec::Unix::file_name_is_absolute, avg 43µs/call |
477 | $base = $self->_cwd(); | ||||
478 | } | ||||
479 | elsif ( ! $self->file_name_is_absolute( $base ) ) { | ||||
480 | $base = $self->rel2abs( $base ) ; | ||||
481 | } | ||||
482 | else { | ||||
483 | 13585 | 248ms | 13585 | 1.91s | $base = $self->canonpath( $base ) ; # spent 1.91s making 13585 calls to File::Spec::Unix::canonpath, avg 141µs/call |
484 | } | ||||
485 | |||||
486 | # Glom them together | ||||
487 | 13585 | 245ms | 13585 | 2.81s | $path = $self->catdir( $base, $path ) ; # spent 2.81s making 13585 calls to File::Spec::Unix::catdir, avg 207µs/call |
488 | } | ||||
489 | |||||
490 | 51617 | 1.82s | 51617 | 6.96s | return $self->canonpath( $path ) ; # spent 6.96s making 51617 calls to File::Spec::Unix::canonpath, avg 135µs/call |
491 | } | ||||
492 | |||||
493 | =back | ||||
494 | |||||
495 | =head1 COPYRIGHT | ||||
496 | |||||
497 | Copyright (c) 2004 by the Perl 5 Porters. All rights reserved. | ||||
498 | |||||
499 | This program is free software; you can redistribute it and/or modify | ||||
500 | it under the same terms as Perl itself. | ||||
501 | |||||
502 | Please submit bug reports and patches to perlbug@perl.org. | ||||
503 | |||||
504 | =head1 SEE ALSO | ||||
505 | |||||
506 | L<File::Spec> | ||||
507 | |||||
508 | =cut | ||||
509 | |||||
510 | # Internal routine to File::Spec, no point in making this public since | ||||
511 | # it is the standard Cwd interface. Most of the platform-specific | ||||
512 | # File::Spec subclasses use this. | ||||
513 | sub _cwd { | ||||
514 | require Cwd; | ||||
515 | Cwd::getcwd(); | ||||
516 | } | ||||
517 | |||||
518 | |||||
519 | # Internal method to reduce xx\..\yy -> yy | ||||
520 | sub _collapse { | ||||
521 | my($fs, $path) = @_; | ||||
522 | |||||
523 | my $updir = $fs->updir; | ||||
524 | my $curdir = $fs->curdir; | ||||
525 | |||||
526 | my($vol, $dirs, $file) = $fs->splitpath($path); | ||||
527 | my @dirs = $fs->splitdir($dirs); | ||||
528 | pop @dirs if @dirs && $dirs[-1] eq ''; | ||||
529 | |||||
530 | my @collapsed; | ||||
531 | foreach my $dir (@dirs) { | ||||
532 | if( $dir eq $updir and # if we have an updir | ||||
533 | @collapsed and # and something to collapse | ||||
534 | length $collapsed[-1] and # and its not the rootdir | ||||
535 | $collapsed[-1] ne $updir and # nor another updir | ||||
536 | $collapsed[-1] ne $curdir # nor the curdir | ||||
537 | ) | ||||
538 | { # then | ||||
539 | pop @collapsed; # collapse | ||||
540 | } | ||||
541 | else { # else | ||||
542 | push @collapsed, $dir; # just hang onto it | ||||
543 | } | ||||
544 | } | ||||
545 | |||||
546 | return $fs->catpath($vol, | ||||
547 | $fs->catdir(@collapsed), | ||||
548 | $file | ||||
549 | ); | ||||
550 | } | ||||
551 | |||||
552 | |||||
553 | 1 | 16µs | 1; | ||
sub File::Spec::Unix::CORE:match; # opcode | |||||
# spent 2.83s within File::Spec::Unix::CORE:subst which was called 929238 times, avg 3µs/call:
# 154873 times (654ms+0s) by File::Spec::Unix::canonpath at line 69, avg 4µs/call
# 154873 times (602ms+0s) by File::Spec::Unix::canonpath at line 64, avg 4µs/call
# 154873 times (594ms+0s) by File::Spec::Unix::canonpath at line 65, avg 4µs/call
# 154873 times (347ms+0s) by File::Spec::Unix::canonpath at line 66, avg 2µs/call
# 154873 times (342ms+0s) by File::Spec::Unix::canonpath at line 67, avg 2µs/call
# 154873 times (291ms+0s) by File::Spec::Unix::canonpath at line 68, avg 2µs/call |