← Index
NYTProf Performance Profile   « line view »
For split.pl
  Run on Thu Apr 20 02:05:47 2023
Reported on Thu Apr 20 18:31:09 2023

Filename/home/hejohns/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/File/Spec/Unix.pm
StatementsExecuted 2527766 statements in 7.53s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
133035112.37s2.73sFile::Spec::Unix::::splitpathFile::Spec::Unix::splitpath
133041641.46s1.88sFile::Spec::Unix::::file_name_is_absoluteFile::Spec::Unix::file_name_is_absolute
133035111.41s2.11sFile::Spec::Unix::::tmpdirFile::Spec::Unix::tmpdir
133079641.23s1.91sFile::Spec::Unix::::catfileFile::Spec::Unix::catfile (xsub)
26607621789ms789msFile::Spec::Unix::::CORE:matchFile::Spec::Unix::CORE:match (opcode)
13303511777ms777msFile::Spec::Unix::::catpathFile::Spec::Unix::catpath
13303511702ms702msFile::Spec::Unix::::_cached_tmpdirFile::Spec::Unix::_cached_tmpdir
13308885501ms562msFile::Spec::Unix::::catdirFile::Spec::Unix::catdir (xsub)
266170115175ms175msFile::Spec::Unix::::canonpathFile::Spec::Unix::canonpath (xsub)
111886µs997µsFile::Spec::Unix::::BEGIN@115File::Spec::Unix::BEGIN@115
11116µs30µsFile::Spec::Unix::::rel2absFile::Spec::Unix::rel2abs
11115µs28µsFile::Spec::Unix::::_tmpdirFile::Spec::Unix::_tmpdir
11112µs12µsFile::Spec::Unix::::pathFile::Spec::Unix::path
1118µs9µsFile::Spec::Unix::::BEGIN@3File::Spec::Unix::BEGIN@3
8116µs6µsFile::Spec::Unix::::splitdirFile::Spec::Unix::splitdir
1116µs9µsFile::Spec::Unix::::BEGIN@167File::Spec::Unix::BEGIN@167
1114µs4µsFile::Spec::Unix::::CORE:ftewriteFile::Spec::Unix::CORE:ftewrite (opcode)
1114µs21µsFile::Spec::Unix::::BEGIN@124File::Spec::Unix::BEGIN@124
1114µs23µsFile::Spec::Unix::::BEGIN@209File::Spec::Unix::BEGIN@209
1114µs20µsFile::Spec::Unix::::BEGIN@231File::Spec::Unix::BEGIN@231
3333µs3µsFile::Spec::Unix::::curdirFile::Spec::Unix::curdir
1113µs3µsFile::Spec::Unix::::CORE:ftdirFile::Spec::Unix::CORE:ftdir (opcode)
1113µs18µsFile::Spec::Unix::::BEGIN@133File::Spec::Unix::BEGIN@133
1113µs3µsFile::Spec::Unix::::_cache_tmpdirFile::Spec::Unix::_cache_tmpdir
1112µs2µsFile::Spec::Unix::::BEGIN@4File::Spec::Unix::BEGIN@4
1111µs1µsFile::Spec::Unix::::updirFile::Spec::Unix::updir
0000s0sFile::Spec::Unix::::_collapseFile::Spec::Unix::_collapse
0000s0sFile::Spec::Unix::::_pp_canonpathFile::Spec::Unix::_pp_canonpath
0000s0sFile::Spec::Unix::::_pp_catdirFile::Spec::Unix::_pp_catdir
0000s0sFile::Spec::Unix::::_pp_catfileFile::Spec::Unix::_pp_catfile
0000s0sFile::Spec::Unix::::_sameFile::Spec::Unix::_same
0000s0sFile::Spec::Unix::::abs2relFile::Spec::Unix::abs2rel
0000s0sFile::Spec::Unix::::case_tolerantFile::Spec::Unix::case_tolerant
0000s0sFile::Spec::Unix::::devnullFile::Spec::Unix::devnull
0000s0sFile::Spec::Unix::::joinFile::Spec::Unix::join
0000s0sFile::Spec::Unix::::no_upwardsFile::Spec::Unix::no_upwards
0000s0sFile::Spec::Unix::::rootdirFile::Spec::Unix::rootdir
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package File::Spec::Unix;
2
3217µs210µs
# spent 9µs (8+1) within File::Spec::Unix::BEGIN@3 which was called: # once (8µs+1µs) by main::BEGIN@16 at line 3
use strict;
# spent 9µs making 1 call to File::Spec::Unix::BEGIN@3 # spent 1µs making 1 call to strict::import
42261µs12µs
# spent 2µs within File::Spec::Unix::BEGIN@4 which was called: # once (2µs+0s) by main::BEGIN@16 at line 4
use Cwd ();
# spent 2µs making 1 call to File::Spec::Unix::BEGIN@4
5
61400nsour $VERSION = '3.75';
71700ns$VERSION =~ tr/_//d;
8
9=head1 NAME
10
11File::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
19Methods for manipulating file specifications. Other File::Spec
20modules, such as File::Spec::Mac, inherit from File::Spec::Unix and
21override specific methods.
22
23=head1 METHODS
24
25=over 2
26
27=item canonpath()
28
29No physical check on the filesystem, but a logical cleanup of a
30path. On UNIX eliminates successive slashes and successive "/.".
31
32 $cpath = File::Spec->canonpath( $path ) ;
33
34Note that this does *not* collapse F<x/../y> sections into F<y>. This
35is by design. If F</foo> on your system is a symlink to F</bar/baz>,
36then F</foo/../quux> is actually F</bar/quux>, not F</quux> as a naive
37F<../>-removal would give you. If you want to do this kind of
38processing, you probably want C<Cwd>'s C<realpath()> function to
39actually traverse the filesystem cleaning up paths like this.
40
41=cut
42
43sub _pp_canonpath {
44 my ($self,$path) = @_;
45 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 my $node = '';
52 my $double_slashes_special = $^O eq 'qnx' || $^O eq 'nto';
53
54
55 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 $path =~ s|/{2,}|/|g; # xx////xx -> xx/xx
65 $path =~ s{(?:/\.)+(?:/|\z)}{/}g; # xx/././xx -> xx/xx
66 $path =~ s|^(?:\./)+||s unless $path eq "./"; # ./xx -> xx
67 $path =~ s|^/(?:\.\./)+|/|; # /../../xx -> xx
68 $path =~ s|^/\.\.$|/|; # /.. -> /
69 $path =~ s|/\z|| unless $path eq "/"; # xx/ -> xx
70 return "$node$path";
71}
721400ns*canonpath = \&_pp_canonpath unless defined &canonpath;
73
74=item catdir()
75
76Concatenate two or more directory names to form a complete path ending
77with a directory. But remove the trailing slash from the resulting
78string, because it doesn't look good, isn't necessary and confuses
79OS2. Of course, if this is the root directory, don't cut off the
80trailing slash :-)
81
82=cut
83
84sub _pp_catdir {
85 my $self = shift;
86
87 $self->canonpath(join('/', @_, '')); # '' because need a trailing '/'
88}
891300ns*catdir = \&_pp_catdir unless defined &catdir;
90
91=item catfile
92
93Concatenate one or more directory names and a filename to form a
94complete path ending with a filename
95
96=cut
97
98sub _pp_catfile {
99 my $self = shift;
100 my $file = $self->canonpath(pop @_);
101 return $file unless @_;
102 my $dir = $self->catdir(@_);
103 $dir .= "/" unless substr($dir,-1) eq "/";
104 return $dir.$file;
105}
1061300ns*catfile = \&_pp_catfile unless defined &catfile;
107
108=item curdir
109
110Returns a string representation of the current directory. "." on UNIX.
111
112=cut
113
11439µs
# spent 3µs within File::Spec::Unix::curdir which was called 3 times, avg 1µs/call: # once (2µs+0s) by IPC::Cmd::can_run at line 21 of ExtUtils/MM_Any.pm # once (1µs+0s) by Module::Metadata::BEGIN@39 at line 775 of File/Find.pm # once (500ns+0s) by IPC::Cmd::can_run at line 104 of ExtUtils/MM_Unix.pm
sub curdir { '.' }
1152114µs21.03ms
# spent 997µs (886+110) within File::Spec::Unix::BEGIN@115 which was called: # once (886µs+110µs) by main::BEGIN@16 at line 115
use constant _fn_curdir => ".";
# spent 997µs making 1 call to File::Spec::Unix::BEGIN@115 # spent 30µs making 1 call to constant::import
116
117=item devnull
118
119Returns a string representation of the null device. "/dev/null" on UNIX.
120
121=cut
122
123sub devnull { '/dev/null' }
124225µs237µs
# spent 21µs (4+16) within File::Spec::Unix::BEGIN@124 which was called: # once (4µs+16µs) by main::BEGIN@16 at line 124
use constant _fn_devnull => "/dev/null";
# spent 21µs making 1 call to File::Spec::Unix::BEGIN@124 # spent 16µs making 1 call to constant::import
125
126=item rootdir
127
128Returns a string representation of the root directory. "/" on UNIX.
129
130=cut
131
132sub rootdir { '/' }
133291µs232µs
# spent 18µs (3+14) within File::Spec::Unix::BEGIN@133 which was called: # once (3µs+14µs) by main::BEGIN@16 at line 133
use constant _fn_rootdir => "/";
# spent 18µs making 1 call to File::Spec::Unix::BEGIN@133 # spent 14µs making 1 call to constant::import
134
135=item tmpdir
136
137Returns a string representation of the first writable directory from
138the following list or the current directory if none from the list are
139writable:
140
141 $ENV{TMPDIR}
142 /tmp
143
144If running under taint mode, and if $ENV{TMPDIR}
145is tainted, it is not used.
146
147=cut
148
1491200nsmy ($tmpdir, %tmpenv);
150# Cache and return the calculated tmpdir, recording which env vars
151# determined it.
152
# spent 3µs within File::Spec::Unix::_cache_tmpdir which was called: # once (3µs+0s) by File::Spec::Unix::tmpdir at line 199
sub _cache_tmpdir {
15312µs @tmpenv{@_[2..$#_]} = @ENV{@_[2..$#_]};
15414µs return $tmpdir = $_[1];
155}
156# Retrieve the cached tmpdir, checking first whether relevant env vars have
157# changed and invalidated the cache.
158
# spent 702ms within File::Spec::Unix::_cached_tmpdir which was called 133035 times, avg 5µs/call: # 133035 times (702ms+0s) by File::Spec::Unix::tmpdir at line 197, avg 5µs/call
sub _cached_tmpdir {
15913303525.0ms shift;
160133035147ms local $^W;
161133035266ms return if grep $ENV{$_} ne $tmpenv{$_}, @_;
162133035701ms return $tmpdir;
163}
164
# spent 28µs (15+13) within File::Spec::Unix::_tmpdir which was called: # once (15µs+13µs) by File::Spec::Unix::tmpdir at line 199
sub _tmpdir {
1651300ns my $self = shift;
16611µs my @dirlist = @_;
1674181µs213µs
# spent 9µs (6+4) within File::Spec::Unix::BEGIN@167 which was called: # once (6µs+4µs) by main::BEGIN@16 at line 167
my $taint = do { no strict 'refs'; ${"\cTAINT"} };
# spent 9µs making 1 call to File::Spec::Unix::BEGIN@167 # spent 4µs making 1 call to strict::unimport
1681400ns if ($taint) { # Check for taint mode on perl >= 5.8.0
169 require Scalar::Util;
170 @dirlist = grep { ! Scalar::Util::tainted($_) } @dirlist;
171 }
172 elsif ($] < 5.007) { # No ${^TAINT} before 5.8
173 @dirlist = grep { !defined($_) || eval { eval('1'.substr $_,0,0) } }
174 @dirlist;
175 }
176
1771600ns foreach (@dirlist) {
178212µs28µs next unless defined && -d && -w _;
# spent 4µs making 1 call to File::Spec::Unix::CORE:ftewrite # spent 3µs making 1 call to File::Spec::Unix::CORE:ftdir
1791200ns $tmpdir = $_;
1801400ns last;
181 }
1821100ns $tmpdir = $self->curdir unless defined $tmpdir;
18313µs11µs $tmpdir = defined $tmpdir && $self->canonpath($tmpdir);
# spent 1µs making 1 call to File::Spec::Unix::canonpath
18412µs14µs if ( !$self->file_name_is_absolute($tmpdir) ) {
# spent 4µs making 1 call to File::Spec::Unix::file_name_is_absolute
185 # See [perl #120593] for the full details
186 # If possible, return a full path, rather than '.' or 'lib', but
187 # jump through some hoops to avoid returning a tainted value.
188 ($tmpdir) = grep {
189 $taint ? ! Scalar::Util::tainted($_) :
190 $] < 5.007 ? eval { eval('1'.substr $_,0,0) } : 1
191 } $self->rel2abs($tmpdir), $tmpdir;
192 }
19314µs return $tmpdir;
194}
195
196
# spent 2.11s (1.41+702ms) within File::Spec::Unix::tmpdir which was called 133035 times, avg 16µs/call: # 133035 times (1.41s+702ms) by File::Temp::_wrap_file_spec_tmpdir at line 1521 of File/Temp.pm, avg 16µs/call
sub tmpdir {
197133035359ms133035702ms my $cached = $_[0]->_cached_tmpdir('TMPDIR');
# spent 702ms making 133035 calls to File::Spec::Unix::_cached_tmpdir, avg 5µs/call
198133035520ms return $cached if defined $cached;
19916µs231µs $_[0]->_cache_tmpdir($_[0]->_tmpdir( $ENV{TMPDIR}, "/tmp" ), 'TMPDIR');
# spent 28µs making 1 call to File::Spec::Unix::_tmpdir # spent 3µs making 1 call to File::Spec::Unix::_cache_tmpdir
200}
201
202=item updir
203
204Returns a string representation of the parent directory. ".." on UNIX.
205
206=cut
207
20812µs
# spent 1µs within File::Spec::Unix::updir which was called: # once (1µs+0s) by IPC::Cmd::can_run at line 105 of ExtUtils/MM_Unix.pm
sub updir { '..' }
209256µs242µs
# spent 23µs (4+19) within File::Spec::Unix::BEGIN@209 which was called: # once (4µs+19µs) by main::BEGIN@16 at line 209
use constant _fn_updir => "..";
# spent 23µs making 1 call to File::Spec::Unix::BEGIN@209 # spent 19µs making 1 call to constant::import
210
211=item no_upwards
212
213Given a list of file names, strip out those that refer to a parent
214directory. (Does not strip symlinks, only '.', '..', and equivalents.)
215
216=cut
217
218sub no_upwards {
219 my $self = shift;
220 return grep(!/^\.{1,2}\z/s, @_);
221}
222
223=item case_tolerant
224
225Returns a true or false value indicating, respectively, that alphabetic
226is not or is significant when comparing file specifications.
227
228=cut
229
230sub case_tolerant { 0 }
2312623µs237µs
# spent 20µs (4+16) within File::Spec::Unix::BEGIN@231 which was called: # once (4µs+16µs) by main::BEGIN@16 at line 231
use constant _fn_case_tolerant => 0;
# spent 20µs making 1 call to File::Spec::Unix::BEGIN@231 # spent 16µs making 1 call to constant::import
232
233=item file_name_is_absolute
234
235Takes as argument a path and returns true if it is an absolute path.
236
237This does not consult the local filesystem on Unix, Win32, OS/2 or Mac
238OS (Classic). It does consult the working environment for VMS (see
239L<File::Spec::VMS/file_name_is_absolute>).
240
241=cut
242
243
# spent 1.88s (1.46+428ms) within File::Spec::Unix::file_name_is_absolute which was called 133041 times, avg 14µs/call: # 133036 times (1.46s+428ms) by IPC::Run::_search_path at line 1164 of IPC/Run.pm, avg 14µs/call # once (4µs+1µs) by IPC::Cmd::can_run at line 240 of IPC/Cmd.pm # once (3µs+1µs) by File::Spec::Unix::_tmpdir at line 184 # once (3µs+600ns) by Data::Printer::Config::_project_home at line 66 of Data/Printer/Config.pm # once (3µs+300ns) by File::Spec::Unix::rel2abs at line 505 # once (1µs+400ns) by File::Spec::Unix::rel2abs at line 507
sub file_name_is_absolute {
244133041430ms my ($self,$file) = @_;
2451330411.53s133041428ms return scalar($file =~ m:^/:s);
# spent 428ms making 133041 calls to File::Spec::Unix::CORE:match, avg 3µs/call
246}
247
248=item path
249
250Takes no argument, returns the environment variable PATH as an array.
251
252=cut
253
254
# spent 12µs within File::Spec::Unix::path which was called: # once (12µs+0s) by IPC::Cmd::can_run at line 244 of IPC/Cmd.pm
sub path {
2551800ns return () unless exists $ENV{PATH};
25614µs my @path = split(':', $ENV{PATH});
257284µs foreach (@path) { $_ = '.' if $_ eq '' }
25816µs return @path;
259}
260
261=item join
262
263join is the same as catfile.
264
265=cut
266
267sub join {
268 my $self = shift;
269 return $self->catfile(@_);
270}
271
272=item splitpath
273
274 ($volume,$directories,$file) = File::Spec->splitpath( $path );
275 ($volume,$directories,$file) = File::Spec->splitpath( $path,
276 $no_file );
277
278Splits a path into volume, directory, and filename portions. On systems
279with no concept of volume, returns '' for volume.
280
281For systems with no syntax differentiating filenames from directories,
282assumes that the last file is a path unless $no_file is true or a
283trailing separator or /. or /.. is present. On Unix this means that $no_file
284true makes this return ( '', $path, '' ).
285
286The directory portion may or may not be returned with a trailing '/'.
287
288The results can be passed to L</catpath()> to get back a path equivalent to
289(usually identical to) the original path.
290
291=cut
292
293
# spent 2.73s (2.37+362ms) within File::Spec::Unix::splitpath which was called 133035 times, avg 21µs/call: # 133035 times (2.37s+362ms) by File::Temp::_gettemp at line 441 of File/Temp.pm, avg 21µs/call
sub splitpath {
29413303576.4ms my ($self,$path, $nofile) = @_;
295
296133035131ms my ($volume,$directory,$file) = ('','','');
297
29813303532.1ms if ( $nofile ) {
299 $directory = $path;
300 }
301 else {
302133035751ms133035362ms $path =~ m|^ ( (?: .* / (?: \.\.?\z )? )? ) ([^/]*) |xs;
# spent 362ms making 133035 calls to File::Spec::Unix::CORE:match, avg 3µs/call
303133035675ms $directory = $1;
304133035638ms $file = $2;
305 }
306
307133035443ms return ($volume,$directory,$file);
308}
309
310
311=item splitdir
312
313The opposite of L</catdir()>.
314
315 @dirs = File::Spec->splitdir( $directories );
316
317$directories must be only the directory portion of the path on systems
318that have the concept of a volume or that have path syntax that differentiates
319files from directories.
320
321Unlike just splitting the directories on the separator, empty
322directory names (C<''>) can be returned, because these are significant
323on some OSs.
324
325On Unix,
326
327 File::Spec->splitdir( "/a/b//c/" );
328
329Yields:
330
331 ( '', 'a', 'b', '', 'c', '' )
332
333=cut
334
335
# spent 6µs within File::Spec::Unix::splitdir which was called 8 times, avg 725ns/call: # 8 times (6µs+0s) by Data::Printer::Config::_get_first_rc_file_available at line 35 of Data/Printer/Config.pm, avg 725ns/call
sub splitdir {
33689µs return split m|/|, $_[1], -1; # Preserve trailing fields
337}
338
339
340=item catpath()
341
342Takes volume, directory and file portions and returns an entire path. Under
343Unix, $volume is ignored, and directory and file are concatenated. A '/' is
344inserted if needed (though if the directory portion doesn't start with
345'/' it is not added). On other OSs, $volume is significant.
346
347=cut
348
349
# spent 777ms within File::Spec::Unix::catpath which was called 133035 times, avg 6µs/call: # 133035 times (777ms+0s) by File::Temp::_gettemp at line 444 of File/Temp.pm, avg 6µs/call
sub catpath {
350133035255ms my ($self,$volume,$directory,$file) = @_;
351
352133035113ms if ( $directory ne '' &&
353 $file ne '' &&
354 substr( $directory, -1 ) ne '/' &&
355 substr( $file, 0, 1 ) ne '/'
356 ) {
357 $directory .= "/$file" ;
358 }
359 else {
36013303527.2ms $directory .= $file ;
361 }
362
363133035403ms return $directory ;
364}
365
366=item abs2rel
367
368Takes a destination path and an optional base path returns a relative path
369from the base path to the destination path:
370
371 $rel_path = File::Spec->abs2rel( $path ) ;
372 $rel_path = File::Spec->abs2rel( $path, $base ) ;
373
374If $base is not present or '', then L<cwd()|Cwd> is used. If $base is
375relative, then it is converted to absolute form using
376L</rel2abs()>. This means that it is taken to be relative to
377L<cwd()|Cwd>.
378
379On systems that have a grammar that indicates filenames, this ignores the
380$base filename. Otherwise all path components are assumed to be
381directories.
382
383If $path is relative, it is converted to absolute form using L</rel2abs()>.
384This means that it is taken to be relative to L<cwd()|Cwd>.
385
386No checks against the filesystem are made, so the result may not be correct if
387C<$base> contains symbolic links. (Apply
388L<Cwd::abs_path()|Cwd/abs_path> beforehand if that
389is a concern.) On VMS, there is interaction with the working environment, as
390logicals and macros are expanded.
391
392Based on code written by Shigio Yamaguchi.
393
394=cut
395
396sub abs2rel {
397 my($self,$path,$base) = @_;
398 $base = Cwd::getcwd() unless defined $base and length $base;
399
400 ($path, $base) = map $self->canonpath($_), $path, $base;
401
402 my $path_directories;
403 my $base_directories;
404
405 if (grep $self->file_name_is_absolute($_), $path, $base) {
406 ($path, $base) = map $self->rel2abs($_), $path, $base;
407
408 my ($path_volume) = $self->splitpath($path, 1);
409 my ($base_volume) = $self->splitpath($base, 1);
410
411 # Can't relativize across volumes
412 return $path unless $path_volume eq $base_volume;
413
414 $path_directories = ($self->splitpath($path, 1))[1];
415 $base_directories = ($self->splitpath($base, 1))[1];
416
417 # For UNC paths, the user might give a volume like //foo/bar that
418 # strictly speaking has no directory portion. Treat it as if it
419 # had the root directory for that volume.
420 if (!length($base_directories) and $self->file_name_is_absolute($base)) {
421 $base_directories = $self->rootdir;
422 }
423 }
424 else {
425 my $wd= ($self->splitpath(Cwd::getcwd(), 1))[1];
426 $path_directories = $self->catdir($wd, $path);
427 $base_directories = $self->catdir($wd, $base);
428 }
429
430 # Now, remove all leading components that are the same
431 my @pathchunks = $self->splitdir( $path_directories );
432 my @basechunks = $self->splitdir( $base_directories );
433
434 if ($base_directories eq $self->rootdir) {
435 return $self->curdir if $path_directories eq $self->rootdir;
436 shift @pathchunks;
437 return $self->canonpath( $self->catpath('', $self->catdir( @pathchunks ), '') );
438 }
439
440 my @common;
441 while (@pathchunks && @basechunks && $self->_same($pathchunks[0], $basechunks[0])) {
442 push @common, shift @pathchunks ;
443 shift @basechunks ;
444 }
445 return $self->curdir unless @pathchunks || @basechunks;
446
447 # @basechunks now contains the directories the resulting relative path
448 # must ascend out of before it can descend to $path_directory. If there
449 # are updir components, we must descend into the corresponding directories
450 # (this only works if they are no symlinks).
451 my @reverse_base;
452 while( defined(my $dir= shift @basechunks) ) {
453 if( $dir ne $self->updir ) {
454 unshift @reverse_base, $self->updir;
455 push @common, $dir;
456 }
457 elsif( @common ) {
458 if( @reverse_base && $reverse_base[0] eq $self->updir ) {
459 shift @reverse_base;
460 pop @common;
461 }
462 else {
463 unshift @reverse_base, pop @common;
464 }
465 }
466 }
467 my $result_dirs = $self->catdir( @reverse_base, @pathchunks );
468 return $self->canonpath( $self->catpath('', $result_dirs, '') );
469}
470
471sub _same {
472 $_[1] eq $_[2];
473}
474
475=item rel2abs()
476
477Converts a relative path to an absolute path.
478
479 $abs_path = File::Spec->rel2abs( $path ) ;
480 $abs_path = File::Spec->rel2abs( $path, $base ) ;
481
482If $base is not present or '', then L<cwd()|Cwd> is used. If $base is
483relative, then it is converted to absolute form using
484L</rel2abs()>. This means that it is taken to be relative to
485L<cwd()|Cwd>.
486
487On systems that have a grammar that indicates filenames, this ignores
488the $base filename. Otherwise all path components are assumed to be
489directories.
490
491If $path is absolute, it is cleaned up and returned using L</canonpath()>.
492
493No checks against the filesystem are made. On VMS, there is
494interaction with the working environment, as logicals and
495macros are expanded.
496
497Based on code written by Shigio Yamaguchi.
498
499=cut
500
501
# spent 30µs (16+13) within File::Spec::Unix::rel2abs which was called: # once (16µs+13µs) by main::BEGIN@35 at line 36 of /home/hejohns/documentsNoSync/22f/490/gradescope-utils/bin/split.pl
sub rel2abs {
5021600ns my ($self,$path,$base ) = @_;
503
504 # Clean up $path
50513µs14µs if ( ! $self->file_name_is_absolute( $path ) ) {
# spent 4µs making 1 call to File::Spec::Unix::file_name_is_absolute
506 # Figure out the effective $base and clean it up.
50712µs12µs if ( !defined( $base ) || $base eq '' ) {
# spent 2µs making 1 call to File::Spec::Unix::file_name_is_absolute
508 $base = Cwd::getcwd();
509 }
510 elsif ( ! $self->file_name_is_absolute( $base ) ) {
511 $base = $self->rel2abs( $base ) ;
512 }
513 else {
51416µs12µs $base = $self->canonpath( $base ) ;
# spent 2µs making 1 call to File::Spec::Unix::canonpath
515 }
516
517 # Glom them together
51818µs26µs $path = $self->catdir( $base, $path ) ;
# spent 6µs making 1 call to File::Spec::Unix::catdir # spent 600ns making 1 call to File::Spec::Unix::canonpath
519 }
520
52113µs1400ns return $self->canonpath( $path ) ;
# spent 400ns making 1 call to File::Spec::Unix::canonpath
522}
523
524=back
525
526=head1 COPYRIGHT
527
528Copyright (c) 2004 by the Perl 5 Porters. All rights reserved.
529
530This program is free software; you can redistribute it and/or modify
531it under the same terms as Perl itself.
532
533Please submit bug reports and patches to perlbug@perl.org.
534
535=head1 SEE ALSO
536
537L<File::Spec>
538
539=cut
540
541# Internal method to reduce xx\..\yy -> yy
542sub _collapse {
543 my($fs, $path) = @_;
544
545 my $updir = $fs->updir;
546 my $curdir = $fs->curdir;
547
548 my($vol, $dirs, $file) = $fs->splitpath($path);
549 my @dirs = $fs->splitdir($dirs);
550 pop @dirs if @dirs && $dirs[-1] eq '';
551
552 my @collapsed;
553 foreach my $dir (@dirs) {
554 if( $dir eq $updir and # if we have an updir
555 @collapsed and # and something to collapse
556 length $collapsed[-1] and # and its not the rootdir
557 $collapsed[-1] ne $updir and # nor another updir
558 $collapsed[-1] ne $curdir # nor the curdir
559 )
560 { # then
561 pop @collapsed; # collapse
562 }
563 else { # else
564 push @collapsed, $dir; # just hang onto it
565 }
566 }
567
568 return $fs->catpath($vol,
569 $fs->catdir(@collapsed),
570 $file
571 );
572}
573
574
57516µs1;
 
