Stas told me we didn't want any more dependencies, so I cancel this patch 
and resubmit and other one which does the same only inline in Build.pm.

At 13:28 19.04.2002, Per Einar Ellefsen wrote:

>I've created a File::Which module for use for the mod_perl site and which 
>exports a which() function based on the one in mod_perl 2.0. I've tweaked 
>it a little so it works with different extensions on Win32 too. And it 
>handles ~ in the PATH correctly.
>
>Here is a patch to use this instead of misc. which subroutines in mod_perl 2.
>
>I'm not able to test it as I can't compile mod_perl myself (Win32 here), 
>but unless there's a serious bug in the module, I don't see any reasons 
>for it not working.
>I suppose you will have to add File::Which as a prerequisite (and in turn 
>it needs File::Spec and File::HomeDir ), but I couldn't find the place to 
>do that.


Index: lib/Apache/Build.pm
===================================================================
RCS file: /home/cvspublic/modperl-2.0/lib/Apache/Build.pm,v
retrieving revision 1.79
diff -u -r1.79 Build.pm
--- lib/Apache/Build.pm 7 Apr 2002 02:56:52 -0000       1.79
+++ lib/Apache/Build.pm 24 Apr 2002 12:29:05 -0000
@@ -111,11 +111,40 @@
      $cflags;
  }

+
+my @path_ext = ('');        # For Win32 systems, stores the extensions 
used for
+                            # executable files
+                            # For others, the empty string is used
+                            # because 'perl' . '' eq 'perl' => easier
+if (is_win32) {
+    if ($ENV{PATHEXT}) {    # WinNT
+        push @path_ext, split ';', $ENV{PATHEXT};
+    }
+    else {
+        push @path_ext, map { ".$_" } qw(com exe bat); # Win9X: doesn't 
have PATHEXT, so needs hardcoded.
+    }
+}
+
  sub which {
-    foreach (map { File::Spec->catfile($_, $_[0]) } File::Spec->path) {
-       return $_ if -x;
+    my ($exec, $opt) = @_;
+
+    return undef unless $exec;
+
+    my @results = ();
+
+    for my $base (map { catfile($_, $exec) } File::Spec->path()) {
+
+        if ($ENV{HOME} and not is_win32) {
+            # only works on Unix, but that's
+            # normal: on Win32 the shell doesn't treat '~' specially.
+            $base =~ s/~/$ENV{HOME}/o;
+        }
+        for my $ext (@path_ext) {
+            return $base.$ext if-x $base.$ext
+        }
      }
  }
+

  #--- Perl Config stuff ---




-- 
Per Einar Ellefsen
[EMAIL PROTECTED]



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

Reply via email to