Subject: | setmoduledirs(undef) doesn't reset to searching @INC |
Date: | Thu, 11 Nov 2010 14:23:10 +0000 |
To: | bug-Module-Find [...] rt.cpan.org |
From: | Colin Robertson <colin.robertson [...] lovefilm.com> |
There appears to be a bug in Module::Find 0.10 when setting
setmoduledirs to undef to switch back to the default behaviour of
searching @INC. This can be reproduced with the following code:
use Module::Find;
use Data::Dumper;
print Dumper([findallmod('CGI')]);
setmoduledirs('foo');
setmoduledirs(undef);
print Dumper([findallmod('CGI')]);'
On my system this prints:
$VAR1 = [
'CGI::Cookie',
'CGI::Util',
'CGI::Pretty',
'CGI::Carp',
'CGI::Push',
'CGI::Switch',
'CGI::Apache',
'CGI::Fast'
];
$VAR1 = [];
(Substituting setmoduledirs(undef) with setmoduledirs() has the same
effect.)
The issue is at line 169 with the check:
if (defined @Module::Find::ModuleDirs) {
'perldoc -f defined' says:
Use of "defined" on aggregates (hashes and arrays) is depre‐
cated. It used to report whether memory for that aggregate has
ever been allocated. This behavior may disappear in future
versions of Perl. You should instead use a simple test for
size: ...
To fix the bug while preserving the documented interface I'd suggest
something like the following (untested) code:
sub setmoduledirs {
if (!@_ || (@_ == 1 && !defined($_[0])) {
@Module::Find::ModuleDirs = ();
return;
}
else {
return @Module::Find::ModuleDirs = @_;
}
}
and then the check at line 169 would become:
if (@Module::Find::ModuleDirs) {
-----------------------------------------------------------------------------------------------------------------------------------------
LOVEFiLM UK Limited is a company registered in England and Wales.
Registered Number: 06528297.
Registered Office: No.9, 6 Portal Way, London W3 6RU, United Kingdom.
This e-mail is confidential to the ordinary user of the e-mail address to which it was addressed. If you have received it in error,
please delete it from your system and notify the sender immediately.
This email message has been delivered safely and archived online by Mimecast.
For more information please visit http://www.mimecast.co.uk
-----------------------------------------------------------------------------------------------------------------------------------------