Faster File::Compare
[p5sagit/p5-mst-13.2.git] / lib / AutoLoader.pm
index 7d781d1..be6429e 100644 (file)
@@ -95,16 +95,25 @@ subroutine may have a shorter name that the routine itself. This can lead to
 conflicting file names. The I<AutoSplit> package warns of these potential
 conflicts when used to split a module.
 
-Calling foo($1) for the autoloaded function foo() might not work as
-expected, because the AUTOLOAD function of B<AutoLoader> clobbers the
-regexp variables.  Invoking it as foo("$1") avoids this problem.
-
 =cut
 
 AUTOLOAD {
-    my $name = "auto/$AUTOLOAD.al";
-    # Braces used on the s/// below to preserve $1 et al.
-    {$name =~ s#::#/#g}
+    my $name;
+    # Braces used to preserve $1 et al.
+    {
+     my ($pkg,$func) = $AUTOLOAD =~ /(.*)::([^:]+)$/;
+     $pkg =~ s#::#/#g;
+     if (defined($name=$INC{"$pkg.pm"}))
+      {
+       $name =~ s#^(.*)$pkg\.pm$#$1auto/$pkg/$func.al#;
+       $name = undef unless (-r $name); 
+      }
+     unless (defined $name)
+      {
+       $name = "auto/$AUTOLOAD.al";
+       $name =~ s#::#/#g;
+      }
+    }
     my $save = $@;
     eval {require $name};
     if ($@) {