perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject resolving Apache::Test vs. Apache::test collision
Date Tue, 06 May 2003 00:01:00 GMT
We have a problem with using the Apache::Test name, more correctly we have a 
problem with using the Apache/Test.pm filename. On platforms with 
case-insentive filesystems (winFU, Mac OS X) if mod_perl 1.x is installed, 
there is Apache/test.pm (notice the lower case 't'). So when you say 'use 
Apache::Test' it loads Apache::test. Boom, nothing works.

There are several routes we can take to resolve this problem:

1. rename Apache::Test to something else. David Wheeler has proposed to use 
Apache::Tester (or even swap the sides: Test::Apache).

2. add a new package Apache::TestLoad which will deal with loading the right 
Apache::Test package, by replacing 'require Apache::Test' with search for 
'Apache/Test.pm' in @INC and doing do $file; on the full path. That solves the 
problem, of loading the right file but you will have to replace all instances 
of 'use Apache::Test;' with 'use Apache::TestLoad;', but still using the 
functions from Apache::Test. Since they are all imported by default, this is 
not a big issue. It's just confusing that use 'Apache::TestLoad'.

So the first solution is probably the cleanest in the long run, there will be 
some mess while moving things to a new name, but since I don't think many 
developers are using this package yet, it won't be as bad as it could be at a 
later stage.

The second solution allows to keep things as they are on CPAN, cvs rep, etc, 
but s/use Apache::Test;/use Apache::TestLoad;/

To me the first solution is favorite for the users of the module, the second 
one for its maintainers.

Now please help to make the right choice, and if of course you have other 
ideas, let us know.

And the patch for the second solution:

find t -type f -exec perl -pi -e 's/use Apache::Test;/use Apache::TestLoad;/' 
{} \;

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	5 May 2003 00:01:44 -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-05 09:50:29.000000000 +1000
@@ -0,0 +1,57 @@
+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;
+
+sub import {
+    my $package = shift;
+    unshift @_, 'Apache::Test';
+    goto &{Apache::Test->can('import')};
+}
+
+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

-- 


__________________________________________________________________
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


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Mime
View raw message