Heya,

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:

use Config; use One; *One::Config = *::Config; use Two; *Two::Config = *::Config;

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.

Peace.

 

-justin simoni
skazat me


In reply to Sharing Namespaces by skazat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.