Filename | C:/tmp64ng/perl/lib/File/Spec/Win32.pm |
Statements | Executed 7137 statements in 46.8ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
360 | 5 | 2 | 31.2ms | 31.2ms | splitpath | File::Spec::Win32::
873 | 8 | 1 | 15.6ms | 15.6ms | CORE:match (opcode) | File::Spec::Win32::
1 | 1 | 1 | 0s | 0s | BEGIN@3 | File::Spec::Win32::
1 | 1 | 1 | 0s | 0s | BEGIN@5 | File::Spec::Win32::
575 | 5 | 1 | 0s | 0s | CORE:regcomp (opcode) | File::Spec::Win32::
2233 | 8 | 1 | 0s | 0s | CORE:subst (opcode) | File::Spec::Win32::
269 | 3 | 1 | 0s | 15.6ms | _canon_cat | File::Spec::Win32::
0 | 0 | 0 | 0s | 0s | _same | File::Spec::Win32::
92 | 4 | 2 | 0s | 0s | canonpath | File::Spec::Win32::
0 | 0 | 0 | 0s | 0s | case_tolerant | File::Spec::Win32::
90 | 22 | 3 | 0s | 0s | catdir | File::Spec::Win32::
87 | 3 | 3 | 0s | 15.6ms | catfile | File::Spec::Win32::
0 | 0 | 0 | 0s | 0s | catpath | File::Spec::Win32::
0 | 0 | 0 | 0s | 0s | devnull | File::Spec::Win32::
22 | 3 | 2 | 0s | 0s | file_name_is_absolute | File::Spec::Win32::
3 | 1 | 1 | 0s | 0s | path | File::Spec::Win32::
0 | 0 | 0 | 0s | 0s | rel2abs | File::Spec::Win32::
2 | 2 | 2 | 0s | 0s | rootdir | File::Spec::Win32::
15 | 1 | 1 | 0s | 0s | splitdir | File::Spec::Win32::
0 | 0 | 0 | 0s | 0s | tmpdir | File::Spec::Win32::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package File::Spec::Win32; | ||||
2 | |||||
3 | 2 | 0s | 2 | 0s | # spent 0s within File::Spec::Win32::BEGIN@3 which was called:
# once (0s+0s) by File::Path::BEGIN@8 at line 3 # spent 0s making 1 call to File::Spec::Win32::BEGIN@3
# spent 0s making 1 call to strict::import |
4 | |||||
5 | 2 | 0s | 2 | 0s | # spent 0s within File::Spec::Win32::BEGIN@5 which was called:
# once (0s+0s) by File::Path::BEGIN@8 at line 5 # spent 0s making 1 call to File::Spec::Win32::BEGIN@5
# spent 0s making 1 call to vars::import |
6 | 1 | 0s | require File::Spec::Unix; | ||
7 | |||||
8 | 1 | 0s | $VERSION = '3.48_01'; | ||
9 | 1 | 0s | $VERSION =~ tr/_//; | ||
10 | |||||
11 | 1 | 0s | @ISA = qw(File::Spec::Unix); | ||
12 | |||||
13 | # Some regexes we use for path splitting | ||||
14 | 1 | 0s | my $DRIVE_RX = '[a-zA-Z]:'; | ||
15 | 1 | 0s | my $UNC_RX = '(?:\\\\\\\\|//)[^\\\\/]+[\\\\/][^\\\\/]+'; | ||
16 | 1 | 0s | my $VOL_RX = "(?:$DRIVE_RX|$UNC_RX)"; | ||
17 | |||||
18 | |||||
19 | =head1 NAME | ||||
20 | |||||
21 | File::Spec::Win32 - methods for Win32 file specs | ||||
22 | |||||
23 | =head1 SYNOPSIS | ||||
24 | |||||
25 | require File::Spec::Win32; # Done internally by File::Spec if needed | ||||
26 | |||||
27 | =head1 DESCRIPTION | ||||
28 | |||||
29 | See File::Spec::Unix for a documentation of the methods provided | ||||
30 | there. This package overrides the implementation of these methods, not | ||||
31 | the semantics. | ||||
32 | |||||
33 | =over 4 | ||||
34 | |||||
35 | =item devnull | ||||
36 | |||||
37 | Returns a string representation of the null device. | ||||
38 | |||||
39 | =cut | ||||
40 | |||||
41 | sub devnull { | ||||
42 | return "nul"; | ||||
43 | } | ||||
44 | |||||
45 | 2 | 0s | # spent 0s within File::Spec::Win32::rootdir which was called 2 times, avg 0s/call:
# once (0s+0s) by main::BEGIN@1 at line 20 of ExtUtils/MM_Any.pm
# once (0s+0s) by main::BEGIN@1 at line 101 of ExtUtils/MM_Unix.pm | ||
46 | |||||
47 | |||||
48 | =item tmpdir | ||||
49 | |||||
50 | Returns a string representation of the first existing directory | ||||
51 | from the following list: | ||||
52 | |||||
53 | $ENV{TMPDIR} | ||||
54 | $ENV{TEMP} | ||||
55 | $ENV{TMP} | ||||
56 | SYS:/temp | ||||
57 | C:\system\temp | ||||
58 | C:/temp | ||||
59 | /tmp | ||||
60 | / | ||||
61 | |||||
62 | The SYS:/temp is preferred in Novell NetWare and the C:\system\temp | ||||
63 | for Symbian (the File::Spec::Win32 is used also for those platforms). | ||||
64 | |||||
65 | If running under taint mode, and if the environment | ||||
66 | variables are tainted, they are not used. | ||||
67 | |||||
68 | =cut | ||||
69 | |||||
70 | sub tmpdir { | ||||
71 | my $tmpdir = $_[0]->_cached_tmpdir(qw(TMPDIR TEMP TMP)); | ||||
72 | return $tmpdir if defined $tmpdir; | ||||
73 | $tmpdir = $_[0]->_tmpdir( map( $ENV{$_}, qw(TMPDIR TEMP TMP) ), | ||||
74 | 'SYS:/temp', | ||||
75 | 'C:\system\temp', | ||||
76 | 'C:/temp', | ||||
77 | '/tmp', | ||||
78 | '/' ); | ||||
79 | $_[0]->_cache_tmpdir($tmpdir, qw(TMPDIR TEMP TMP)); | ||||
80 | } | ||||
81 | |||||
82 | =item case_tolerant | ||||
83 | |||||
84 | MSWin32 case-tolerance depends on GetVolumeInformation() $ouFsFlags == FS_CASE_SENSITIVE, | ||||
85 | indicating the case significance when comparing file specifications. | ||||
86 | Since XP FS_CASE_SENSITIVE is effectively disabled for the NT subsubsystem. | ||||
87 | See http://cygwin.com/ml/cygwin/2007-07/msg00891.html | ||||
88 | Default: 1 | ||||
89 | |||||
90 | =cut | ||||
91 | |||||
92 | sub case_tolerant { | ||||
93 | eval { require Win32API::File; } or return 1; | ||||
94 | my $drive = shift || "C:"; | ||||
95 | my $osFsType = "\0"x256; | ||||
96 | my $osVolName = "\0"x256; | ||||
97 | my $ouFsFlags = 0; | ||||
98 | Win32API::File::GetVolumeInformation($drive, $osVolName, 256, [], [], $ouFsFlags, $osFsType, 256 ); | ||||
99 | if ($ouFsFlags & Win32API::File::FS_CASE_SENSITIVE()) { return 0; } | ||||
100 | else { return 1; } | ||||
101 | } | ||||
102 | |||||
103 | =item file_name_is_absolute | ||||
104 | |||||
105 | As of right now, this returns 2 if the path is absolute with a | ||||
106 | volume, 1 if it's absolute with no volume, 0 otherwise. | ||||
107 | |||||
108 | =cut | ||||
109 | |||||
110 | # spent 0s within File::Spec::Win32::file_name_is_absolute which was called 22 times, avg 0s/call:
# 18 times (0s+0s) by ExtUtils::MakeMaker::new at line 606 of ExtUtils/MakeMaker.pm, avg 0s/call
# 3 times (0s+0s) by ExtUtils::MM_Unix::init_PERL at line 1967 of ExtUtils/MM_Unix.pm, avg 0s/call
# once (0s+0s) by ExtUtils::MM_Unix::find_perl at line 1055 of ExtUtils/MM_Unix.pm | ||||
111 | |||||
112 | 22 | 0s | my ($self,$file) = @_; | ||
113 | |||||
114 | 22 | 0s | 44 | 0s | if ($file =~ m{^($VOL_RX)}o) { # spent 0s making 22 calls to File::Spec::Win32::CORE:match, avg 0s/call
# spent 0s making 22 calls to File::Spec::Win32::CORE:regcomp, avg 0s/call |
115 | 8 | 0s | my $vol = $1; | ||
116 | 8 | 0s | 32 | 0s | return ($vol =~ m{^$UNC_RX}o ? 2 # spent 0s making 16 calls to File::Spec::Win32::CORE:match, avg 0s/call
# spent 0s making 16 calls to File::Spec::Win32::CORE:regcomp, avg 0s/call |
117 | : $file =~ m{^$DRIVE_RX[\\/]}o ? 2 | ||||
118 | : 0); | ||||
119 | } | ||||
120 | 14 | 0s | 14 | 0s | return $file =~ m{^[\\/]} ? 1 : 0; # spent 0s making 14 calls to File::Spec::Win32::CORE:match, avg 0s/call |
121 | } | ||||
122 | |||||
123 | =item catfile | ||||
124 | |||||
125 | Concatenate one or more directory names and a filename to form a | ||||
126 | complete path ending with a filename | ||||
127 | |||||
128 | =cut | ||||
129 | |||||
130 | # spent 15.6ms (0s+15.6) within File::Spec::Win32::catfile which was called 87 times, avg 179µs/call:
# 83 times (0s+15.6ms) by ExtUtils::MM_Any::catfile at line 2624 of ExtUtils/MM_Any.pm, avg 188µs/call
# 3 times (0s+0s) by ExtUtils::MM_Unix::constants at line 465 of ExtUtils/MM_Unix.pm, avg 0s/call
# once (0s+0s) by ExtUtils::MakeMaker::check_manifest at line 59 of ExtUtils/Manifest.pm | ||||
131 | 87 | 0s | shift; | ||
132 | |||||
133 | # Legacy / compatibility support | ||||
134 | # | ||||
135 | 87 | 0s | shift, return _canon_cat( "/", @_ ) | ||
136 | if $_[0] eq ""; | ||||
137 | |||||
138 | # Compatibility with File::Spec <= 3.26: | ||||
139 | # catfile('A:', 'foo') should return 'A:\foo'. | ||||
140 | 87 | 0s | 174 | 0s | return _canon_cat( ($_[0].'\\'), @_[1..$#_] ) # spent 0s making 87 calls to File::Spec::Win32::CORE:match, avg 0s/call
# spent 0s making 87 calls to File::Spec::Win32::CORE:regcomp, avg 0s/call |
141 | if $_[0] =~ m{^$DRIVE_RX\z}o; | ||||
142 | |||||
143 | 87 | 0s | 87 | 15.6ms | return _canon_cat( @_ ); # spent 15.6ms making 87 calls to File::Spec::Win32::_canon_cat, avg 179µs/call |
144 | } | ||||
145 | |||||
146 | # spent 0s within File::Spec::Win32::catdir which was called 90 times, avg 0s/call:
# 24 times (0s+0s) by ExtUtils::MM_Unix::init_main at line 1642 of ExtUtils/MM_Unix.pm, avg 0s/call
# 14 times (0s+0s) by ExtUtils::MakeMaker::new at line 606 of ExtUtils/MakeMaker.pm, avg 0s/call
# 12 times (0s+0s) by ExtUtils::MM_Unix::tool_xsubpp at line 3589 of ExtUtils/MM_Unix.pm, avg 0s/call
# 3 times (0s+0s) by ExtUtils::MakeMaker::check_hints at line 1026 of ExtUtils/MakeMaker.pm, avg 0s/call
# 3 times (0s+0s) by ExtUtils::MM_Unix::tool_xsubpp at line 3597 of ExtUtils/MM_Unix.pm, avg 0s/call
# 3 times (0s+0s) by ExtUtils::MM_Unix::pm_to_blib at line 2904 of ExtUtils/MM_Unix.pm, avg 0s/call
# 3 times (0s+0s) by ExtUtils::MM_Unix::init_main at line 1693 of ExtUtils/MM_Unix.pm, avg 0s/call
# 3 times (0s+0s) by ExtUtils::MM_Unix::init_main at line 1606 of ExtUtils/MM_Unix.pm, avg 0s/call
# 3 times (0s+0s) by ExtUtils::MM_Any::init_INST at line 1772 of ExtUtils/MM_Any.pm, avg 0s/call
# 3 times (0s+0s) by ExtUtils::MM_Any::init_INST at line 1771 of ExtUtils/MM_Any.pm, avg 0s/call
# 3 times (0s+0s) by ExtUtils::MM_Any::init_INST at line 1770 of ExtUtils/MM_Any.pm, avg 0s/call
# 3 times (0s+0s) by ExtUtils::MM_Any::init_INST at line 1774 of ExtUtils/MM_Any.pm, avg 0s/call
# 3 times (0s+0s) by ExtUtils::MM_Any::_perl_header_files at line 2852 of ExtUtils/MM_Any.pm, avg 0s/call
# 2 times (0s+0s) by ExtUtils::MakeMaker::eval_in_subdirs at line 227 of ExtUtils/MakeMaker.pm, avg 0s/call
# once (0s+0s) by ExtUtils::MM_Unix::install at line 2129 of ExtUtils/MM_Unix.pm
# once (0s+0s) by ExtUtils::MM_Unix::install at line 2148 of ExtUtils/MM_Unix.pm
# once (0s+0s) by ExtUtils::MM_Any::init_INST at line 1777 of ExtUtils/MM_Any.pm
# once (0s+0s) by ExtUtils::MM_Any::init_INST at line 1779 of ExtUtils/MM_Any.pm
# once (0s+0s) by ExtUtils::MM_Any::init_INST at line 1756 of ExtUtils/MM_Any.pm
# once (0s+0s) by ExtUtils::MM_Any::init_INST at line 1765 of ExtUtils/MM_Any.pm
# once (0s+0s) by ExtUtils::MM_Any::init_INST at line 1755 of ExtUtils/MM_Any.pm
# once (0s+0s) by ExtUtils::MM_Any::init_INST at line 1780 of ExtUtils/MM_Any.pm | ||||
147 | 90 | 0s | shift; | ||
148 | |||||
149 | # Legacy / compatibility support | ||||
150 | # | ||||
151 | 90 | 0s | return "" | ||
152 | unless @_; | ||||
153 | 90 | 0s | shift, return _canon_cat( "/", @_ ) | ||
154 | if $_[0] eq ""; | ||||
155 | |||||
156 | # Compatibility with File::Spec <= 3.26: | ||||
157 | # catdir('A:', 'foo') should return 'A:\foo'. | ||||
158 | 90 | 0s | 180 | 0s | return _canon_cat( ($_[0].'\\'), @_[1..$#_] ) # spent 0s making 90 calls to File::Spec::Win32::CORE:match, avg 0s/call
# spent 0s making 90 calls to File::Spec::Win32::CORE:regcomp, avg 0s/call |
159 | if $_[0] =~ m{^$DRIVE_RX\z}o; | ||||
160 | |||||
161 | 90 | 0s | 90 | 0s | return _canon_cat( @_ ); # spent 0s making 90 calls to File::Spec::Win32::_canon_cat, avg 0s/call |
162 | } | ||||
163 | |||||
164 | # spent 0s within File::Spec::Win32::path which was called 3 times, avg 0s/call:
# 3 times (0s+0s) by ExtUtils::MM_Unix::init_PERL at line 1900 of ExtUtils/MM_Unix.pm, avg 0s/call | ||||
165 | 3 | 0s | my @path = split(';', $ENV{PATH}); | ||
166 | 3 | 0s | 153 | 0s | s/"//g for @path; # spent 0s making 153 calls to File::Spec::Win32::CORE:subst, avg 0s/call |
167 | 3 | 0s | @path = grep length, @path; | ||
168 | 3 | 0s | unshift(@path, "."); | ||
169 | 3 | 0s | return @path; | ||
170 | } | ||||
171 | |||||
172 | =item canonpath | ||||
173 | |||||
174 | No physical check on the filesystem, but a logical cleanup of a | ||||
175 | path. On UNIX eliminated successive slashes and successive "/.". | ||||
176 | On Win32 makes | ||||
177 | |||||
178 | dir1\dir2\dir3\..\..\dir4 -> \dir\dir4 and even | ||||
179 | dir1\dir2\dir3\...\dir4 -> \dir\dir4 | ||||
180 | |||||
181 | =cut | ||||
182 | |||||
183 | # spent 0s within File::Spec::Win32::canonpath which was called 92 times, avg 0s/call:
# 83 times (0s+0s) by ExtUtils::MM_Any::catfile at line 2624 of ExtUtils/MM_Any.pm, avg 0s/call
# 3 times (0s+0s) by ExtUtils::MM_Any::arch_check at line 2582 of ExtUtils/MM_Any.pm, avg 0s/call
# 3 times (0s+0s) by ExtUtils::MM_Any::arch_check at line 2581 of ExtUtils/MM_Any.pm, avg 0s/call
# 3 times (0s+0s) by ExtUtils::MM_Unix::init_PERL at line 1907 of ExtUtils/MM_Unix.pm, avg 0s/call | ||||
184 | # Legacy / compatibility support | ||||
185 | # | ||||
186 | 92 | 0s | return $_[1] if !defined($_[1]) or $_[1] eq ''; | ||
187 | 92 | 0s | 92 | 0s | return _canon_cat( $_[1] ); # spent 0s making 92 calls to File::Spec::Win32::_canon_cat, avg 0s/call |
188 | } | ||||
189 | |||||
190 | =item splitpath | ||||
191 | |||||
192 | ($volume,$directories,$file) = File::Spec->splitpath( $path ); | ||||
193 | ($volume,$directories,$file) = File::Spec->splitpath( $path, | ||||
194 | $no_file ); | ||||
195 | |||||
196 | Splits a path into volume, directory, and filename portions. Assumes that | ||||
197 | the last file is a path unless the path ends in '\\', '\\.', '\\..' | ||||
198 | or $no_file is true. On Win32 this means that $no_file true makes this return | ||||
199 | ( $volume, $path, '' ). | ||||
200 | |||||
201 | Separators accepted are \ and /. | ||||
202 | |||||
203 | Volumes can be drive letters or UNC sharenames (\\server\share). | ||||
204 | |||||
205 | The results can be passed to L</catpath> to get back a path equivalent to | ||||
206 | (usually identical to) the original path. | ||||
207 | |||||
208 | =cut | ||||
209 | |||||
210 | # spent 31.2ms within File::Spec::Win32::splitpath which was called 360 times, avg 87µs/call:
# 336 times (31.2ms+0s) by ExtUtils::MM_Any::is_make_type at line 207 of ExtUtils/MM_Any.pm, avg 93µs/call
# 15 times (0s+0s) by ExtUtils::MM_Any::libscan at line 2737 of ExtUtils/MM_Any.pm, avg 0s/call
# 3 times (0s+0s) by ExtUtils::MM_Any::arch_check at line 2578 of ExtUtils/MM_Any.pm, avg 0s/call
# 3 times (0s+0s) by ExtUtils::MM_Any::arch_check at line 2579 of ExtUtils/MM_Any.pm, avg 0s/call
# 3 times (0s+0s) by ExtUtils::MakeMaker::flush at line 1160 of ExtUtils/MakeMaker.pm, avg 0s/call | ||||
211 | 360 | 0s | my ($self,$path, $nofile) = @_; | ||
212 | 360 | 0s | my ($volume,$directory,$file) = ('','',''); | ||
213 | 360 | 0s | if ( $nofile ) { | ||
214 | $path =~ | ||||
215 | m{^ ( $VOL_RX ? ) (.*) }sox; | ||||
216 | $volume = $1; | ||||
217 | $directory = $2; | ||||
218 | } | ||||
219 | else { | ||||
220 | 360 | 15.6ms | 720 | 0s | $path =~ # spent 0s making 360 calls to File::Spec::Win32::CORE:match, avg 0s/call
# spent 0s making 360 calls to File::Spec::Win32::CORE:regcomp, avg 0s/call |
221 | m{^ ( $VOL_RX ? ) | ||||
222 | ( (?:.*[\\/](?:\.\.?\Z(?!\n))?)? ) | ||||
223 | (.*) | ||||
224 | }sox; | ||||
225 | 360 | 0s | $volume = $1; | ||
226 | 360 | 15.6ms | $directory = $2; | ||
227 | 360 | 0s | $file = $3; | ||
228 | } | ||||
229 | |||||
230 | 360 | 0s | return ($volume,$directory,$file); | ||
231 | } | ||||
232 | |||||
233 | |||||
234 | =item splitdir | ||||
235 | |||||
236 | The opposite of L<catdir()|File::Spec/catdir>. | ||||
237 | |||||
238 | @dirs = File::Spec->splitdir( $directories ); | ||||
239 | |||||
240 | $directories must be only the directory portion of the path on systems | ||||
241 | that have the concept of a volume or that have path syntax that differentiates | ||||
242 | files from directories. | ||||
243 | |||||
244 | Unlike just splitting the directories on the separator, leading empty and | ||||
245 | trailing directory entries can be returned, because these are significant | ||||
246 | on some OSs. So, | ||||
247 | |||||
248 | File::Spec->splitdir( "/a/b/c" ); | ||||
249 | |||||
250 | Yields: | ||||
251 | |||||
252 | ( '', 'a', 'b', '', 'c', '' ) | ||||
253 | |||||
254 | =cut | ||||
255 | |||||
256 | # spent 0s within File::Spec::Win32::splitdir which was called 15 times, avg 0s/call:
# 15 times (0s+0s) by ExtUtils::MM_Any::libscan at line 2738 of ExtUtils/MM_Any.pm, avg 0s/call | ||||
257 | 15 | 0s | my ($self,$directories) = @_ ; | ||
258 | # | ||||
259 | # split() likes to forget about trailing null fields, so here we | ||||
260 | # check to be sure that there will not be any before handling the | ||||
261 | # simple case. | ||||
262 | # | ||||
263 | 15 | 0s | 15 | 0s | if ( $directories !~ m|[\\/]\Z(?!\n)| ) { # spent 0s making 15 calls to File::Spec::Win32::CORE:match, avg 0s/call |
264 | 15 | 0s | return split( m|[\\/]|, $directories ); | ||
265 | } | ||||
266 | else { | ||||
267 | # | ||||
268 | # since there was a trailing separator, add a file name to the end, | ||||
269 | # then do the split, then replace it with ''. | ||||
270 | # | ||||
271 | my( @directories )= split( m|[\\/]|, "${directories}dummy" ) ; | ||||
272 | $directories[ $#directories ]= '' ; | ||||
273 | return @directories ; | ||||
274 | } | ||||
275 | } | ||||
276 | |||||
277 | |||||
278 | =item catpath | ||||
279 | |||||
280 | Takes volume, directory and file portions and returns an entire path. Under | ||||
281 | Unix, $volume is ignored, and this is just like catfile(). On other OSs, | ||||
282 | the $volume become significant. | ||||
283 | |||||
284 | =cut | ||||
285 | |||||
286 | sub catpath { | ||||
287 | my ($self,$volume,$directory,$file) = @_; | ||||
288 | |||||
289 | # If it's UNC, make sure the glue separator is there, reusing | ||||
290 | # whatever separator is first in the $volume | ||||
291 | my $v; | ||||
292 | $volume .= $v | ||||
293 | if ( (($v) = $volume =~ m@^([\\/])[\\/][^\\/]+[\\/][^\\/]+\Z(?!\n)@s) && | ||||
294 | $directory =~ m@^[^\\/]@s | ||||
295 | ) ; | ||||
296 | |||||
297 | $volume .= $directory ; | ||||
298 | |||||
299 | # If the volume is not just A:, make sure the glue separator is | ||||
300 | # there, reusing whatever separator is first in the $volume if possible. | ||||
301 | if ( $volume !~ m@^[a-zA-Z]:\Z(?!\n)@s && | ||||
302 | $volume =~ m@[^\\/]\Z(?!\n)@ && | ||||
303 | $file =~ m@[^\\/]@ | ||||
304 | ) { | ||||
305 | $volume =~ m@([\\/])@ ; | ||||
306 | my $sep = $1 ? $1 : '\\' ; | ||||
307 | $volume .= $sep ; | ||||
308 | } | ||||
309 | |||||
310 | $volume .= $file ; | ||||
311 | |||||
312 | return $volume ; | ||||
313 | } | ||||
314 | |||||
315 | sub _same { | ||||
316 | lc($_[1]) eq lc($_[2]); | ||||
317 | } | ||||
318 | |||||
319 | sub rel2abs { | ||||
320 | my ($self,$path,$base ) = @_; | ||||
321 | |||||
322 | my $is_abs = $self->file_name_is_absolute($path); | ||||
323 | |||||
324 | # Check for volume (should probably document the '2' thing...) | ||||
325 | return $self->canonpath( $path ) if $is_abs == 2; | ||||
326 | |||||
327 | if ($is_abs) { | ||||
328 | # It's missing a volume, add one | ||||
329 | my $vol = ($self->splitpath( $self->_cwd() ))[0]; | ||||
330 | return $self->canonpath( $vol . $path ); | ||||
331 | } | ||||
332 | |||||
333 | if ( !defined( $base ) || $base eq '' ) { | ||||
334 | require Cwd ; | ||||
335 | $base = Cwd::getdcwd( ($self->splitpath( $path ))[0] ) if defined &Cwd::getdcwd ; | ||||
336 | $base = $self->_cwd() unless defined $base ; | ||||
337 | } | ||||
338 | elsif ( ! $self->file_name_is_absolute( $base ) ) { | ||||
339 | $base = $self->rel2abs( $base ) ; | ||||
340 | } | ||||
341 | else { | ||||
342 | $base = $self->canonpath( $base ) ; | ||||
343 | } | ||||
344 | |||||
345 | my ( $path_directories, $path_file ) = | ||||
346 | ($self->splitpath( $path, 1 ))[1,2] ; | ||||
347 | |||||
348 | my ( $base_volume, $base_directories ) = | ||||
349 | $self->splitpath( $base, 1 ) ; | ||||
350 | |||||
351 | $path = $self->catpath( | ||||
352 | $base_volume, | ||||
353 | $self->catdir( $base_directories, $path_directories ), | ||||
354 | $path_file | ||||
355 | ) ; | ||||
356 | |||||
357 | return $self->canonpath( $path ) ; | ||||
358 | } | ||||
359 | |||||
360 | =back | ||||
361 | |||||
362 | =head2 Note For File::Spec::Win32 Maintainers | ||||
363 | |||||
364 | Novell NetWare inherits its File::Spec behaviour from File::Spec::Win32. | ||||
365 | |||||
366 | =head1 COPYRIGHT | ||||
367 | |||||
368 | Copyright (c) 2004,2007 by the Perl 5 Porters. All rights reserved. | ||||
369 | |||||
370 | This program is free software; you can redistribute it and/or modify | ||||
371 | it under the same terms as Perl itself. | ||||
372 | |||||
373 | =head1 SEE ALSO | ||||
374 | |||||
375 | See L<File::Spec> and L<File::Spec::Unix>. This package overrides the | ||||
376 | implementation of these methods, not the semantics. | ||||
377 | |||||
378 | =cut | ||||
379 | |||||
380 | |||||
381 | sub _canon_cat # @path -> path | ||||
382 | # spent 15.6ms (0s+15.6) within File::Spec::Win32::_canon_cat which was called 269 times, avg 58µs/call:
# 92 times (0s+0s) by File::Spec::Win32::canonpath at line 187, avg 0s/call
# 90 times (0s+0s) by File::Spec::Win32::catdir at line 161, avg 0s/call
# 87 times (0s+15.6ms) by File::Spec::Win32::catfile at line 143, avg 179µs/call | ||||
383 | 269 | 0s | my ($first, @rest) = @_; | ||
384 | |||||
385 | 269 | 0s | 651 | 0s | my $volume = $first =~ s{ \A ([A-Za-z]:) ([\\/]?) }{}x # drive letter # spent 0s making 651 calls to File::Spec::Win32::CORE:subst, avg 0s/call |
386 | ? ucfirst( $1 ).( $2 ? "\\" : "" ) | ||||
387 | : $first =~ s{ \A (?:\\\\|//) ([^\\/]+) | ||||
388 | (?: [\\/] ([^\\/]+) )? | ||||
389 | [\\/]? }{}xs # UNC volume | ||||
390 | ? "\\\\$1".( defined $2 ? "\\$2" : "" )."\\" | ||||
391 | : $first =~ s{ \A [\\/] }{}x # root dir | ||||
392 | ? "\\" | ||||
393 | : ""; | ||||
394 | 269 | 0s | my $path = join "\\", $first, @rest; | ||
395 | |||||
396 | 269 | 0s | $path =~ tr#\\/#\\\\#s; # xx/yy --> xx\yy & xx\\yy --> xx\yy | ||
397 | |||||
398 | # xx/././yy --> xx/yy | ||||
399 | 269 | 0s | 269 | 0s | $path =~ s{(?: # spent 0s making 269 calls to File::Spec::Win32::CORE:subst, avg 0s/call |
400 | (?:\A|\\) # at begin or after a slash | ||||
401 | \. | ||||
402 | (?:\\\.)* # and more | ||||
403 | (?:\\|\z) # at end or followed by slash | ||||
404 | )+ # performance boost -- I do not know why | ||||
405 | }{\\}gx; | ||||
406 | |||||
407 | # XXX I do not know whether more dots are supported by the OS supporting | ||||
408 | # this ... annotation (NetWare or symbian but not MSWin32). | ||||
409 | # Then .... could easily become ../../.. etc: | ||||
410 | # Replace \.\.\. by (\.\.\.+) and substitute with | ||||
411 | # { $1 . ".." . "\\.." x (length($2)-2) }gex | ||||
412 | # ... --> ../.. | ||||
413 | 269 | 0s | 269 | 0s | $path =~ s{ (\A|\\) # at begin or after a slash # spent 0s making 269 calls to File::Spec::Win32::CORE:subst, avg 0s/call |
414 | \.\.\. | ||||
415 | (?=\\|\z) # at end or followed by slash | ||||
416 | }{$1..\\..}gx; | ||||
417 | # xx\yy\..\zz --> xx\zz | ||||
418 | 269 | 0s | 269 | 0s | while ( $path =~ s{(?: # spent 0s making 269 calls to File::Spec::Win32::CORE:subst, avg 0s/call |
419 | (?:\A|\\) # at begin or after a slash | ||||
420 | [^\\]+ # rip this 'yy' off | ||||
421 | \\\.\. | ||||
422 | (?<!\A\.\.\\\.\.) # do *not* replace ^..\.. | ||||
423 | (?<!\\\.\.\\\.\.) # do *not* replace \..\.. | ||||
424 | (?:\\|\z) # at end or followed by slash | ||||
425 | )+ # performance boost -- I do not know why | ||||
426 | }{\\}sx ) {} | ||||
427 | |||||
428 | 269 | 0s | 269 | 0s | $path =~ s#\A\\##; # \xx --> xx NOTE: this is *not* root # spent 0s making 269 calls to File::Spec::Win32::CORE:subst, avg 0s/call |
429 | 269 | 0s | 269 | 0s | $path =~ s#\\\z##; # xx\ --> xx # spent 0s making 269 calls to File::Spec::Win32::CORE:subst, avg 0s/call |
430 | |||||
431 | 269 | 15.6ms | 269 | 15.6ms | if ( $volume =~ m#\\\z# ) # spent 15.6ms making 269 calls to File::Spec::Win32::CORE:match, avg 58µs/call |
432 | { # <vol>\.. --> <vol>\ | ||||
433 | 84 | 0s | 84 | 0s | $path =~ s{ \A # at begin # spent 0s making 84 calls to File::Spec::Win32::CORE:subst, avg 0s/call |
434 | \.\. | ||||
435 | (?:\\\.\.)* # and more | ||||
436 | (?:\\|\z) # at end or followed by slash | ||||
437 | }{}x; | ||||
438 | |||||
439 | 84 | 0s | return $1 # \\HOST\SHARE\ --> \\HOST\SHARE | ||
440 | if $path eq "" | ||||
441 | and $volume =~ m#\A(\\\\.*)\\\z#s; | ||||
442 | } | ||||
443 | 269 | 0s | return $path ne "" || $volume ? $volume.$path : "."; | ||
444 | } | ||||
445 | |||||
446 | 1 | 0s | 1; | ||
# spent 15.6ms within File::Spec::Win32::CORE:match which was called 873 times, avg 18µs/call:
# 360 times (0s+0s) by File::Spec::Win32::splitpath at line 220, avg 0s/call
# 269 times (15.6ms+0s) by File::Spec::Win32::_canon_cat at line 431, avg 58µs/call
# 90 times (0s+0s) by File::Spec::Win32::catdir at line 158, avg 0s/call
# 87 times (0s+0s) by File::Spec::Win32::catfile at line 140, avg 0s/call
# 22 times (0s+0s) by File::Spec::Win32::file_name_is_absolute at line 114, avg 0s/call
# 16 times (0s+0s) by File::Spec::Win32::file_name_is_absolute at line 116, avg 0s/call
# 15 times (0s+0s) by File::Spec::Win32::splitdir at line 263, avg 0s/call
# 14 times (0s+0s) by File::Spec::Win32::file_name_is_absolute at line 120, avg 0s/call | |||||
# spent 0s within File::Spec::Win32::CORE:regcomp which was called 575 times, avg 0s/call:
# 360 times (0s+0s) by File::Spec::Win32::splitpath at line 220, avg 0s/call
# 90 times (0s+0s) by File::Spec::Win32::catdir at line 158, avg 0s/call
# 87 times (0s+0s) by File::Spec::Win32::catfile at line 140, avg 0s/call
# 22 times (0s+0s) by File::Spec::Win32::file_name_is_absolute at line 114, avg 0s/call
# 16 times (0s+0s) by File::Spec::Win32::file_name_is_absolute at line 116, avg 0s/call | |||||
# spent 0s within File::Spec::Win32::CORE:subst which was called 2233 times, avg 0s/call:
# 651 times (0s+0s) by File::Spec::Win32::_canon_cat at line 385, avg 0s/call
# 269 times (0s+0s) by File::Spec::Win32::_canon_cat at line 399, avg 0s/call
# 269 times (0s+0s) by File::Spec::Win32::_canon_cat at line 428, avg 0s/call
# 269 times (0s+0s) by File::Spec::Win32::_canon_cat at line 418, avg 0s/call
# 269 times (0s+0s) by File::Spec::Win32::_canon_cat at line 429, avg 0s/call
# 269 times (0s+0s) by File::Spec::Win32::_canon_cat at line 413, avg 0s/call
# 153 times (0s+0s) by File::Spec::Win32::path at line 166, avg 0s/call
# 84 times (0s+0s) by File::Spec::Win32::_canon_cat at line 433, avg 0s/call |