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 (Abbot)
on Jan 24, 2008 at 21:57 UTC ( #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
Node Status?
node history
Node Type: note [id://664149]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2019-06-19 00:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (83 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!