Grandfather has pointed you in the standard direction, which is to use a singleton object. However, I'm more willing to challenge your assertions that:
I need everything in the Webapp namespace to access the %Webapp::Bathroom data. And I need any module I want to be able to modify data in there as well.
That just sounds like an incomplete design* to me. There are several reason why I don't think you really want what you think you want. Some are webapp-specific and some aren't.
- In a webapp, everything is in the context of the request.
- If you're in a persistent environment (like mod_perl), then you just made changes in one of the child processes that isn't seen by the other child processes. Since which child process handles which request is essentially random, you have just created a random change in your data. Which will give you random results.
- If you're not, then any changes you make to the shared data disappears unless it's backed by some datastore.
- If you are backed by a datastore, then the only global thing should be the connection to the datastore.
- Changing something that's held globally results in what's known as "Action at a Distance". Essentially, if code in one subsystem changes to now alter one of the Bathrooms, code in every other subsystem might break. This increases the coupling between pieces of your application. Essentially, any piece of code that uses any part of the Bathrooms is coupled to every other piece of code that potentially could use the Bathrooms. If you alter your piece, you not only have to test every other piece. You sure you want that requirement?
*: If you claim it's a complete design, then it's a bad design. I went with the nicer possibility.
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.