use Module::Stubber; stub 'Foo::Bar' => { new => sub { bless {}, $_[0]; }, stringify => sub { "$_[0]"; } }; autorequire( qr/^Acme::/ => undef ); # Block access to Acme:: modul +es autorequire( 1 => sub { my $mod = shift; local @INC; unshift @INC,$special_lib; eval "require $mod"; !$@};
Also, this module can be used to hook to a CPAN or CPANPLUS load if the module has not already been installed (in the manner of Acme::Everything, but with more control).
Similarly, the modules might be installed elsewhere, such as a private LIB or PREFIX area. This could provide a way of hooking to these modules in such a way as to track whether and when any of these modules are being used, without stopping the functionality.
The first parameter to autorequire can be a regex, a code reference or a value. The regexp is matched against the module name, the code ref called passing in the module name, or the value tested; in each case for a true value. If this was true, the second parameter was called or tested, and execution continues if this is true. If the second parameter is false, the code carps with "Unable to require <module>".
Update: part of the concept in this RFC was released to CPAN as Module::Optional
--
I'm Not Just Another Perl Hacker
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: RFC: Module::Stubber
by stvn (Monsignor) on Nov 30, 2004 at 18:07 UTC | |
by rinceWind (Monsignor) on Dec 01, 2004 at 11:26 UTC | |
by simonflk (Pilgrim) on Dec 06, 2004 at 13:20 UTC | |
|
Re: RFC: Module::Stubber
by revdiablo (Prior) on Nov 30, 2004 at 18:12 UTC |