Class::Singleton and its relatives really don't do that much for you. Look under the hood and you won't find that much code. The concept of a singleton is very simple and you can just implement the 5 lines of code in your module. You can see my article on Singletons in The Perl Review 0.1.

The Cult of Design Patterns seems to think that you should make the end programmer realize he is using a singleton, and instead of new() use something like get_instance(). I think that's the wrong way to go: in most cases the end programmer shouldn't have to think about that as long as everything works.

That doesn't matter much in your case since the magic is hidden in the Tie interface. Before you start doing things in TIEHASH, however, you need to check if you already have the instance, and if you do, simply return it. Don't make a new object then check for an old one.

--
brian d foy <brian@stonehenge.com>

In reply to Re: Multiple Inheritance - Howto marry tie::refhash::nestable with class::singleton by brian_d_foy
in thread Multiple Inheritance - Howto marry tie::refhash::nestable with class::singleton by hoppfrosch

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.