|Just another Perl shrine|
Sharing Namespacesby skazat (Chaplain)
|on Jan 27, 2006 at 07:15 UTC||Need Help??|
skazat has asked for the wisdom of the Perl Monks concerning the following question:
I've been noodling around my brain on how to do this, but I haven't *quite* gotten a hold of exactly how - here's the puzzle:
How do you share a module's namespace with another module?
For example, say I have a module called, "Config.pm" that holds configuration information using just simple variables, arrays, hashes, etc. This script also has One.pm and Two.pm, which require the variables, etc from Config.pm to be available. Do you do something like:
I don't think the above code works, but I know this problem's solution may deal with passing typeglobs around.
I basically have a program that's getting very large and each module of the program (20+) needs this darn Config module loaded. I had an idea that to optimize the program I could, instead of use/requiring this Config.pm module for each other module of the program, just pass the namespace (and thus, the configuration vars) it holds.
The Config.pm module currently opens a file and reads variables saved there to put in its own namespace - so if I do this opitimization, I'd be basically saving (upwards of) 19 file opens - seems worth it, but I just don't understand the mechanics of *how* to pass entire namespaces between modules.
To add a zinger, I still want it to be optional to pass the namespace to these modules (One.pm, Two.pm), since I don't want to break any code that's already out there (quite a bit).
I know this is quite a large problem to ask, but any help in getting direction for this lost monk is appreciated.