Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi Monks!

I often run into the situation where I need access to a single object from many other objects. For example in my current project I have a config object, which parses an XML configuration file and several modules need to access this data. I want to avoid parsing the XML file over and over again, so I just want to have a single instance of this Config object.

I'm using Moose and know that I could use MooseX::Singleton to create a singleton config object, but also have heard several warnings against using singletons. I was in the same situation before, where I made my Log module a singleton, but then wanted to have different logfiles for different modules and ran into issues with just having a singleton object.

So this is more a general design question: How would you design access to a module that is required by multiple modules? I want to avoid passing that module back and forth when instantiating the calling objects as that would also quickly grow cumbersome

Thanks!


In reply to Access to single object from multiple other objects by elTriberium

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [erix]: (you're welcome :P)
    [james28909]: you know, i had a thought a few mnths back. what if this universe were just a puzzle, waiting for life to figure it out!
    [james28909]: what if one day we are able to grab the curtain that is "spacetime" and pull it back to reveal <insert imagination here> pulling at levers and ropes xD
    [holli]: like dorothy?
    [james28909]: see ya later holli
    [james28909]: yeah like wizard of oz lol. its just a joke though
    [james28909]: i cannot understand how someone cant see that a cloud of gas that evolves into a solar system or galaxies. it just makes sense to me. everythign that has happened, had to have happened for anything on this planet to be.
    [james28909]: /gas/gas and debris/
    [james28909]: another thing, i used to be atheist. life experiences, personal evidence. and my own perception is the reason why i believe the things i do.

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (13)
    As of 2017-12-15 14:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What programming language do you hate the most?




















      Results (433 votes). Check out past polls.

      Notices?