Skip Menu |

This queue is for tickets about the Module-Find CPAN distribution.

Report information
The Basics
Id: 62923
Status: resolved
Priority: 0/
Queue: Module-Find

People
Owner: crenz [...] cpan.org
Requestors: colin.robertson [...] lovefilm.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in:
  • 0.10
  • 0.11
Fixed in: 0.12



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 -----------------------------------------------------------------------------------------------------------------------------------------
I suspect that this problem was partially fixed with the release of Module::Find 0.11, but I'm concerned by the module's treatment of @Module::Find::ModuleDirs when set to (undef)--that is, a list with a single undefined element. Looking at the code for Module::Find 0.11, I suspect that the problem still exists. The following change to the "setmoduledirs" function should fix the issue: - return @Module::Find::ModuleDirs = @_; + return @Module::Find::ModuleDirs = grep { defined } @_; On Fri Nov 12 01:23:31 2010, colin.robertson@lovefilm.com wrote: Show quoted text
> 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) {
Thank you for your contribution, and your patience. This should be fixed in v0.12 now. I have also included your suggested change.