httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject Re: libapreq-1.2 release candidate
Date Fri, 02 May 2003 01:25:34 GMT
Randy Kobes wrote:
> On Thu, 1 May 2003, Stas Bekman wrote:
> 
> 
>>David Wheeler wrote:
> 
> [ ... ]
> 
>>>No, the point is that when I told `find` to search for
>>>"test.pm" it didn't find any "Test.pm" files, and when I told
>>>it to search for "Test.pm" it didn't find any "test.pm"
>>>files. So it pays attention to the case you tell it to look
>>>for when it searches the file system.  Theoretically, Perl
>>>can do this, too, at least on case-insensitive file systems
>>>that are also case-preserving.
>>
>>Ah, that's cool. Care to ask this question at p5p? If there is
>>some pragma that can solve that, that'll be the end of the
>>story.
> 
> 
> Although not perhaps ideal, what about something like the
> following? As an example, Digest::SHA1 exports a function sha1().
> Doing then
> 
> eval{ require Digest::SHA1;
>       import Digest::SHA1 qw(sha1);
>       sha1(); };
> print "Oh oh ... : $@\n" if $@;
> 
> is OK, but
> 
> eval{ require Digest::SHa1;
>       import Digest::SHa1 qw(sha1);
>       sha1(); };
> print "Oh oh ... : $@\n" if $@;
> 
> prints out that an undefined subroutine &main::sha1 was called.
> The call to sha1() is needed for systems, like Win32, and perhaps
> also MAC OS X, that preserve case when writing filenames but are
> otherwise case insensitive.
> 
> Alternatively, like David illustrated from the system, one can
> from Perl see if the particular module file exists, by going
> through @INC, using readdir to get a listing, and then grepping
> through the listing for a particular filename - this will honor
> case:
> 
> my $hit;
> foreach (@INC) {
>   my $dir = "$_/Digest";
>   next unless -d $dir;
>   opendir(DIR, $dir) or die "Cannot opendir $dir: $!\n";
>   my @matches = grep {/^SHa1.pm$/} readdir DIR;
>   closedir DIR;
>   $hit++ if @matches;
> }
> 
> print "Oh oh - it's not there ...\n" unless $hit;

Thank you Randy for that idea!!!

we still have a problem with CPAN not installing Apache::Test if Apache::test 
has a higher version. Just need to make sure that it's higher.

So we introduce Apache::TestLoad, whose only purpose is to load the right 
Apache::Test. Randy, David, can you please try this patch against the current 
cvs (e.g. Apache-Test inside the modperl-2.0 cvs rep).

This should be really made into a perl pragma, which should do this work. e.g.:

use require 'casesensitive';
require Apache::Test;

which will override CORE::require, do a normal require, test that it gets the 
$VERSION from the given package and if not, do the dir scan. Unfortunately 
GLOBAL::CORE::require became overridable only in the recent perl versions (I 
think 5.6.1).

Index: lib/Apache/TestMM.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestMM.pm,v
retrieving revision 1.25
diff -u -r1.25 TestMM.pm
--- lib/Apache/TestMM.pm	1 May 2003 06:22:35 -0000	1.25
+++ lib/Apache/TestMM.pm	2 May 2003 01:21:56 -0000
@@ -4,6 +4,7 @@
  use warnings FATAL => 'all';

  use Config;
+use Apache::TestLoad ();
  use Apache::TestConfig ();
  use Apache::TestTrace;


--- /dev/null	1970-01-01 10:00:00.000000000 +1000
+++ lib/Apache/TestLoad.pm	2003-05-02 11:21:56.000000000 +1000
@@ -0,0 +1,51 @@
+package Apache::TestLoad;
+
+use strict;
+use warnings FATAL => 'all';
+
+use File::Spec::Functions qw(catfile catdir);
+
+require Apache::Test;
+
+unless (defined $Apache::Test::VERSION) {
+    foreach (@INC) {
+        my $dir = catdir $_, "Apache";
+        next unless -d $dir;
+        opendir DIR, $dir or die "Cannot opendir $dir: $!\n";
+        my @matches = grep /^Test.pm$/, readdir DIR;
+        closedir DIR;
+        next unless @matches;
+        my $file = catfile $dir, $matches[0];
+        do $file;
+        last;
+    }
+}
+
+die "Still can't find Apache::Test"
+    unless defined defined $Apache::Test::VERSION;
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Apache::TestLoad - Load the correct Apache::Test
+
+=head1 SYNOPSIS
+
+  use Apache::TestLoad;
+
+=head1 DESCRIPTION
+
+If you want to use C<Apache::Test>, you should load
+C<Apache::TestLoad> instead. This is a workaround because some case
+insensitive filesystems may load I<Apache/test.pm> instead of
+I<Apache/Test.pm> where mod_perl 1.0 is installed.
+
+Luckily we can manually walk the @INC dirs and force to load
+I<Apache/Test.pm>.
+
+=cut

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


Mime
View raw message