Subject: | load_extensions() causes "Subroutine %s redefined" warnings |
I've created a module that uses a pair of "private extension" modules, Module::Install::PRIVATE and Module::Install::PRIVATE::Foo. The latter one inherits from the former one, which in turn inherits from Module::Install::Base.
Each extension has a method with a suitably "unique" name such that the autoloader will correctly find it. These methods simply return the object on which they were invoked, and the object can then be used to invoke further methods on (which perhaps have less "unique" names and which could not therefore be reliably found by the autoloader).
An example of this setup is in the attached "Foo.tar.gz" archive.
You will note that running "perl Makefile.PL" produces two "Subroutine %s redefined" warnings:
Subroutine get_private_obj redefined at inc/Module/Install/PRIVATE.pm line 6.
Subroutine greeting redefined at inc/Module/Install/PRIVATE.pm line 7.
I believe that the reason for this is that inc/Module/Install/PRIVATE.pm gets loaded once (by load_extensions()) in the course of looking for get_private_mymodule_obj(), and then again (by inc/Module/Install/PRIVATE/Foo.pm) when it is finally located.
The reason that inc/Module/Install/PRIVATE/Foo.pm loads inc/Module/Install/PRIVATE.pm even though it has already been loaded is that load_extensions() removed the entry for that file from %INC, so Perl "forgets" that is has already been loaded. This is what causes the warnings.
Is there any particular reason why load_extensions() removes entries from %INC?
If not, then the following patch (against 0.33) fixes this problem. It certainly works fine for me:
--- lib/Module/Install.pm.orig 2004-03-11 12:55:22.000000000 +0000
+++ lib/Module/Install.pm 2004-03-31 10:29:25.758297000 +0100
@@ -265,7 +265,7 @@
next if $self->{pathnames}{$pkg};
eval { require $file; 1 } or (warn($@), next);
- $self->{pathnames}{$pkg} = delete $INC{$file};
+ $self->{pathnames}{$pkg} = $INC{$file};
push @{$self->{extensions}}, $pkg->new( _top => $top_obj );
}
}
End of Patch.
There are also some similar deletions in Module::Install::import(), with the comment "Unregister loader and worker packages so subdirs can use them again". I haven't actually seen any problems from this, but I wonder if it might have the same problem again?
This is all running with Perl 5.8.3 on WinXP.
Cheers,
- Steve
Message body not shown because it is not plain text.