I noticed the question because I'd just started some testing code for Exporter::VA, and originally thought of having a bunch of small dummy modules in one test file along with the main-line code that uses them. But I decided against tricks because I wanted the test to look just like the typical use.
But now I have an idea. How about a very simple pragmatic module that just tells perl that a module is already loaded? Then a subsequent use will just import. You don't have to worry about how to adapt a particular module for being included in-line, or have funny constructs in your code. This would be handy for testing, for "linking" some code together into one file, and for having a .pm file suply helper modules directly in the same file.
I'm thinking of something like:
tells perl that the current __PACKAGE__ is "loaded". That is, add $INC{__PACKAGE__} ||= $0.use pm_present;
tells perl that the specified Module is "loaded". That is, add $INC{Module} ||= $0.use pm_present Module;
tells perl to use the specified name for the entry in the %INC hash instead of the current source file name.use pm_present Module => filename
In the spirit of use lib, I think this will be just a couple lines long.
What do y'all think? The name is open to suggestions.
—John
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: pragmatic module idea
by chromatic (Archbishop) on Dec 16, 2002 at 20:39 UTC | |
by John M. Dlugosz (Monsignor) on Dec 16, 2002 at 21:11 UTC | |
by chromatic (Archbishop) on Dec 16, 2002 at 23:20 UTC |