Randy Kobes wrote:
[...]
Those names sound good ... However, there already is a
makepath function in Apache::TestUtil, for (physically)
making a path. How about t_caturl and t_catpath?

I don't think it's correct to use 'path', since in File::Spec lingo path includes volume, whereas dir/file doesn't?


BTW, regarding Win32::GetLongPathName($f), shouldn't
File::Spec be fixed to do the right thing regarding the
short path? what about canonpath()?


In this context I'm not sure what the right thing is ...
If one passed in a short path name into File::Spec, then
for it to do a conversion to a long path name would probably
be incorrect. And similarly for passing in a long path
name and getting a short path name. I think the philosophy
of File::Spec is just to work with what's given, and leave
it to the user to do any conversions needed.

The fact that we even have to workaround File::Spec already shows that something is wrong. (i.e. r->filename doesn't return the platform specific path).


If I'm reading File::Spec correctly, canonpath is called
within catfile.

cool


+    return Apache::TestConfig::WIN32 ?
+        Win32::GetLongPathName($f) : $f;
+}
+
+sub caturl_normalized {
+    my $f = File::Spec::Unix->catfile(@_);
+    return Apache::TestConfig::WIN32 ?
+        Win32::GetLongPathName($f) : $f;

BTW, I think this code won't create the long path if you give it a relative path, since it'll never find it and won't know how to expand it. Am I correct?


}

I'd use an explicit: join '/', @_ here. It doesn't sound right to use File::Spec::Unix->catfile for constructing urls, even if it happens to do that,


Shouldn't one also do some cleanup and checks, like is done
in catpath:

sub t_catpath {
  my $file = canonpath(pop @_);
  return $file unless @_;
  my $dir = catdir(@_);
  $dir .= '/' unless substr($dir, -1) eq '/';
  return $dir.$file;
}

Doesn't canonpath taking care of cleaning the path (/ dups and such)? Can canonpath be called on a relative path?


I'm still unhappy about whatever_url() working with fs paths. I guess I'm taking my words on using Unix-> back. At least we know that we work with paths and not urls. How about this:

# concat a dir/file using unix path separators
# no platform specific path cleanups are run unless the filepath is absolute
sub t_catfile_unix {
    my $f = canonpath join "/", @_;
    return $f unless File::Spec->file_name_is_absolute($f);
    return Apache::TestConfig::WIN32 ?
        Win32::GetLongPathName($f) : $f;
}

# concat a dir/file ala catfile
# and run platform specific path cleanups if the filepath is absolute
sub t_catfile {
    my $f = File::Spec->catfile(@_);
    return $f unless File::Spec->file_name_is_absolute($f);
    return Apache::TestConfig::WIN32 ?
        Win32::GetLongPathName($f) : $f;
}

or may be even better:
 s/t_catfile_unix/t_catfile_apache/
? to denote that we catfile the apache way?

I won't try to use File::Spec::Unix instead of join '/', because one day it may stop loading on non-Unix...

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to