in reply to Re^4: Making an Existing Class a Singleton
in thread Making an Existing Class a Singleton

oh, I see, Class::SingletonProxy doesn't work that way, you don't have to use it as the base for your classes.

Suppose you already have a Car class...

package Car; our @ISA = qw(Vehicle); # nothing related to Class::SingletonProxy goes here! sub wheels { 4 }
... and so you want to create a singleton for it:
package MyCar; use base 'Class::SingletonProxy'; sub SINGLETON { Car->new('Ferrary', 'F40', 'red') }
and then you can access the singleton from your scripts as...
MyCar->go_supermarket(speed => 200);
Notice that the Car class remains untouched!

Replies are listed 'Best First'.
Re^6: Making an Existing Class a Singleton
by exussum0 (Vicar) on Jan 24, 2008 at 22:45 UTC
    Something feels really odd about this, in regards to serialization and any type of inspection one may do. I only speak to working with someone's really wonky code to determine the object's class and tripping up on someone's proxy.