Skip Menu |

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

Report information
The Basics
Id: 62752
Status: open
Priority: 0/
Queue: Module-Mask

People
Owner: Nobody in particular
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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; }
On Fri Nov 05 19:50:07 2010, user42@zip.com.au wrote: Show quoted text
> 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. >
Sorry it's taken me so very long to reply. I see you've created Module::Util::Masked to scratch that particular itch. I think this might actually be a preferable way of implementing this, because it allows for the opposite case to be catered for, where you want to prevent loading of modules without find_installed et al lying to you about the filesystem. If Module::Mask *always* monkeyed with the static functions in Module::Util there would be a risk of unintended consequences, so I like the fact that you have to explicitly ask Module::Util::Masked to do it for you. In some ways this makes me wish I'd gone with an OO approach with Module::Util, at least on some level, because it seems like it would be much easier to overlay these changes as a subclass. Would you mind if I link to Module::Util::Masked in the Module::Mask documentation?
Subject: Re: [rt.cpan.org #62752] suggest masking Module::Utils find_installed() too
Date: Sun, 04 Mar 2012 09:08:36 +1100
To: bug-Module-Mask [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Matthew Lawrence via RT" <bug-Module-Mask@rt.cpan.org> writes: Show quoted text
> > I see you've created Module::Util::Masked
Ah I forgot about this ticket and made some code :-). Show quoted text
> I think this might actually be a preferable way
Yes, especially as it depends a bit on how the masking modules have decided to implement themselves. Show quoted text
> In some ways this makes me wish I'd gone with an OO approach with > Module::Util, at least on some level, because it seems like it would be > much easier to overlay these changes as a subclass.
Perhaps for applications using a different class name, otherwise the mangling would still have to act on the plain Module::Util class name. Show quoted text
> Would you mind if I link to Module::Util::Masked in the Module::Mask > documentation?
No worries. :) The two Module::Mask and Test::Without::Module which I look at are only because they're the two I've used. Dunno if there's any other require-hiding/masking which might be tied-in too. I suppose variations could hide from other similar modules like Module::Find or the underlying File::Find or various plugin schemes. -- Food jargon elucidated for the layman: "Gourmet selection" -- twice the price.