develooper Front page | perl.perl5.porters | Postings from October 2003

Re: 5.8.2 perldelta

Stas Bekman
October 29, 2003 17:56
Re: 5.8.2 perldelta
Message ID:
Here is a test which demonstrates why the new change in require is broken 
(IMHO) (besides a completely hosed mod_perl 1.0 test suite):

use Cwd;
use File::Spec::Functions qw(catdir);
use lib qw(.);

my $i = 1;
my $file = "";
my $cwd = cwd;
my $not_cwd = catdir $cwd, "foo";

mkdir $not_cwd;
write_file($file, qq[die "can't find $file" unless -e $file; 1;\n]);

for my $expected_failure (1,0) {
     chdir $expected_failure ? $not_cwd : $cwd;
     eval { require $file };
     print map { "# $_\n" } split /\n/, $@ if $@;

     print "not " if $expected_failure xor $@;
     print "ok ", $i++, "\n";

     print "not " unless exists $INC{$file};
     print "ok ", $i++, "\n";
chdir $cwd;
unlink $file;
rmdir $not_cwd;

sub write_file {
     my($file, $data) = @_;
     open my $fh, ">$file" or die $!;
     print $fh $data;
     close $fh;

% perl-5.8.1 /tmp/nick
# can't find at line 1.
# Compilation failed in require at /tmp/nick line 12.
ok 1
ok 2
ok 3
ok 4

% perl-5.8.2 /tmp/nick
# can't find at line 1.
# Compilation failed in require at /tmp/nick line 12.
ok 1
ok 2
# Compilation failed in require at /tmp/nick line 12.
not ok 3
ok 4

Here is the problem. If a module fails to load once it must not be 
blacklisted. The test demonstrates how a module may fail if loaded from the 
wrong directory, but then is supposed to succeed if moved to a different 

Imagine a real world situation: program A tries to load module Foo, but fails 
for some reason. Now program B tries to load module Foo and it succeeds (e.g. 
this time loaded from the proper directory, or some other condition became 
true). Now run both program from a persistent enviroment like mod_perl. 
Program A prevents from program B to load module Foo. The only way to fix that 
problem is to delete $INC{""} in program B. But this is abnormal since 
the developer of program B, had no idea that some other program may do 
something that will require a cleanup of %INC.

It's quite possible that there are more situations when this change breaks 
things. I have found only one so far. If someone has other idea please speak up.

Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker     mod_perl Guide ---> Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About