Filename | /usr/lib/perl/5.14/File/Spec/Unix.pm |
Statements | Executed 19 statements in 3.02ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 29µs | 36µs | BEGIN@3 | File::Spec::Unix::
1 | 1 | 1 | 25µs | 32µs | splitpath | File::Spec::Unix::
1 | 1 | 1 | 15µs | 40µs | BEGIN@65 | File::Spec::Unix::
1 | 1 | 1 | 13µs | 53µs | BEGIN@4 | File::Spec::Unix::
1 | 1 | 1 | 7µs | 7µs | CORE:match (opcode) | File::Spec::Unix::
1 | 1 | 1 | 6µs | 6µs | splitdir | File::Spec::Unix::
1 | 1 | 1 | 4µs | 4µs | curdir | 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 | canonpath | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | case_tolerant | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | catdir | 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 | devnull | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | file_name_is_absolute | 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 | rel2abs | File::Spec::Unix::
0 | 0 | 0 | 0s | 0s | rootdir | 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 | 56µs | 2 | 42µs | # spent 36µs (29+7) within File::Spec::Unix::BEGIN@3 which was called:
# once (29µs+7µs) by DateTime::TimeZone::Local::BEGIN@14 at line 3 # spent 36µs making 1 call to File::Spec::Unix::BEGIN@3
# spent 7µs making 1 call to strict::import |
4 | 2 | 786µs | 2 | 93µs | # spent 53µs (13+40) within File::Spec::Unix::BEGIN@4 which was called:
# once (13µs+40µs) by DateTime::TimeZone::Local::BEGIN@14 at line 4 # spent 53µs making 1 call to File::Spec::Unix::BEGIN@4
# spent 40µs making 1 call to vars::import |
5 | |||||
6 | 1 | 1µs | $VERSION = '3.33'; | ||
7 | 1 | 31µs | $VERSION = eval $VERSION; # spent 5µs executing statements in string eval | ||
8 | |||||
9 | sub canonpath { | ||||
10 | my ($self,$path) = @_; | ||||
11 | 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 | my $node = ''; | ||||
18 | my $double_slashes_special = $^O eq 'qnx' || $^O eq 'nto'; | ||||
19 | |||||
20 | 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 | $path =~ s|/{2,}|/|g; # xx////xx -> xx/xx | ||||
30 | $path =~ s{(?:/\.)+(?:/|\z)}{/}g; # xx/././xx -> xx/xx | ||||
31 | $path =~ s|^(?:\./)+||s unless $path eq "./"; # ./xx -> xx | ||||
32 | $path =~ s|^/(?:\.\./)+|/|; # /../../xx -> xx | ||||
33 | $path =~ s|^/\.\.$|/|; # /.. -> / | ||||
34 | $path =~ s|/\z|| unless $path eq "/"; # xx/ -> xx | ||||
35 | return "$node$path"; | ||||
36 | } | ||||
37 | |||||
38 | sub catdir { | ||||
39 | my $self = shift; | ||||
40 | |||||
41 | $self->canonpath(join('/', @_, '')); # '' because need a trailing '/' | ||||
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 | 1 | 8µs | # spent 4µs within File::Spec::Unix::curdir which was called:
# once (4µs+0s) by DateTime::TimeZone::Local::Unix::_FindMatchingZoneinfoFile at line 1094 of File/Find.pm | ||
54 | |||||
55 | sub devnull { '/dev/null' } | ||||
56 | |||||
57 | sub rootdir { '/' } | ||||
58 | |||||
59 | 1 | 400ns | my $tmpdir; | ||
60 | sub _tmpdir { | ||||
61 | return $tmpdir if defined $tmpdir; | ||||
62 | my $self = shift; | ||||
63 | my @dirlist = @_; | ||||
64 | { | ||||
65 | 2 | 2.09ms | 2 | 65µs | # spent 40µs (15+25) within File::Spec::Unix::BEGIN@65 which was called:
# once (15µs+25µs) by DateTime::TimeZone::Local::BEGIN@14 at line 65 # spent 40µs making 1 call to File::Spec::Unix::BEGIN@65
# spent 25µ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 | } | ||||
71 | foreach (@dirlist) { | ||||
72 | next unless defined && -d && -w _; | ||||
73 | $tmpdir = $_; | ||||
74 | last; | ||||
75 | } | ||||
76 | $tmpdir = $self->curdir unless defined $tmpdir; | ||||
77 | $tmpdir = defined $tmpdir && $self->canonpath($tmpdir); | ||||
78 | return $tmpdir; | ||||
79 | } | ||||
80 | |||||
81 | sub tmpdir { | ||||
82 | return $tmpdir if defined $tmpdir; | ||||
83 | $tmpdir = $_[0]->_tmpdir( $ENV{TMPDIR}, "/tmp" ); | ||||
84 | } | ||||
85 | |||||
86 | sub updir { '..' } | ||||
87 | |||||
88 | sub no_upwards { | ||||
89 | my $self = shift; | ||||
90 | return grep(!/^\.{1,2}\z/s, @_); | ||||
91 | } | ||||
92 | |||||
93 | sub case_tolerant { 0 } | ||||
94 | |||||
95 | sub file_name_is_absolute { | ||||
96 | my ($self,$file) = @_; | ||||
97 | return scalar($file =~ m:^/:s); | ||||
98 | } | ||||
99 | |||||
100 | sub path { | ||||
101 | return () unless exists $ENV{PATH}; | ||||
102 | my @path = split(':', $ENV{PATH}); | ||||
103 | foreach (@path) { $_ = '.' if $_ eq '' } | ||||
104 | return @path; | ||||
105 | } | ||||
106 | |||||
107 | sub join { | ||||
108 | my $self = shift; | ||||
109 | return $self->catfile(@_); | ||||
110 | } | ||||
111 | |||||
112 | # spent 32µs (25+7) within File::Spec::Unix::splitpath which was called:
# once (25µs+7µs) by DateTime::TimeZone::Local::Unix::FromEtcLocaltime at line 45 of DateTime/TimeZone/Local/Unix.pm | ||||
113 | 4 | 13µs | my ($self,$path, $nofile) = @_; | ||
114 | |||||
115 | my ($volume,$directory,$file) = ('','',''); | ||||
116 | |||||
117 | 3 | 21µs | if ( $nofile ) { | ||
118 | $directory = $path; | ||||
119 | } | ||||
120 | else { | ||||
121 | 1 | 7µs | $path =~ m|^ ( (?: .* / (?: \.\.?\z )? )? ) ([^/]*) |xs; # spent 7µs making 1 call to File::Spec::Unix::CORE:match | ||
122 | $directory = $1; | ||||
123 | $file = $2; | ||||
124 | } | ||||
125 | |||||
126 | return ($volume,$directory,$file); | ||||
127 | } | ||||
128 | |||||
129 | # spent 6µs within File::Spec::Unix::splitdir which was called:
# once (6µs+0s) by DateTime::TimeZone::Local::Unix::FromEtcLocaltime at line 48 of DateTime/TimeZone/Local/Unix.pm | ||||
130 | 1 | 10µs | return split m|/|, $_[1], -1; # Preserve trailing fields | ||
131 | } | ||||
132 | |||||
133 | sub catpath { | ||||
134 | my ($self,$volume,$directory,$file) = @_; | ||||
135 | |||||
136 | if ( $directory ne '' && | ||||
137 | $file ne '' && | ||||
138 | substr( $directory, -1 ) ne '/' && | ||||
139 | substr( $file, 0, 1 ) ne '/' | ||||
140 | ) { | ||||
141 | $directory .= "/$file" ; | ||||
142 | } | ||||
143 | else { | ||||
144 | $directory .= $file ; | ||||
145 | } | ||||
146 | |||||
147 | return $directory ; | ||||
148 | } | ||||
149 | |||||
150 | sub abs2rel { | ||||
151 | my($self,$path,$base) = @_; | ||||
152 | $base = $self->_cwd() unless defined $base and length $base; | ||||
153 | |||||
154 | ($path, $base) = map $self->canonpath($_), $path, $base; | ||||
155 | |||||
156 | if (grep $self->file_name_is_absolute($_), $path, $base) { | ||||
157 | ($path, $base) = map $self->rel2abs($_), $path, $base; | ||||
158 | } | ||||
159 | else { | ||||
160 | # save a couple of cwd()s if both paths are relative | ||||
161 | ($path, $base) = map $self->catdir('/', $_), $path, $base; | ||||
162 | } | ||||
163 | |||||
164 | my ($path_volume) = $self->splitpath($path, 1); | ||||
165 | my ($base_volume) = $self->splitpath($base, 1); | ||||
166 | |||||
167 | # Can't relativize across volumes | ||||
168 | return $path unless $path_volume eq $base_volume; | ||||
169 | |||||
170 | my $path_directories = ($self->splitpath($path, 1))[1]; | ||||
171 | my $base_directories = ($self->splitpath($base, 1))[1]; | ||||
172 | |||||
173 | # For UNC paths, the user might give a volume like //foo/bar that | ||||
174 | # strictly speaking has no directory portion. Treat it as if it | ||||
175 | # had the root directory for that volume. | ||||
176 | if (!length($base_directories) and $self->file_name_is_absolute($base)) { | ||||
177 | $base_directories = $self->rootdir; | ||||
178 | } | ||||
179 | |||||
180 | # Now, remove all leading components that are the same | ||||
181 | my @pathchunks = $self->splitdir( $path_directories ); | ||||
182 | my @basechunks = $self->splitdir( $base_directories ); | ||||
183 | |||||
184 | if ($base_directories eq $self->rootdir) { | ||||
185 | shift @pathchunks; | ||||
186 | return $self->canonpath( $self->catpath('', $self->catdir( @pathchunks ), '') ); | ||||
187 | } | ||||
188 | |||||
189 | while (@pathchunks && @basechunks && $self->_same($pathchunks[0], $basechunks[0])) { | ||||
190 | shift @pathchunks ; | ||||
191 | shift @basechunks ; | ||||
192 | } | ||||
193 | return $self->curdir unless @pathchunks || @basechunks; | ||||
194 | |||||
195 | # $base now contains the directories the resulting relative path | ||||
196 | # must ascend out of before it can descend to $path_directory. | ||||
197 | my $result_dirs = $self->catdir( ($self->updir) x @basechunks, @pathchunks ); | ||||
198 | return $self->canonpath( $self->catpath('', $result_dirs, '') ); | ||||
199 | } | ||||
200 | |||||
201 | sub _same { | ||||
202 | $_[1] eq $_[2]; | ||||
203 | } | ||||
204 | |||||
205 | sub rel2abs { | ||||
206 | my ($self,$path,$base ) = @_; | ||||
207 | |||||
208 | # Clean up $path | ||||
209 | if ( ! $self->file_name_is_absolute( $path ) ) { | ||||
210 | # Figure out the effective $base and clean it up. | ||||
211 | if ( !defined( $base ) || $base eq '' ) { | ||||
212 | $base = $self->_cwd(); | ||||
213 | } | ||||
214 | elsif ( ! $self->file_name_is_absolute( $base ) ) { | ||||
215 | $base = $self->rel2abs( $base ) ; | ||||
216 | } | ||||
217 | else { | ||||
218 | $base = $self->canonpath( $base ) ; | ||||
219 | } | ||||
220 | |||||
221 | # Glom them together | ||||
222 | $path = $self->catdir( $base, $path ) ; | ||||
223 | } | ||||
224 | |||||
225 | return $self->canonpath( $path ) ; | ||||
226 | } | ||||
227 | |||||
228 | # Internal routine to File::Spec, no point in making this public since | ||||
229 | # it is the standard Cwd interface. Most of the platform-specific | ||||
230 | # File::Spec subclasses use this. | ||||
231 | sub _cwd { | ||||
232 | require Cwd; | ||||
233 | Cwd::getcwd(); | ||||
234 | } | ||||
235 | |||||
236 | # Internal method to reduce xx\..\yy -> yy | ||||
237 | sub _collapse { | ||||
238 | my($fs, $path) = @_; | ||||
239 | |||||
240 | my $updir = $fs->updir; | ||||
241 | my $curdir = $fs->curdir; | ||||
242 | |||||
243 | my($vol, $dirs, $file) = $fs->splitpath($path); | ||||
244 | my @dirs = $fs->splitdir($dirs); | ||||
245 | pop @dirs if @dirs && $dirs[-1] eq ''; | ||||
246 | |||||
247 | my @collapsed; | ||||
248 | foreach my $dir (@dirs) { | ||||
249 | if( $dir eq $updir and # if we have an updir | ||||
250 | @collapsed and # and something to collapse | ||||
251 | length $collapsed[-1] and # and its not the rootdir | ||||
252 | $collapsed[-1] ne $updir and # nor another updir | ||||
253 | $collapsed[-1] ne $curdir # nor the curdir | ||||
254 | ) | ||||
255 | { # then | ||||
256 | pop @collapsed; # collapse | ||||
257 | } | ||||
258 | else { # else | ||||
259 | push @collapsed, $dir; # just hang onto it | ||||
260 | } | ||||
261 | } | ||||
262 | |||||
263 | return $fs->catpath($vol, | ||||
264 | $fs->catdir(@collapsed), | ||||
265 | $file | ||||
266 | ); | ||||
267 | } | ||||
268 | |||||
269 | 1 | 6µs | 1; | ||
# spent 7µs within File::Spec::Unix::CORE:match which was called:
# once (7µs+0s) by File::Spec::Unix::splitpath at line 121 |