So I thought I was writing clean code, friendly to any coders that might want to use parts of it, etc... I sepparated stuff into modules, checked to make sure the namespaces did not collide as i offer them out..

Made sure to comment stuff and name my vars so that any prying eyes would know what they do.. and then.. No. Turns out, my code is third grade.

I found an unforgivable hole in what I do.
I use global variables. Yes.
Here's why.

(this is a web app)

I have Webapp.pm
then i have Webapp/Bathroom.pm
then i have Webapp/Bathroom/Toilet.pm
then i have Webapp/Bathroom/Status.pm

I'm using a globally accessible hashes of data,
%Webapp::Bathroom

which might hold something like
@{$Webapp::Bathroom{toilets}}
and then
%{$Webapp::Bathroom{joetoilet}
%{$Webapp::Bathroom{janetoilet}

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.

I seem to have been doing it this way.. I declare that Webbapp/Bathroom.pm has an our %Bathroom and that this symbol is exported.
so, other modules can access and change data in %Bathroom by pointing to %Webapp::Bathroom, without calling use Bathroom

Ok. I seem to be going insane. That's ok. Is this sounding like I should be playing with OO at this point ? maybe making a $Webapp object to store all data into ? How will this be accessible to all dependant packages ? Ouch.. Point to where I should take my corpse to properly do this.. I know I'm not supposed to use our, ever. I don't want to write useless code. Or worse, troublemaking code.

What is a propper way to make a chunk of data accessible to all my packages for retrieval and modification ?


In reply to what is a propper way to make a chunk of data accessible to all my packages for retrieval and modification ? by leocharre

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.