|Keep It Simple, Stupid|
RFC: Module::Stubberby rinceWind (Monsignor)
|on Nov 30, 2004 at 17:06 UTC||Need Help??|
This is currently just pod for an idea I've had. Do you think it would be a useful module?
NAMEModule::Stubber - Provide hooks and handles to modules not in @INC
DESCRIPTIONThere are several scenarios when this module could be useful. I have a case of using a module which pulls in a whole host of dependencies, some of which are missing on some platforms I am targetting. By providing surrogate code, at the expense of the full module functionality, it is possible to eliminate the chain dependency and allow deployment onto a wider range of platforms.
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.
stubThe purpose of stub is to replace subs and method calls in a module that has not been required, with user supplied code. If the module has been successfully required, the genuine subs are left intact. Similarly if a successful require happens after the call to stub, the stub reference is overwritten.
autorequireThis is similar in concept to AUTOLOAD, but works for module names. When a require or use happens for a module outside @INC, autorequire is called with a parameter of the module name and any import list specified.
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