Subject: | suggest masking Module::Utils find_installed() too |
Date: | Sat, 06 Nov 2010 10:49:21 +1100 |
To: | bug-Module-Mask [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
I was using Module::Utils find_installed() to see if a module is
available, without loading it. As an idea for a feature, Module::Mask
might subvert or mangle find_installed() to not find masked modules.
For interest, I threw down the few lines below. I'm not sure if it's a
good idea to mangle like this always. If Module::Mask loads
Module::Util anyway then there'd be an opportunity to do it always.
I think mangling like this doesn't affect already-imported copies of
find_installed(), so it might be desirable to insist Module::Util is not
already loaded, or warn if not, or something.
{
my $orig = \&Module::Util::find_installed;
my $repl = sub ($;@) {
my ($module, @inc) = @_;
if ($VERBOSE >= 2) {
print STDERR "Module::Util::find_installed() $module\n";
}
my $module_path = Module::Util::module_path($module);
if (! @inc) {
@inc = @INC;
}
foreach my $inc (@inc) {
if ($VERBOSE >= 2) {
print STDERR "consider $inc\n";
}
if (ref $inc) {
if (Scalar::Util::blessed($inc)
&& $inc->isa('Module::Mask')
&& $inc->is_masked($module)) {
if ($VERBOSE) {
print STDERR "Module::Util::find_installed() wrap: $module masked by Module::Mask\n";
}
return undef;
}
} else {
my $fullpath = "$inc/$module_path";
if (-e $fullpath) {
if ($VERBOSE >= 2) {
print STDERR "found in dir $inc\n";
}
return $fullpath;
}
}
}
return undef;
};
no warnings 'redefine';
*Module::Util::find_installed = $repl;
}