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

Thanks for the response thcsoft but I'm not sure how Exporter is relevant to the static/class var and singleton constructor question. Could you clarify?

Personally I like using C:MM because it forces me to declare class/instance vars and I get errors on mispellings. I have to admit that I haven't done any benchmarking though...

  • Comment on Re: work around for static vars and singleton constructors not inheriting properly?

Replies are listed 'Best First'.
Re^2: work around for static vars and singleton constructors not inheriting properly?
by thcsoft (Monk) on May 27, 2005 at 04:25 UTC
    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.