in reply to Re: work around for static vars and singleton constructors not inheriting properly?
in thread work around for static vars and singleton constructors not inheriting properly?

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.