# spent 3µs within File::Spec::Unix::CORE:ftdir which was called: # once (3µs+0s) by File::Spec::Unix::_tmpdir at line 178
sub File::Spec::Unix::CORE:ftdir; # opcode
# spent 4µs within File::Spec::Unix::CORE:ftewrite which was called: # once (4µs+0s) by File::Spec::Unix::_tmpdir at line 178
sub File::Spec::Unix::CORE:ftewrite; # opcode
# spent 789ms within File::Spec::Unix::CORE:match which was called 266076 times, avg 3µs/call: # 133041 times (428ms+0s) by File::Spec::Unix::file_name_is_absolute at line 245, avg 3µs/call # 133035 times (362ms+0s) by File::Spec::Unix::splitpath at line 302, avg 3µs/call
sub File::Spec::Unix::CORE:match; # opcode
# spent 175ms within File::Spec::Unix::canonpath which was called 266170 times, avg 657ns/call: # 266070 times (175ms+0s) by File::Spec::Unix::catdir or File::Spec::Unix::catfile at line 1450 of File/Temp.pm, avg 657ns/call # 54 times (9µs+0s) by File::Spec::Unix::catdir or File::Spec::Unix::catfile at line 249 of IPC/Cmd.pm, avg 169ns/call # 16 times (3µs+0s) by File::Spec::Unix::catdir or File::Spec::Unix::catfile at line 33 of Data/Printer/Config.pm, avg 188ns/call # 14 times (10µs+0s) by File::Spec::Unix::catdir or File::Spec::Unix::catfile at line 1218 of IPC/Run.pm, avg 714ns/call # 8 times (2µs+0s) by File::Spec::Unix::catdir at line 37 of Data/Printer/Config.pm, avg 212ns/call # 2 times (1µs+0s) by File::Spec::Unix::catdir or File::Spec::Unix::catfile at line 66 of Data/Printer/Config.pm, avg 550ns/call # 2 times (400ns+0s) by File::Spec::Unix::catdir or File::Spec::Unix::catfile at line 42 of Data/Printer/Config.pm, avg 200ns/call # once (2µs+0s) by File::Spec::Unix::rel2abs at line 514 # once (1µs+0s) by File::Spec::Unix::_tmpdir at line 183 # once (600ns+0s) by File::Spec::Unix::catdir at line 518 # once (400ns+0s) by File::Spec::Unix::rel2abs at line 521
sub File::Spec::Unix::canonpath; # xsub
# spent 562ms (501+60.9) within File::Spec::Unix::catdir which was called 133088 times, avg 4µs/call: # 133035 times (501ms+60.8ms) by File::Spec::Unix::catfile at line 1450 of File/Temp.pm, avg 4µs/call # 27 times (25µs+5µs) by File::Spec::Unix::catfile at line 249 of IPC/Cmd.pm, avg 1µs/call # 8 times (10µs+2µs) by Data::Printer::Config::_get_first_rc_file_available at line 37 of Data/Printer/Config.pm, avg 1µs/call # 8 times (8µs+2µs) by File::Spec::Unix::catfile at line 33 of Data/Printer/Config.pm, avg 1µs/call # 7 times (23µs+5µs) by File::Spec::Unix::catfile at line 1218 of IPC/Run.pm, avg 4µs/call # once (5µs+600ns) by File::Spec::Unix::rel2abs at line 518 # once (2µs+300ns) by File::Spec::Unix::catfile at line 66 of Data/Printer/Config.pm # once (2µs+200ns) by File::Spec::Unix::catfile at line 42 of Data/Printer/Config.pm
sub File::Spec::Unix::catdir; # xsub
# spent 1.91s (1.23+676ms) within File::Spec::Unix::catfile which was called 133079 times, avg 14µs/call: # 133035 times (1.23s+676ms) by File::Temp::tempfile at line 1450 of File/Temp.pm, avg 14µs/call # 27 times (47µs+34µs) by IPC::Cmd::can_run at line 249 of IPC/Cmd.pm, avg 3µs/call # 8 times (14µs+11µs) by Data::Printer::Config::_get_first_rc_file_available at line 33 of Data/Printer/Config.pm, avg 3µs/call # 7 times (51µs+33µs) by IPC::Run::_search_path at line 1218 of IPC/Run.pm, avg 12µs/call # once (6µs+3µs) by Data::Printer::Config::_project_home at line 66 of Data/Printer/Config.pm # once (3µs+2µs) by Data::Printer::Config::_get_first_rc_file_available at line 42 of Data/Printer/Config.pm
sub File::Spec::Unix::catfile; # xsub