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?
is conceeded.package Baz; BEGIN { require Foo; require Bar; push @ISA, qw(Foo Bar); }
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.my $object = MyClass->new; print $object->name; print $object->{'name'};
unlike java, perl does'nt even try to protect you from yourself. ;)package MyClass; use strict; use vars qw/$MUSTHAVEONLYONEINSTANCE/; $MUSTHAVEONLYONEINSTANCE = 0; ... sub new { return undef if $MUSTHAVEONLYONEINSTANCE; $MUSTHAVEONLYONEINSTANCE = 1; ... } sub DESTROY { $MUSTHAVEONLYONEINSTANCE = 0; }
|
---|