your problem, i pretend, is maybe that Class::MethodMaker is an astonishing (and absurd, imho) effort to import java-think into perl. that's why for perl it's an overhead, even base.pm looks like. as you can see in the documentation from base.pm, the similarity to
package Baz; BEGIN { require Foo; require Bar; push @ISA, qw(Foo Bar); }
is conceeded.
the thing with perl is, that everything is an agreement. every member of a class's instance is accessible directly - however, most people consider that unattractive... so:
my $object = MyClass->new; print $object->name; print $object->{'name'};
are identical, provided in MyClass the 'name' method is defined. moreover, the second approach will always be a tick faster, as there is no need for dereferencing a method.
and if you really like your class to always have only one instance at the same time, try this:
package MyClass; use strict; use vars qw/$MUSTHAVEONLYONEINSTANCE/; $MUSTHAVEONLYONEINSTANCE = 0; ... sub new { return undef if $MUSTHAVEONLYONEINSTANCE; $MUSTHAVEONLYONEINSTANCE = 1; ... } sub DESTROY { $MUSTHAVEONLYONEINSTANCE = 0; }
unlike java, perl does'nt even try to protect you from yourself. ;)

language is a virus from outer space.

In reply to Re^2: work around for static vars and singleton constructors not inheriting properly? by thcsoft
in thread work around for static vars and singleton constructors not inheriting properly? by Anonymous Monk

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.