← Index
NYTProf Performance Profile   « line view »
For webmerge/scripts/webmerge.pl
  Run on Mon Oct 7 02:42:42 2013
Reported on Mon Oct 7 03:03:17 2013

Filename/usr/lib64/perl5/5.16.0/File/Basename.pm
StatementsExecuted 1360873 statements in 17.1s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
51610424.23s5.15sFile::Basename::::fileparseFile::Basename::fileparse
51608213.87s7.32sFile::Basename::::_strip_trailing_sepFile::Basename::_strip_trailing_sep
35304862.99s12.1sFile::Basename::::dirnameFile::Basename::dirname
51608112.68s2.68sFile::Basename::::CORE:substFile::Basename::CORE:subst (opcode)
16304211.19s4.58sFile::Basename::::basenameFile::Basename::basename
5162021918ms918msFile::Basename::::CORE:matchFile::Basename::CORE:match (opcode)
10321611771ms771msFile::Basename::::CORE:substcontFile::Basename::CORE:substcont (opcode)
111310µs525µsFile::Basename::::fileparse_set_fstypeFile::Basename::fileparse_set_fstype
1011176µs176µsFile::Basename::::CORE:regcompFile::Basename::CORE:regcomp (opcode)
11170µs104µsFile::Basename::::BEGIN@52File::Basename::BEGIN@52
11169µs69µsFile::Basename::::BEGIN@51File::Basename::BEGIN@51
11160µs60µsFile::Basename::::BEGIN@42File::Basename::BEGIN@42
11155µs55µsFile::Basename::::BEGIN@371File::Basename::BEGIN@371
11151µs146µsFile::Basename::::BEGIN@50File::Basename::BEGIN@50
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1=head1 NAME
2
3File::Basename - Parse file paths into directory, filename and suffix.
4
5=head1 SYNOPSIS
6
7 use File::Basename;
8
9 ($name,$path,$suffix) = fileparse($fullname,@suffixlist);
10 $name = fileparse($fullname,@suffixlist);
11
12 $basename = basename($fullname,@suffixlist);
13 $dirname = dirname($fullname);
14
15
16=head1 DESCRIPTION
17
18These routines allow you to parse file paths into their directory, filename
19and suffix.
20
21B<NOTE>: C<dirname()> and C<basename()> emulate the behaviours, and
22quirks, of the shell and C functions of the same name. See each
23function's documentation for details. If your concern is just parsing
24paths it is safer to use L<File::Spec>'s C<splitpath()> and
25C<splitdir()> methods.
26
27It is guaranteed that
28
29 # Where $path_separator is / for Unix, \ for Windows, etc...
30 dirname($path) . $path_separator . basename($path);
31
32is equivalent to the original path for all systems but VMS.
33
34
35=cut
36
37
38package File::Basename;
39
40# File::Basename is used during the Perl build, when the re extension may
41# not be available, but we only actually need it if running under tainting.
42
# spent 60µs within File::Basename::BEGIN@42 which was called: # once (60µs+0s) by FindBin::BEGIN@84 at line 47
BEGIN {
43139µs if (${^TAINT}) {
44 require re;
45 re->import('taint');
46 }
471114µs160µs}
# spent 60µs making 1 call to File::Basename::BEGIN@42
48
49
502144µs2241µs
# spent 146µs (51+95) within File::Basename::BEGIN@50 which was called: # once (51µs+95µs) by FindBin::BEGIN@84 at line 50
use strict;
# spent 146µs making 1 call to File::Basename::BEGIN@50 # spent 95µs making 1 call to strict::import
512298µs169µs
# spent 69µs within File::Basename::BEGIN@51 which was called: # once (69µs+0s) by FindBin::BEGIN@84 at line 51
use 5.006;
# spent 69µs making 1 call to File::Basename::BEGIN@51
5226.26ms2139µs
# spent 104µs (70+34) within File::Basename::BEGIN@52 which was called: # once (70µs+34µs) by FindBin::BEGIN@84 at line 52
use warnings;
# spent 104µs making 1 call to File::Basename::BEGIN@52 # spent 34µs making 1 call to warnings::import
5313µsour(@ISA, @EXPORT, $VERSION, $Fileparse_fstype, $Fileparse_igncase);
5414µsrequire Exporter;
55134µs@ISA = qw(Exporter);
5617µs@EXPORT = qw(fileparse fileparse_set_fstype basename dirname);
5712µs$VERSION = "2.84";
58
59111µs1525µsfileparse_set_fstype($^O);
# spent 525µs making 1 call to File::Basename::fileparse_set_fstype
60
61
62=over 4
63
64=item C<fileparse>
65X<fileparse>
66
67 my($filename, $directories, $suffix) = fileparse($path);
68 my($filename, $directories, $suffix) = fileparse($path, @suffixes);
69 my $filename = fileparse($path, @suffixes);
70
71The C<fileparse()> routine divides a file path into its $directories, $filename
72and (optionally) the filename $suffix.
73
74$directories contains everything up to and including the last
75directory separator in the $path including the volume (if applicable).
76The remainder of the $path is the $filename.
77
78 # On Unix returns ("baz", "/foo/bar/", "")
79 fileparse("/foo/bar/baz");
80
81 # On Windows returns ("baz", 'C:\foo\bar\', "")
82 fileparse('C:\foo\bar\baz');
83
84 # On Unix returns ("", "/foo/bar/baz/", "")
85 fileparse("/foo/bar/baz/");
86
87If @suffixes are given each element is a pattern (either a string or a
88C<qr//>) matched against the end of the $filename. The matching
89portion is removed and becomes the $suffix.
90
91 # On Unix returns ("baz", "/foo/bar/", ".txt")
92 fileparse("/foo/bar/baz.txt", qr/\.[^.]*/);
93
94If type is non-Unix (see L</fileparse_set_fstype>) then the pattern
95matching for suffix removal is performed case-insensitively, since
96those systems are not case-sensitive when opening existing files.
97
98You are guaranteed that C<$directories . $filename . $suffix> will
99denote the same location as the original $path.
100
101=cut
102
103
104
# spent 5.15s (4.23+918ms) within File::Basename::fileparse which was called 51610 times, avg 100µs/call: # 35304 times (3.07s+677ms) by File::Basename::dirname at line 294, avg 106µs/call # 16304 times (1.16s+242ms) by File::Basename::basename at line 222, avg 86µs/call # once (94µs+21µs) by FindBin::init at line 140 of FindBin.pm # once (61µs+15µs) by FindBin::init at line 147 of FindBin.pm
sub fileparse {
10551610299ms my($fullname,@suffices) = @_;
106
1075161068.6ms unless (defined $fullname) {
108 require Carp;
109 Carp::croak("fileparse(): need a valid pathname");
110 }
111
1125161080.1ms my $orig_type = '';
11351610117ms my($type,$igncase) = ($Fileparse_fstype, $Fileparse_igncase);
114
11551610268ms my($taint) = substr($fullname,0,0); # Is $fullname tainted?
116
1175161062.1ms if ($type eq "VMS" and $fullname =~ m{/} ) {
118 # We're doing Unix emulation
119 $orig_type = $type;
120 $type = 'Unix';
121 }
122
1235161066.6ms my($dirpath, $basename);
124
12551610570ms 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.
147516102.27s51610918ms ($dirpath,$basename) = ($fullname =~ m{^(.*/)?(.*)}s);
# spent 918ms making 51610 calls to File::Basename::CORE:match, avg 18µs/call
1485161076.8ms 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 }
15751610115ms $dirpath = './' unless $dirpath;
158 }
159
160
1615161086.8ms my $tail = '';
1625161052.8ms my $suffix = '';
16351610107ms 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 propagated from the path to its pieces.
1745161086.8ms $tail .= $taint;
175516101.51s wantarray ? ($basename .= $taint, $dirpath .= $taint, $tail)
176 : ($basename .= $taint);
177}
178
- -
181=item C<basename>
182X<basename> X<filename>
183
184 my $filename = basename($path);
185 my $filename = basename($path, @suffixes);
186
187This function is provided for compatibility with the Unix shell command
188C<basename(1)>. It does B<NOT> always return the file name portion of a
189path as you might expect. To be safe, if you want the file name portion of
190a path use C<fileparse()>.
191
192C<basename()> returns the last level of a filepath even if the last
193level is clearly directory. In effect, it is acting like C<pop()> for
194paths. This differs from C<fileparse()>'s behaviour.
195
196 # Both return "bar"
197 basename("/foo/bar");
198 basename("/foo/bar/");
199
200@suffixes work as in C<fileparse()> except all regex metacharacters are
201quoted.
202
203 # These two function calls are equivalent.
204 my $filename = basename("/foo/bar/baz.txt", ".txt");
205 my $filename = fileparse("/foo/bar/baz.txt", qr/\Q.txt\E/);
206
207Also note that in order to be compatible with the shell command,
208C<basename()> does not strip off a suffix if it is identical to the
209remaining characters in the filename.
210
211=cut
212
213
214
# spent 4.58s (1.19+3.39) within File::Basename::basename which was called 16304 times, avg 281µs/call: # 13585 times (969ms+2.59s) by RTP::Webmerge::Path::importURI at line 68 of webmerge/scripts/modules/RTP/Webmerge/Path.pm, avg 262µs/call # 2719 times (225ms+792ms) by RTP::Webmerge::Path::check_path at line 164 of webmerge/scripts/modules/RTP/Webmerge/Path.pm, avg 374µs/call
sub basename {
2151630462.4ms 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)
22016304127ms163041.98s _strip_trailing_sep($path);
# spent 1.98s making 16304 calls to File::Basename::_strip_trailing_sep, avg 122µs/call
221
22216304245ms163041.40s my($basename, $dirname, $suffix) = fileparse( $path, map("\Q$_\E",@_) );
# spent 1.40s making 16304 calls to File::Basename::fileparse, avg 86µs/call
223
224 # From BSD basename(1)
225 # The suffix is not stripped if it is identical to the remaining
226 # characters in string.
2271630429.3ms if( length $suffix and !length $basename ) {
228 $basename = $suffix;
229 }
230
231 # Ensure that basename '/' == '/'
2321630426.3ms if( !length $basename ) {
233 $basename = $dirname;
234 }
235
23616304399ms return $basename;
237}
238
- -
241=item C<dirname>
242X<dirname>
243
244This function is provided for compatibility with the Unix shell
245command C<dirname(1)> and has inherited some of its quirks. In spite of
246its name it does B<NOT> always return the directory name as you might
247expect. To be safe, if you want the directory name of a path use
248C<fileparse()>.
249
250Only on VMS (where there is no ambiguity between the file and directory
251portions of a path) and AmigaOS (possibly due to an implementation quirk in
252this module) does C<dirname()> work like C<fileparse($path)>, returning just the
253$directories.
254
255 # On VMS and AmigaOS
256 my $directories = dirname($path);
257
258When using Unix or MSDOS syntax this emulates the C<dirname(1)> shell function
259which is subtly different from how C<fileparse()> works. It returns all but
260the last level of a file path even if the last level is clearly a directory.
261In effect, it is not returning the directory portion but simply the path one
262level up acting like C<chop()> for file paths.
263
264Also unlike C<fileparse()>, C<dirname()> does not include a trailing slash on
265its returned path.
266
267 # returns /foo/bar. fileparse() would return /foo/bar/
268 dirname("/foo/bar/baz");
269
270 # also returns /foo/bar despite the fact that baz is clearly a
271 # directory. fileparse() would return /foo/bar/baz/
272 dirname("/foo/bar/baz/");
273
274 # returns '.'. fileparse() would return 'foo/'
275 dirname("foo/");
276
277Under VMS, if there is no directory information in the $path, then the
278current default device and directory is used.
279
280=cut
281
282
283
# spent 12.1s (2.99+9.08) within File::Basename::dirname which was called 35304 times, avg 342µs/call: # 13585 times (1.00s+2.82s) by RTP::Webmerge::Path::importURI at line 67 of webmerge/scripts/modules/RTP/Webmerge/Path.pm, avg 281µs/call # 12350 times (1.08s+3.37s) by RTP::Webmerge::IO::CSS::incCSS at line 87 of webmerge/scripts/modules/RTP/Webmerge/IO/CSS.pm, avg 361µs/call # 6574 times (591ms+2.05s) by RTP::Webmerge::IO::CSS::exportCSS at line 153 of webmerge/scripts/modules/RTP/Webmerge/IO/CSS.pm, avg 402µs/call # 2719 times (306ms+813ms) by RTP::Webmerge::Path::check_path at line 164 of webmerge/scripts/modules/RTP/Webmerge/Path.pm, avg 411µs/call # 39 times (3.00ms+10.4ms) by RTP::Webmerge::IO::writefile at line 216 of webmerge/scripts/modules/RTP/Webmerge/IO.pm, avg 344µs/call # 18 times (1.70ms+6.09ms) by RTP::Webmerge::Merge::writer at line 116 of webmerge/scripts/modules/RTP/Webmerge/Merge.pm, avg 433µs/call # 18 times (1.52ms+5.49ms) by RTP::Webmerge::Checksum::crcCheckEntry at line 104 of webmerge/scripts/modules/RTP/Webmerge/Checksum.pm, avg 389µs/call # once (72µs+240µs) by XML::SAX::load_parsers at line 57 of XML/SAX.pm
sub dirname {
28435304114ms my $path = shift;
285
2863530484.7ms my($type) = $Fileparse_fstype;
287
2883530456.3ms if( $type eq 'VMS' and $path =~ m{/} ) {
289 # Parse as Unix
290 local($File::Basename::Fileparse_fstype) = '';
291 return dirname($path);
292 }
293
29435304446ms353043.74s my($basename, $dirname) = fileparse($path);
# spent 3.74s making 35304 calls to File::Basename::fileparse, avg 106µs/call
295
29635304351ms 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 {
31935304375ms353045.33s _strip_trailing_sep($dirname);
# spent 5.33s making 35304 calls to File::Basename::_strip_trailing_sep, avg 151µs/call
32035304157ms unless( length($basename) ) {
321 ($basename,$dirname) = fileparse $dirname;
322 _strip_trailing_sep($dirname);
323 }
324 }
325
32635304795ms $dirname;
327}
328
329
330# Strip the trailing path separator.
331
# spent 7.32s (3.87+3.45) within File::Basename::_strip_trailing_sep which was called 51608 times, avg 142µs/call: # 35304 times (2.78s+2.55s) by File::Basename::dirname at line 319, avg 151µs/call # 16304 times (1.09s+895ms) by File::Basename::basename at line 220, avg 122µs/call
sub _strip_trailing_sep {
3325160881.4ms my $type = $Fileparse_fstype;
333
334516081.43s 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 {
341516086.47s1548243.45s $_[0] =~ s{(.)/*\z}{$1}s;
# spent 2.68s making 51608 calls to File::Basename::CORE:subst, avg 52µs/call # spent 771ms making 103216 calls to File::Basename::CORE:substcont, avg 7µs/call
342 }
343}
344
345
346=item C<fileparse_set_fstype>
347X<filesystem>
348
349 my $type = fileparse_set_fstype();
350 my $previous_type = fileparse_set_fstype($type);
351
352Normally File::Basename will assume a file path type native to your current
353operating system (ie. /foo/bar style on Unix, \foo\bar on Windows, etc...).
354With this function you can override that assumption.
355
356Valid $types are "MacOS", "VMS", "AmigaOS", "OS2", "RISCOS",
357"MSWin32", "DOS" (also "MSDOS" for backwards bug compatibility),
358"Epoc" and "Unix" (all case-insensitive). If an unrecognized $type is
359given "Unix" will be assumed.
360
361If you've selected VMS syntax, and the file specification you pass to
362one of these routines contains a "/", they assume you are using Unix
363emulation and apply the Unix syntax rules instead, for that function
364call only.
365
366=back
367
368=cut
369
370
371
# spent 55µs within File::Basename::BEGIN@371 which was called: # once (55µs+0s) by FindBin::BEGIN@84 at line 394
BEGIN {
372
373112µsmy @Ignore_Case = qw(MacOS VMS AmigaOS OS2 RISCOS MSWin32 MSDOS DOS Epoc);
374146µsmy @Types = (@Ignore_Case, qw(Unix));
375
376
# spent 525µs (310+215) within File::Basename::fileparse_set_fstype which was called: # once (310µs+215µs) by FindBin::BEGIN@84 at line 59
sub fileparse_set_fstype {
37712µs my $old = $Fileparse_fstype;
378
37913µs if (@_) {
38018µs my $new_type = shift;
381
38211µs $Fileparse_fstype = 'Unix'; # default
38316µs foreach my $type (@Types) {
38410481µs20215µs $Fileparse_fstype = $type if $new_type =~ /^$type/i;
# spent 176µs making 10 calls to File::Basename::CORE:regcomp, avg 18µs/call # spent 39µs making 10 calls to File::Basename::CORE:match, avg 4µs/call
385 }
386
387 $Fileparse_igncase =
388114µs (grep $Fileparse_fstype eq $_, @Ignore_Case) ? 1 : 0;
389 }
390
391120µs return $old;
392}
393
3941131µs155µs}
# spent 55µs making 1 call to File::Basename::BEGIN@371
395
396
397128µs1;
398
399
400=head1 SEE ALSO
401
402L<dirname(1)>, L<basename(1)>, L<File::Spec>
 
# spent 918ms within File::Basename::CORE:match which was called 51620 times, avg 18µs/call: # 51610 times (918ms+0s) by File::Basename::fileparse at line 147, avg 18µs/call # 10 times (39µs+0s) by File::Basename::fileparse_set_fstype at line 384, avg 4µs/call
sub File::Basename::CORE:match; # opcode
# spent 176µs within File::Basename::CORE:regcomp which was called 10 times, avg 18µs/call: # 10 times (176µs+0s) by File::Basename::fileparse_set_fstype at line 384, avg 18µs/call
sub File::Basename::CORE:regcomp; # opcode
# spent 2.68s within File::Basename::CORE:subst which was called 51608 times, avg 52µs/call: # 51608 times (2.68s+0s) by File::Basename::_strip_trailing_sep at line 341, avg 52µs/call
sub File::Basename::CORE:subst; # opcode
# spent 771ms within File::Basename::CORE:substcont which was called 103216 times, avg 7µs/call: # 103216 times (771ms+0s) by File::Basename::_strip_trailing_sep at line 341, avg 7µs/call
sub File::Basename::CORE:substcont; # opcode