Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Problems importing constants in multiple namespacesby Weevil (Novice) |
on Aug 19, 2004 at 18:13 UTC ( [id://384405]=perlquestion: print w/replies, xml ) | Need Help?? |
Weevil has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks, my problem is as follows. I have a module (let's call it Module), which has a few sub-modules (let us call them Module::Monkey and Module::Ape). Module exports some constants through use constant using Exporter. The code looks like this: If I use Module; in main, the constants are imported just fine. However, if I use Module; in Module/Ape.pm or Module/Monkey.pm, the constants are not imported. I suspect it's because I did use Module::Monkey; and use Module::Ape; in Module.pm, and this is processed before the code to export the constants ever gets done. I tried putting the exporting code inside a BEGIN block, but that did not fix the problem, and surely if I put use Module; in Module/Monkey.pm, the constants should be re-imported regardless of whether Module.pm has already been loaded. Currently, my only solution that works is to define the constants in a seperate package file and use that in all my modules that need the constants (kind of like a .h file in C), but that seems a messy way of doing things. Is there an accepted way of defining constants that work across all my sub-packages? Am I being silly by doing use Module::Monkey; and so on in Module.pm and then doing use Module; in Module/Monkey.pm to import Module's constants? Man, I hope I explained that right, it's confusing the heck out of me. I hope you can guide me.
Back to
Seekers of Perl Wisdom
|
|