in reply to Re^4: Making an Existing Class a Singleton
in thread Making an Existing Class a Singleton
Suppose you already have a Car class...
... and so you want to create a singleton for it:package Car; our @ISA = qw(Vehicle); # nothing related to Class::SingletonProxy goes here! sub wheels { 4 }
and then you can access the singleton from your scripts as...package MyCar; use base 'Class::SingletonProxy'; sub SINGLETON { Car->new('Ferrary', 'F40', 'red') }
Notice that the Car class remains untouched!MyCar->go_supermarket(speed => 200);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Making an Existing Class a Singleton
by exussum0 (Vicar) on Jan 24, 2008 at 22:45 UTC |