Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^5: Making an Existing Class a Singleton

by salva (Canon)
on Jan 24, 2008 at 21:57 UTC ( [id://664149]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://664149]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-19 19:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found