You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Per Einar Ellefsen <pe...@skynet.be> on 2002/04/19 13:28:40 UTC
[PATCH] Apache::Build, Apache::TestConfig
Hi,
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: Apache-Test/lib/Apache/TestConfig.pm
===================================================================
RCS file:
/home/cvspublic/httpd-test/perl-framework/Apache-Test/lib/Apache/TestConfig.pm,v
retrieving revision 1.128
diff -u -r1.128 TestConfig.pm
--- Apache-Test/lib/Apache/TestConfig.pm 6 Apr 2002 02:39:31
-0000 1.128
+++ Apache-Test/lib/Apache/TestConfig.pm 19 Apr 2002 11:21:31 -0000
@@ -18,6 +18,7 @@
use File::Path ();
use File::Spec::Functions qw(catfile abs2rel splitdir
catdir file_name_is_absolute);
+use File::Which qw(which);
use Cwd qw(fastcwd);
use Apache::TestConfigPerl ();
@@ -1223,16 +1224,6 @@
#utils
-#duplicating small bits of Apache::Build so we dont require it
-sub which {
- foreach (map { catfile $_, $_[0] } File::Spec->path) {
- return $_ if -x;
- if (WIN32) {
- my $exe = "$_.exe";
- return $exe if -x $exe;
- }
- }
-}
sub apxs {
my($self, $q, $ok_fail) = @_;
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 19 Apr 2002 11:21:33 -0000
@@ -13,6 +13,7 @@
use ModPerl::Code ();
use ModPerl::BuildOptions ();
use Apache::TestTrace;
+use File::Which qw(which);
use constant REQUIRE_ITHREADS => grep { $^O eq $_ } qw(MSWin32);
use constant HAS_ITHREADS =>
@@ -111,11 +112,6 @@
$cflags;
}
-sub which {
- foreach (map { File::Spec->catfile($_, $_[0]) } File::Spec->path) {
- return $_ if -x;
- }
-}
#--- Perl Config stuff ---
--
Per Einar Ellefsen
per.einar@skynet.be
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [PATCH] Apache::Build, Apache::TestConfig
Posted by Doug MacEachern <do...@covalent.net>.
On Wed, 24 Apr 2002, Per Einar Ellefsen wrote:
looks good, applied to cvs, thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [PATCH] Apache::Build, Apache::TestConfig
Posted by Per Einar Ellefsen <pe...@skynet.be>.
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
per.einar@skynet.be
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org