[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

[PATCH] bugfix, AutoLoader 0.67



Hi,

attached is a diff between blead's AutoLoader (.pm and tests) and what's
shortly to become AutoLoader 0.67 on CPAN (currently there only as a dev
release: http://search.cpan.org/~smueller/AutoLoader-5.66_02/).

The patch fixes an AutoLoader issue for the strange case in which a
module file has an unexpected name and AutoLoader couldn't find
autosplit.ix via a simple s///.

Guess what, this cropped up with PAR. (And Storable.)

The patch is most certainly safe to backport to both 5.8.x and 5.10.x,
except I haven't checked their AutoLoader version. So if in doubt, copy
from the CPAN release.

Best regards,
Steffen


--- lib/AutoLoader.pm.orig	2008-09-05 13:48:26.000000000 +0200
+++ lib/AutoLoader.pm	2008-05-21 15:24:40.000000000 +0200
@@ -15,7 +15,7 @@
     $is_epoc = $^O eq 'epoc';
     $is_vms = $^O eq 'VMS';
     $is_macos = $^O eq 'MacOS';
-    $VERSION = '5.67';
+    $VERSION = '5.66';
 }
 
 AUTOLOAD {
@@ -155,20 +155,17 @@
     (my $calldir = $callpkg) =~ s#::#/#g;
     my $path = $INC{$calldir . '.pm'};
     if (defined($path)) {
-	# Try absolute path name, but only eval it if the
-        # transformation from module path to autosplit.ix path
-        # succeeded!
-	my $replaced_okay;
+	# Try absolute path name.
 	if ($is_macos) {
 	    (my $malldir = $calldir) =~ tr#/#:#;
-	    $replaced_okay = ($path =~ s#^(.*)$malldir\.pm\z#$1auto:$malldir:autosplit.ix#s);
+	    $path =~ s#^(.*)$malldir\.pm\z#$1auto:$malldir:autosplit.ix#s;
 	} else {
-	    $replaced_okay = ($path =~ s#^(.*)$calldir\.pm\z#$1auto/$calldir/autosplit.ix#);
+	    $path =~ s#^(.*)$calldir\.pm\z#$1auto/$calldir/autosplit.ix#;
 	}
 
-	eval { require $path; } if $replaced_okay;
+	eval { require $path; };
 	# If that failed, try relative path with normal @INC searching.
-	if (!$replaced_okay or $@) {
+	if ($@) {
 	    $path ="auto/$calldir/autosplit.ix";
 	    eval { require $path; };
 	}
--- lib/AutoLoader/t/01AutoLoader.t.orig	2008-09-05 13:48:31.000000000 +0200
+++ lib/AutoLoader/t/01AutoLoader.t	2008-01-08 23:14:37.000000000 +0100
@@ -14,44 +14,51 @@
 my $dir;
 BEGIN
 {
-    $dir = File::Spec->catdir( "auto-$$" );
+	$dir = File::Spec->catdir( "auto-$$" );
     unshift @INC, $dir;
 }
 
-use Test::More tests => 18;
-
-sub write_file {
-    my ($file, $text) = @_;
-    open my $fh, '>', $file
-      or die "Could not open file '$file' for writing: $!";
-    print $fh $text;
-    close $fh;
-}
+use Test::More tests => 17;
 
 # First we must set up some autoloader files
 my $fulldir = File::Spec->catdir( $dir, 'auto', 'Foo' );
 mkpath( $fulldir ) or die "Can't mkdir '$fulldir': $!";
 
-write_file( File::Spec->catfile( $fulldir, 'foo.al' ), <<'EOT' );
+open(FOO, '>', File::Spec->catfile( $fulldir, 'foo.al' ))
+	or die "Can't open foo file: $!";
+print FOO <<'EOT';
 package Foo;
 sub foo { shift; shift || "foo" }
 1;
 EOT
+close(FOO);
 
-write_file( File::Spec->catfile( $fulldir, 'bazmarkhian.al' ), <<'EOT' );
+open(BAZ, '>', File::Spec->catfile( $fulldir, 'bazmarkhian.al' ))
+	or die "Can't open bazmarkhian file: $!";
+print BAZ <<'EOT';
 package Foo;
 sub bazmarkhianish { shift; shift || "baz" }
 1;
 EOT
+close(BAZ);
 
-my $blechanawilla_text = <<'EOT';
+open(BLECH, '>', File::Spec->catfile( $fulldir, 'blechanawilla.al' ))
+       or die "Can't open blech file: $!";
+print BLECH <<'EOT';
 package Foo;
 sub blechanawilla { compilation error (
 EOT
-write_file( File::Spec->catfile( $fulldir, 'blechanawilla.al' ), $blechanawilla_text );
+close(BLECH);
+
 # This is just to keep the old SVR3 systems happy; they may fail
 # to find the above file so we duplicate it where they should find it.
-write_file( File::Spec->catfile( $fulldir, 'blechanawil.al' ), $blechanawilla_text );
+open(BLECH, '>', File::Spec->catfile( $fulldir, 'blechanawil.al' ))
+       or die "Can't open blech file: $!";
+print BLECH <<'EOT';
+package Foo;
+sub blechanawilla { compilation error (
+EOT
+close(BLECH);
 
 # Let's define the package
 package Foo;
@@ -104,18 +111,24 @@
 like( $@, qr/syntax error/i, 'require error propagates' );
 
 # test recursive autoloads
-write_file( File::Spec->catfile( $fulldir, 'a.al' ), <<'EOT' );
+open(F, '>', File::Spec->catfile( $fulldir, 'a.al'))
+	or die "Cannot make 'a' file: $!";
+print F <<'EOT';
 package Foo;
 BEGIN { b() }
 sub a { ::ok( 1, 'adding a new autoloaded method' ); }
 1;
 EOT
-write_file( File::Spec->catfile( $fulldir, 'b.al' ), <<'EOT' );
+close(F);
+
+open(F, '>', File::Spec->catfile( $fulldir, 'b.al'))
+	or die "Cannot make 'b' file: $!";
+print F <<'EOT';
 package Foo;
 sub b { ::ok( 1, 'adding a new autoloaded method' ) }
 1;
 EOT
-
+close(F);
 Foo::a();
 
 package Bar;
@@ -127,7 +140,7 @@
 AutoLoader->unimport();
 eval { Foo->baz() };
 ::like( $@, qr/locate object method "baz"/,
-        'unimport() should remove imported AUTOLOAD()' );
+	'unimport() should remove imported AUTOLOAD()' );
 
 package Baz;
 
@@ -153,70 +166,8 @@
 } # <-- deep recursion in AUTOLOAD looking for SomeClass::DESTROY?
 ::ok(1, "AutoLoader shouldn't loop forever if \%INC is modified");
 
-# Now test the bug that lead to AutoLoader 0.67:
-# If the module is loaded from a file name different than normal,
-# we could formerly have trouble finding autosplit.ix
-# Contributed by Christoph Lamprecht.
-# Recreate the following file structure:
-# auto/MyAddon/autosplit.ix
-# auto/MyAddon/testsub.al
-# MyModule.pm
-SCOPE: {
-    my $autopath = File::Spec->catdir( $dir, 'auto', 'MyAddon' );
-    mkpath( $autopath ) or die "Can't mkdir '$autopath': $!";
-    my $autosplit_text = <<'EOT';
-# Index created by AutoSplit for MyModule.pm
-#    (file acts as timestamp)
-package MyAddon;
-sub testsub ;
-1;
-EOT
-    write_file( File::Spec->catfile( $autopath, 'autosplit.ix' ), $autosplit_text );
-
-    my $testsub_text = <<'EOT';
-# NOTE: Derived from MyModule.pm.
-# Changes made here will be lost when autosplit is run again.
-# See AutoSplit.pm.
-package MyAddon;
-
-#line 13 "MyModule.pm (autosplit into auto/MyAddon/testsub.al)"
-sub testsub{
-    return "MyAddon";
-}
-
-1;
-# end of MyAddon::testsub
-EOT
-    write_file( File::Spec->catfile( $autopath, 'testsub.al' ), $testsub_text);
-
-    my $mymodule_text = <<'EOT';
-use strict;
-use warnings;
-package MyModule;
-sub testsub{return 'MyModule';}
-
-package MyAddon;
-our @ISA = ('MyModule');
-BEGIN{$INC{'MyAddon.pm'} = __FILE__}
-use AutoLoader 'AUTOLOAD';
-1;
-__END__
-
-sub testsub{
-    return "MyAddon";
-}
-EOT
-    write_file( File::Spec->catfile( $dir, 'MyModule.pm' ), $mymodule_text);
-
-    require MyModule;
-
-    my $res = MyAddon->testsub();
-    ::is ($res , 'MyAddon', 'invoke MyAddon::testsub');
-}
-
 # cleanup
 END {
-    return unless $dir && -d $dir;
-    rmtree $dir;
+	return unless $dir && -d $dir;
+	rmtree $dir;
 }
-

Follow-Ups from:
Nicholas Clark <nick@ccl4.org>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]