| File | /usr/share/perl/5.8/File/Spec/Unix.pm | Statements Executed | 407 | Total Time | 0.000676 seconds |
| Calls | Inclusive Time | Subroutine | |
|---|---|---|---|
| 31 | 0.00070 | File::Spec::Unix:: | canonpath |
| 10 | 0.00067 | File::Spec::Unix:: | catfile |
| 10 | 0.00035 | File::Spec::Unix:: | catdir |
| 5 | 0.00010 | File::Spec::Unix:: | splitdir |
| 6 | 0.00005 | File::Spec::Unix:: | file_name_is_absolute |
| 0 | 0 | File::Spec::Unix:: | BEGIN |
| 0 | 0 | File::Spec::Unix:: | _collapse |
| 0 | 0 | File::Spec::Unix:: | _cwd |
| 0 | 0 | File::Spec::Unix:: | _tmpdir |
| 0 | 0 | File::Spec::Unix:: | abs2rel |
| 0 | 0 | File::Spec::Unix:: | catpath |
| 0 | 0 | File::Spec::Unix:: | join |
| 0 | 0 | File::Spec::Unix:: | no_upwards |
| 0 | 0 | File::Spec::Unix:: | path |
| 0 | 0 | File::Spec::Unix:: | rel2abs |
| 0 | 0 | File::Spec::Unix:: | splitpath |
| 0 | 0 | File::Spec::Unix:: | tmpdir |
| Line | Stmts. | Exclusive Time | Avg. | Code |
|---|---|---|---|---|
| 1 | package File::Spec::Unix; | |||
| 2 | ||||
| 3 | use strict; | |||
| 4 | use vars qw($VERSION); | |||
| 5 | ||||
| 6 | $VERSION = '1.5'; | |||
| 7 | ||||
| 8 | # spent 0.00070s within File::Spec::Unix::canonpath which was called 31 times, avg 0.00002s/call:
# 10 times (0.00016s) by File::Spec::Unix::catfile at line 42 of /usr/share/perl/5.8/File/Spec/Unix.pm, avg 0.00002s/call
# 10 times (0.00026s) by File::Spec::Unix::catdir at line 37 of /usr/share/perl/5.8/File/Spec/Unix.pm, avg 0.00003s/call
# 5 times (0.00014s) by HTML::Template::Pro::_find_file at line 333 of /usr/local/lib/perl/5.8.8/HTML/Template/Pro.pm, avg 0.00003s/call
# 5 times (0.00011s) by HTML::Template::Pro::_find_file at line 320 of /usr/local/lib/perl/5.8.8/HTML/Template/Pro.pm, avg 0.00002s/call
# 1 times (0.00003s) by HTML::Template::Pro::_find_file at line 314 of /usr/local/lib/perl/5.8.8/HTML/Template/Pro.pm sub canonpath { | |||
| 9 | 31 | 0.00003 | 9e-07 | my ($self,$path) = @_; |
| 10 | ||||
| 11 | # Handle POSIX-style node names beginning with double slash (qnx, nto) | |||
| 12 | # Handle network path names beginning with double slash (cygwin) | |||
| 13 | # (POSIX says: "a pathname that begins with two successive slashes | |||
| 14 | # may be interpreted in an implementation-defined manner, although | |||
| 15 | # more than two leading slashes shall be treated as a single slash.") | |||
| 16 | 31 | 0.00001 | 4e-07 | my $node = ''; |
| 17 | 31 | 0.00007 | 2e-06 | if ( $^O =~ m/^(?:qnx|nto|cygwin)$/ && $path =~ s:^(//[^/]+)(/|\z):/:s ) { |
| 18 | $node = $1; | |||
| 19 | } | |||
| 20 | # This used to be | |||
| 21 | # $path =~ s|/+|/|g unless($^O eq 'cygwin'); | |||
| 22 | # but that made tests 29, 30, 35, 46, and 213 (as of #13272) to fail | |||
| 23 | # (Mainly because trailing "" directories didn't get stripped). | |||
| 24 | # Why would cygwin avoid collapsing multiple slashes into one? --jhi | |||
| 25 | 31 | 0.00015 | 5e-06 | $path =~ s|/+|/|g; # xx////xx -> xx/xx |
| 26 | 31 | 0.00002 | 6e-07 | $path =~ s@(/\.)+(/|\Z(?!\n))@/@g; # xx/././xx -> xx/xx |
| 27 | 31 | 0.00003 | 9e-07 | $path =~ s|^(\./)+||s unless $path eq "./"; # ./xx -> xx |
| 28 | 31 | 0.00002 | 5e-07 | $path =~ s|^/(\.\./)+|/|; # /../../xx -> xx |
| 29 | 31 | 0.00002 | 5e-07 | $path =~ s|^/\.\.$|/|; # /.. -> / |
| 30 | 31 | 0.00003 | 1e-06 | $path =~ s|/\Z(?!\n)|| unless $path eq "/"; # xx/ -> xx |
| 31 | 31 | 0.00006 | 2e-06 | return "$node$path"; |
| 32 | } | |||
| 33 | ||||
| 34 | # spent 0.00035s within File::Spec::Unix::catdir which was called 10 times, avg 0.00003s/call:
# 10 times (0.00035s) by File::Spec::Unix::catfile at line 44 of /usr/share/perl/5.8/File/Spec/Unix.pm, avg 0.00003s/call sub catdir { | |||
| 35 | 10 | 6e-06 | 6e-07 | my $self = shift; |
| 36 | ||||
| 37 | 10 | 0.00006 | 6e-06 | $self->canonpath(join('/', @_, '')); # '' because need a trailing '/' # spent 0.00026s making 10 calls to File::Spec::Unix::canonpath, avg 0.00003s/call |
| 38 | } | |||
| 39 | ||||
| 40 | # spent 0.00067s within File::Spec::Unix::catfile which was called 10 times, avg 0.00007s/call:
# 5 times (0.00033s) by HTML::Template::Pro::_find_file at line 320 of /usr/local/lib/perl/5.8.8/HTML/Template/Pro.pm, avg 0.00007s/call
# 5 times (0.00034s) by HTML::Template::Pro::_find_file at line 332 of /usr/local/lib/perl/5.8.8/HTML/Template/Pro.pm, avg 0.00007s/call sub catfile { | |||
| 41 | 10 | 5e-06 | 5e-07 | my $self = shift; |
| 42 | 10 | 0.00004 | 4e-06 | my $file = $self->canonpath(pop @_); # spent 0.00016s making 10 calls to File::Spec::Unix::canonpath, avg 0.00002s/call |
| 43 | 10 | 5e-06 | 5e-07 | return $file unless @_; |
| 44 | 10 | 0.00005 | 5e-06 | my $dir = $self->catdir(@_); # spent 0.00035s making 10 calls to File::Spec::Unix::catdir, avg 0.00003s/call |
| 45 | 10 | 0.00002 | 2e-06 | $dir .= "/" unless substr($dir,-1) eq "/"; |
| 46 | 10 | 0.00002 | 2e-06 | return $dir.$file; |
| 47 | } | |||
| 48 | ||||
| 49 | sub curdir () { '.' } | |||
| 50 | ||||
| 51 | sub devnull () { '/dev/null' } | |||
| 52 | ||||
| 53 | sub rootdir () { '/' } | |||
| 54 | ||||
| 55 | my $tmpdir; | |||
| 56 | sub _tmpdir { | |||
| 57 | return $tmpdir if defined $tmpdir; | |||
| 58 | my $self = shift; | |||
| 59 | my @dirlist = @_; | |||
| 60 | { | |||
| 61 | no strict 'refs'; | |||
| 62 | if (${"\cTAINT"}) { # Check for taint mode on perl >= 5.8.0 | |||
| 63 | require Scalar::Util; | |||
| 64 | @dirlist = grep { ! Scalar::Util::tainted($_) } @dirlist; | |||
| 65 | } | |||
| 66 | } | |||
| 67 | foreach (@dirlist) { | |||
| 68 | next unless defined && -d && -w _; | |||
| 69 | $tmpdir = $_; | |||
| 70 | last; | |||
| 71 | } | |||
| 72 | $tmpdir = $self->curdir unless defined $tmpdir; | |||
| 73 | $tmpdir = defined $tmpdir && $self->canonpath($tmpdir); | |||
| 74 | return $tmpdir; | |||
| 75 | } | |||
| 76 | ||||
| 77 | sub tmpdir { | |||
| 78 | return $tmpdir if defined $tmpdir; | |||
| 79 | $tmpdir = $_[0]->_tmpdir( $ENV{TMPDIR}, "/tmp" ); | |||
| 80 | } | |||
| 81 | ||||
| 82 | sub updir () { '..' } | |||
| 83 | ||||
| 84 | sub no_upwards { | |||
| 85 | my $self = shift; | |||
| 86 | return grep(!/^\.{1,2}\Z(?!\n)/s, @_); | |||
| 87 | } | |||
| 88 | ||||
| 89 | sub case_tolerant () { 0 } | |||
| 90 | ||||
| 91 | # spent 0.00005s within File::Spec::Unix::file_name_is_absolute which was called 6 times, avg 8e-06s/call:
# 6 times (0.00005s) by HTML::Template::Pro::_find_file at line 314 of /usr/local/lib/perl/5.8.8/HTML/Template/Pro.pm, avg 8e-06s/call sub file_name_is_absolute { | |||
| 92 | 6 | 4e-06 | 7e-07 | my ($self,$file) = @_; |
| 93 | 6 | 0.00001 | 2e-06 | return scalar($file =~ m:^/:s); |
| 94 | } | |||
| 95 | ||||
| 96 | sub path { | |||
| 97 | return () unless exists $ENV{PATH}; | |||
| 98 | my @path = split(':', $ENV{PATH}); | |||
| 99 | foreach (@path) { $_ = '.' if $_ eq '' } | |||
| 100 | return @path; | |||
| 101 | } | |||
| 102 | ||||
| 103 | sub join { | |||
| 104 | my $self = shift; | |||
| 105 | return $self->catfile(@_); | |||
| 106 | } | |||
| 107 | ||||
| 108 | sub splitpath { | |||
| 109 | my ($self,$path, $nofile) = @_; | |||
| 110 | ||||
| 111 | my ($volume,$directory,$file) = ('','',''); | |||
| 112 | ||||
| 113 | if ( $nofile ) { | |||
| 114 | $directory = $path; | |||
| 115 | } | |||
| 116 | else { | |||
| 117 | $path =~ m|^ ( (?: .* / (?: \.\.?\Z(?!\n) )? )? ) ([^/]*) |xs; | |||
| 118 | $directory = $1; | |||
| 119 | $file = $2; | |||
| 120 | } | |||
| 121 | ||||
| 122 | return ($volume,$directory,$file); | |||
| 123 | } | |||
| 124 | ||||
| 125 | # spent 0.00010s within File::Spec::Unix::splitdir which was called 5 times, avg 0.00002s/call:
# 5 times (0.00010s) by HTML::Template::Pro::_get_filepath at line 301 of /usr/local/lib/perl/5.8.8/HTML/Template/Pro.pm, avg 0.00002s/call sub splitdir { | |||
| 126 | 5 | 0.00002 | 5e-06 | return split m|/|, $_[1], -1; # Preserve trailing fields |
| 127 | } | |||
| 128 | ||||
| 129 | sub catpath { | |||
| 130 | my ($self,$volume,$directory,$file) = @_; | |||
| 131 | ||||
| 132 | if ( $directory ne '' && | |||
| 133 | $file ne '' && | |||
| 134 | substr( $directory, -1 ) ne '/' && | |||
| 135 | substr( $file, 0, 1 ) ne '/' | |||
| 136 | ) { | |||
| 137 | $directory .= "/$file" ; | |||
| 138 | } | |||
| 139 | else { | |||
| 140 | $directory .= $file ; | |||
| 141 | } | |||
| 142 | ||||
| 143 | return $directory ; | |||
| 144 | } | |||
| 145 | ||||
| 146 | sub abs2rel { | |||
| 147 | my($self,$path,$base) = @_; | |||
| 148 | ||||
| 149 | # Figure out the effective $base and clean it up. | |||
| 150 | if ( !defined( $base ) || $base eq '' ) { | |||
| 151 | $base = $self->_cwd(); | |||
| 152 | } | |||
| 153 | elsif ( ! $self->file_name_is_absolute( $base ) ) { | |||
| 154 | if ( ! $self->file_name_is_absolute( $path ) ) { | |||
| 155 | # optimisation where both paths are relative: save 2 x cwd | |||
| 156 | $base = $self->canonpath( "/$base" ); | |||
| 157 | $path = "/$path"; | |||
| 158 | } | |||
| 159 | else { | |||
| 160 | $base = $self->rel2abs( $base ) ; | |||
| 161 | } | |||
| 162 | } | |||
| 163 | else { | |||
| 164 | $base = $self->canonpath( $base ) ; | |||
| 165 | } | |||
| 166 | ||||
| 167 | # Clean up $path | |||
| 168 | if ( ! $self->file_name_is_absolute( $path ) ) { | |||
| 169 | $path = $self->rel2abs( $path ) ; | |||
| 170 | } | |||
| 171 | else { | |||
| 172 | $path = $self->canonpath( $path ) ; | |||
| 173 | } | |||
| 174 | ||||
| 175 | # Now, remove all leading components that are the same | |||
| 176 | my @pathchunks = $self->splitdir( $path); | |||
| 177 | my @basechunks = $self->splitdir( $base); | |||
| 178 | ||||
| 179 | while (@pathchunks && @basechunks && $pathchunks[0] eq $basechunks[0]) { | |||
| 180 | shift @pathchunks ; | |||
| 181 | shift @basechunks ; | |||
| 182 | } | |||
| 183 | ||||
| 184 | $path = CORE::join( '/', @pathchunks ); | |||
| 185 | $base = CORE::join( '/', @basechunks ); | |||
| 186 | ||||
| 187 | # $base now contains the directories the resulting relative path | |||
| 188 | # must ascend out of before it can descend to $path_directory. So, | |||
| 189 | # replace all names with $parentDir | |||
| 190 | $base =~ s|[^/]+|..|g ; | |||
| 191 | ||||
| 192 | # Glue the two together, using a separator if necessary, and preventing an | |||
| 193 | # empty result. | |||
| 194 | if ( $path ne '' && $base ne '' ) { | |||
| 195 | $path = "$base/$path" ; | |||
| 196 | } else { | |||
| 197 | $path = "$base$path" ; | |||
| 198 | } | |||
| 199 | ||||
| 200 | return $self->canonpath( $path ) ; | |||
| 201 | } | |||
| 202 | ||||
| 203 | sub rel2abs { | |||
| 204 | my ($self,$path,$base ) = @_; | |||
| 205 | ||||
| 206 | # Clean up $path | |||
| 207 | if ( ! $self->file_name_is_absolute( $path ) ) { | |||
| 208 | # Figure out the effective $base and clean it up. | |||
| 209 | if ( !defined( $base ) || $base eq '' ) { | |||
| 210 | $base = $self->_cwd(); | |||
| 211 | } | |||
| 212 | elsif ( ! $self->file_name_is_absolute( $base ) ) { | |||
| 213 | $base = $self->rel2abs( $base ) ; | |||
| 214 | } | |||
| 215 | else { | |||
| 216 | $base = $self->canonpath( $base ) ; | |||
| 217 | } | |||
| 218 | ||||
| 219 | # Glom them together | |||
| 220 | $path = $self->catdir( $base, $path ) ; | |||
| 221 | } | |||
| 222 | ||||
| 223 | return $self->canonpath( $path ) ; | |||
| 224 | } | |||
| 225 | ||||
| 226 | # Internal routine to File::Spec, no point in making this public since | |||
| 227 | # it is the standard Cwd interface. Most of the platform-specific | |||
| 228 | # File::Spec subclasses use this. | |||
| 229 | sub _cwd { | |||
| 230 | require Cwd; | |||
| 231 | Cwd::cwd(); | |||
| 232 | } | |||
| 233 | ||||
| 234 | # Internal method to reduce xx\..\yy -> yy | |||
| 235 | sub _collapse { | |||
| 236 | my($fs, $path) = @_; | |||
| 237 | ||||
| 238 | my $updir = $fs->updir; | |||
| 239 | my $curdir = $fs->curdir; | |||
| 240 | ||||
| 241 | my($vol, $dirs, $file) = $fs->splitpath($path); | |||
| 242 | my @dirs = $fs->splitdir($dirs); | |||
| 243 | ||||
| 244 | my @collapsed; | |||
| 245 | foreach my $dir (@dirs) { | |||
| 246 | if( $dir eq $updir and # if we have an updir | |||
| 247 | @collapsed and # and something to collapse | |||
| 248 | length $collapsed[-1] and # and its not the rootdir | |||
| 249 | $collapsed[-1] ne $updir and # nor another updir | |||
| 250 | $collapsed[-1] ne $curdir # nor the curdir | |||
| 251 | ) | |||
| 252 | { # then | |||
| 253 | pop @collapsed; # collapse | |||
| 254 | } | |||
| 255 | else { # else | |||
| 256 | push @collapsed, $dir; # just hang onto it | |||
| 257 | } | |||
| 258 | } | |||
| 259 | ||||
| 260 | return $fs->catpath($vol, | |||
| 261 | $fs->catdir(@collapsed), | |||
| 262 | $file | |||
| 263 | ); | |||
| 264 | } | |||
| 265 | ||||
| 266 | 1; |