Filename | /usr/share/perl/5.10/File/Basename.pm |
Statements | Executed 145 statements in 2.51ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.30ms | 1.40ms | BEGIN@43 | File::Basename::
6 | 4 | 3 | 200µs | 247µs | fileparse | File::Basename::
1 | 1 | 1 | 81µs | 139µs | fileparse_set_fstype | File::Basename::
1 | 1 | 1 | 63µs | 63µs | BEGIN@51 | File::Basename::
16 | 2 | 1 | 60µs | 60µs | CORE:match (opcode) | File::Basename::
10 | 1 | 1 | 45µs | 45µs | CORE:regcomp (opcode) | File::Basename::
1 | 1 | 1 | 30µs | 135µs | dirname | File::Basename::
1 | 1 | 1 | 24µs | 24µs | BEGIN@371 | File::Basename::
1 | 1 | 1 | 20µs | 36µs | _strip_trailing_sep | File::Basename::
1 | 1 | 1 | 16µs | 39µs | BEGIN@52 | File::Basename::
1 | 1 | 1 | 14µs | 17µs | BEGIN@50 | File::Basename::
1 | 1 | 1 | 10µs | 10µs | CORE:subst (opcode) | File::Basename::
2 | 1 | 1 | 6µs | 6µs | CORE:substcont (opcode) | File::Basename::
0 | 0 | 0 | 0s | 0s | basename | File::Basename::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | =head1 NAME | ||||
2 | |||||
- - | |||||
38 | package File::Basename; | ||||
39 | |||||
40 | # A bit of juggling to insure that C<use re 'taint';> always works, since | ||||
41 | # File::Basename is used during the Perl build, when the re extension may | ||||
42 | # not be available. | ||||
43 | # spent 1.40ms (1.30+92µs) within File::Basename::BEGIN@43 which was called:
# once (1.30ms+92µs) by XML::Simple::find_xml_file at line 47 | ||||
44 | 2 | 88µs | unless (eval { require re; }) | ||
45 | { eval ' sub re::import { $^H |= 0x00100000; } ' } # HINT_RE_TAINT | ||||
46 | 1 | 16µs | 1 | 33µs | import re 'taint'; # spent 33µs making 1 call to re::import |
47 | 1 | 37µs | 1 | 1.40ms | } # spent 1.40ms making 1 call to File::Basename::BEGIN@43 |
48 | |||||
49 | |||||
50 | 3 | 27µs | 2 | 21µs | # spent 17µs (14+4) within File::Basename::BEGIN@50 which was called:
# once (14µs+4µs) by XML::Simple::find_xml_file at line 50 # spent 17µs making 1 call to File::Basename::BEGIN@50
# spent 4µs making 1 call to strict::import |
51 | 3 | 109µs | 1 | 63µs | # spent 63µs within File::Basename::BEGIN@51 which was called:
# once (63µs+0s) by XML::Simple::find_xml_file at line 51 # spent 63µs making 1 call to File::Basename::BEGIN@51 |
52 | 3 | 1.65ms | 2 | 63µs | # spent 39µs (16+24) within File::Basename::BEGIN@52 which was called:
# once (16µs+24µs) by XML::Simple::find_xml_file at line 52 # spent 39µs making 1 call to File::Basename::BEGIN@52
# spent 24µs making 1 call to warnings::import |
53 | 1 | 2µs | our(@ISA, @EXPORT, $VERSION, $Fileparse_fstype, $Fileparse_igncase); | ||
54 | 1 | 2µs | require Exporter; | ||
55 | 1 | 23µs | @ISA = qw(Exporter); | ||
56 | 1 | 2µs | @EXPORT = qw(fileparse fileparse_set_fstype basename dirname); | ||
57 | 1 | 700ns | $VERSION = "2.77"; | ||
58 | |||||
59 | 1 | 5µs | 1 | 139µs | fileparse_set_fstype($^O); # spent 139µs making 1 call to File::Basename::fileparse_set_fstype |
60 | |||||
61 | |||||
62 | =over 4 | ||||
63 | |||||
- - | |||||
104 | # spent 247µs (200+47) within File::Basename::fileparse which was called 6 times, avg 41µs/call:
# 3 times (86µs+19µs) by XML::Simple::find_xml_file at line 923 of XML/Simple.pm, avg 35µs/call
# once (54µs+14µs) by File::Basename::dirname at line 294
# once (45µs+9µs) by FindBin::init at line 179 of FindBin.pm
# once (15µs+4µs) by FindBin::init at line 186 of FindBin.pm | ||||
105 | 6 | 13µs | my($fullname,@suffices) = @_; | ||
106 | |||||
107 | 6 | 4µs | unless (defined $fullname) { | ||
108 | require Carp; | ||||
109 | Carp::croak("fileparse(): need a valid pathname"); | ||||
110 | } | ||||
111 | |||||
112 | 6 | 7µs | my $orig_type = ''; | ||
113 | 6 | 9µs | my($type,$igncase) = ($Fileparse_fstype, $Fileparse_igncase); | ||
114 | |||||
115 | 6 | 12µs | my($taint) = substr($fullname,0,0); # Is $fullname tainted? | ||
116 | |||||
117 | 6 | 6µs | if ($type eq "VMS" and $fullname =~ m{/} ) { | ||
118 | # We're doing Unix emulation | ||||
119 | $orig_type = $type; | ||||
120 | $type = 'Unix'; | ||||
121 | } | ||||
122 | |||||
123 | 6 | 5µs | my($dirpath, $basename); | ||
124 | |||||
125 | 6 | 31µs | if (grep { $type eq $_ } qw(MSDOS DOS MSWin32 Epoc)) { | ||
126 | ($dirpath,$basename) = ($fullname =~ /^((?:.*[:\\\/])?)(.*)/s); | ||||
127 | $dirpath .= '.\\' unless $dirpath =~ /[\\\/]\z/; | ||||
128 | } | ||||
129 | elsif ($type eq "OS2") { | ||||
130 | ($dirpath,$basename) = ($fullname =~ m#^((?:.*[:\\/])?)(.*)#s); | ||||
131 | $dirpath = './' unless $dirpath; # Can't be 0 | ||||
132 | $dirpath .= '/' unless $dirpath =~ m#[\\/]\z#; | ||||
133 | } | ||||
134 | elsif ($type eq "MacOS") { | ||||
135 | ($dirpath,$basename) = ($fullname =~ /^(.*:)?(.*)/s); | ||||
136 | $dirpath = ':' unless $dirpath; | ||||
137 | } | ||||
138 | elsif ($type eq "AmigaOS") { | ||||
139 | ($dirpath,$basename) = ($fullname =~ /(.*[:\/])?(.*)/s); | ||||
140 | $dirpath = './' unless $dirpath; | ||||
141 | } | ||||
142 | elsif ($type eq 'VMS' ) { | ||||
143 | ($dirpath,$basename) = ($fullname =~ /^(.*[:>\]])?(.*)/s); | ||||
144 | $dirpath ||= ''; # should always be defined | ||||
145 | } | ||||
146 | else { # Default to Unix semantics. | ||||
147 | 6 | 98µs | 6 | 47µs | ($dirpath,$basename) = ($fullname =~ m{^(.*/)?(.*)}s); # spent 47µs making 6 calls to File::Basename::CORE:match, avg 8µs/call |
148 | 6 | 6µs | if ($orig_type eq 'VMS' and $fullname =~ m{^(/[^/]+/000000(/|$))(.*)}) { | ||
149 | # dev:[000000] is top of VMS tree, similar to Unix '/' | ||||
150 | # so strip it off and treat the rest as "normal" | ||||
151 | my $devspec = $1; | ||||
152 | my $remainder = $3; | ||||
153 | ($dirpath,$basename) = ($remainder =~ m{^(.*/)?(.*)}s); | ||||
154 | $dirpath ||= ''; # should always be defined | ||||
155 | $dirpath = $devspec.$dirpath; | ||||
156 | } | ||||
157 | 6 | 6µs | $dirpath = './' unless $dirpath; | ||
158 | } | ||||
159 | |||||
160 | |||||
161 | 6 | 6µs | my $tail = ''; | ||
162 | 6 | 3µs | my $suffix = ''; | ||
163 | 6 | 5µs | if (@suffices) { | ||
164 | foreach $suffix (@suffices) { | ||||
165 | my $pat = ($igncase ? '(?i)' : '') . "($suffix)\$"; | ||||
166 | if ($basename =~ s/$pat//s) { | ||||
167 | $taint .= substr($suffix,0,0); | ||||
168 | $tail = $1 . $tail; | ||||
169 | } | ||||
170 | } | ||||
171 | } | ||||
172 | |||||
173 | # Ensure taint is propgated from the path to its pieces. | ||||
174 | 6 | 5µs | $tail .= $taint; | ||
175 | 6 | 45µs | wantarray ? ($basename .= $taint, $dirpath .= $taint, $tail) | ||
176 | : ($basename .= $taint); | ||||
177 | } | ||||
178 | |||||
- - | |||||
181 | =item C<basename> | ||||
182 | |||||
- - | |||||
214 | sub basename { | ||||
215 | my($path) = shift; | ||||
216 | |||||
217 | # From BSD basename(1) | ||||
218 | # The basename utility deletes any prefix ending with the last slash `/' | ||||
219 | # character present in string (after first stripping trailing slashes) | ||||
220 | _strip_trailing_sep($path); | ||||
221 | |||||
222 | my($basename, $dirname, $suffix) = fileparse( $path, map("\Q$_\E",@_) ); | ||||
223 | |||||
224 | # From BSD basename(1) | ||||
225 | # The suffix is not stripped if it is identical to the remaining | ||||
226 | # characters in string. | ||||
227 | if( length $suffix and !length $basename ) { | ||||
228 | $basename = $suffix; | ||||
229 | } | ||||
230 | |||||
231 | # Ensure that basename '/' == '/' | ||||
232 | if( !length $basename ) { | ||||
233 | $basename = $dirname; | ||||
234 | } | ||||
235 | |||||
236 | return $basename; | ||||
237 | } | ||||
238 | |||||
- - | |||||
241 | =item C<dirname> | ||||
242 | |||||
- - | |||||
283 | # spent 135µs (30+104) within File::Basename::dirname which was called:
# once (30µs+104µs) by XML::SAX::load_parsers at line 57 of XML/SAX.pm | ||||
284 | 1 | 1µs | my $path = shift; | ||
285 | |||||
286 | 1 | 2µs | my($type) = $Fileparse_fstype; | ||
287 | |||||
288 | 1 | 2µs | if( $type eq 'VMS' and $path =~ m{/} ) { | ||
289 | # Parse as Unix | ||||
290 | local($File::Basename::Fileparse_fstype) = ''; | ||||
291 | return dirname($path); | ||||
292 | } | ||||
293 | |||||
294 | 1 | 6µs | 1 | 68µs | my($basename, $dirname) = fileparse($path); # spent 68µs making 1 call to File::Basename::fileparse |
295 | |||||
296 | 1 | 5µs | if ($type eq 'VMS') { | ||
297 | $dirname ||= $ENV{DEFAULT}; | ||||
298 | } | ||||
299 | elsif ($type eq 'MacOS') { | ||||
300 | if( !length($basename) && $dirname !~ /^[^:]+:\z/) { | ||||
301 | _strip_trailing_sep($dirname); | ||||
302 | ($basename,$dirname) = fileparse $dirname; | ||||
303 | } | ||||
304 | $dirname .= ":" unless $dirname =~ /:\z/; | ||||
305 | } | ||||
306 | elsif (grep { $type eq $_ } qw(MSDOS DOS MSWin32 OS2)) { | ||||
307 | _strip_trailing_sep($dirname); | ||||
308 | unless( length($basename) ) { | ||||
309 | ($basename,$dirname) = fileparse $dirname; | ||||
310 | _strip_trailing_sep($dirname); | ||||
311 | } | ||||
312 | } | ||||
313 | elsif ($type eq 'AmigaOS') { | ||||
314 | if ( $dirname =~ /:\z/) { return $dirname } | ||||
315 | chop $dirname; | ||||
316 | $dirname =~ s{[^:/]+\z}{} unless length($basename); | ||||
317 | } | ||||
318 | else { | ||||
319 | 1 | 4µs | 1 | 36µs | _strip_trailing_sep($dirname); # spent 36µs making 1 call to File::Basename::_strip_trailing_sep |
320 | 1 | 1µs | unless( length($basename) ) { | ||
321 | ($basename,$dirname) = fileparse $dirname; | ||||
322 | _strip_trailing_sep($dirname); | ||||
323 | } | ||||
324 | } | ||||
325 | |||||
326 | 1 | 4µs | $dirname; | ||
327 | } | ||||
328 | |||||
329 | |||||
330 | # Strip the trailing path separator. | ||||
331 | # spent 36µs (20+16) within File::Basename::_strip_trailing_sep which was called:
# once (20µs+16µs) by File::Basename::dirname at line 319 | ||||
332 | 1 | 700ns | my $type = $Fileparse_fstype; | ||
333 | |||||
334 | 1 | 5µs | if ($type eq 'MacOS') { | ||
335 | $_[0] =~ s/([^:]):\z/$1/s; | ||||
336 | } | ||||
337 | elsif (grep { $type eq $_ } qw(MSDOS DOS MSWin32 OS2)) { | ||||
338 | $_[0] =~ s/([^:])[\\\/]*\z/$1/; | ||||
339 | } | ||||
340 | else { | ||||
341 | 1 | 30µs | 3 | 16µs | $_[0] =~ s{(.)/*\z}{$1}s; # spent 10µs making 1 call to File::Basename::CORE:subst
# spent 6µs making 2 calls to File::Basename::CORE:substcont, avg 3µs/call |
342 | } | ||||
343 | } | ||||
344 | |||||
345 | |||||
346 | =item C<fileparse_set_fstype> | ||||
347 | |||||
- - | |||||
371 | # spent 24µs within File::Basename::BEGIN@371 which was called:
# once (24µs+0s) by XML::Simple::find_xml_file at line 394 | ||||
372 | |||||
373 | 1 | 5µs | my @Ignore_Case = qw(MacOS VMS AmigaOS OS2 RISCOS MSWin32 MSDOS DOS Epoc); | ||
374 | 1 | 20µs | my @Types = (@Ignore_Case, qw(Unix)); | ||
375 | |||||
376 | # spent 139µs (81+58) within File::Basename::fileparse_set_fstype which was called:
# once (81µs+58µs) by XML::Simple::find_xml_file at line 59 | ||||
377 | 1 | 800ns | my $old = $Fileparse_fstype; | ||
378 | |||||
379 | 1 | 1µs | if (@_) { | ||
380 | 1 | 4µs | my $new_type = shift; | ||
381 | |||||
382 | 1 | 600ns | $Fileparse_fstype = 'Unix'; # default | ||
383 | 1 | 3µs | foreach my $type (@Types) { | ||
384 | 10 | 122µs | 20 | 58µs | $Fileparse_fstype = $type if $new_type =~ /^$type/i; # spent 45µs making 10 calls to File::Basename::CORE:regcomp, avg 4µs/call
# spent 14µs making 10 calls to File::Basename::CORE:match, avg 1µs/call |
385 | } | ||||
386 | |||||
387 | $Fileparse_igncase = | ||||
388 | 1 | 4µs | (grep $Fileparse_fstype eq $_, @Ignore_Case) ? 1 : 0; | ||
389 | } | ||||
390 | |||||
391 | 1 | 6µs | return $old; | ||
392 | } | ||||
393 | |||||
394 | 1 | 48µs | 1 | 24µs | } # spent 24µs making 1 call to File::Basename::BEGIN@371 |
395 | |||||
396 | |||||
397 | 1 | 14µs | 1; | ||
398 | |||||
399 | |||||
400 | =head1 SEE ALSO | ||||
sub File::Basename::CORE:match; # opcode | |||||
# spent 45µs within File::Basename::CORE:regcomp which was called 10 times, avg 4µs/call:
# 10 times (45µs+0s) by File::Basename::fileparse_set_fstype at line 384, avg 4µs/call | |||||
# spent 10µs within File::Basename::CORE:subst which was called:
# once (10µs+0s) by File::Basename::_strip_trailing_sep at line 341 | |||||
# spent 6µs within File::Basename::CORE:substcont which was called 2 times, avg 3µs/call:
# 2 times (6µs+0s) by File::Basename::_strip_trailing_sep at line 341, avg 3µs/call |