Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Object singleton method

by pc88mxer (Vicar)
on Apr 21, 2008 at 22:45 UTC ( [id://682040]=note: print w/replies, xml ) Need Help??


in reply to Object singleton method

Of course it's possible! There's even a module on CPAN to do it: Class::Singleton.

However, a singleton is really more of a design pattern, so there's a lot of ways to implement it. Rolling your own isn't that hard:

package MyClass; my $instance; sub get_instance { unless ($instance) { $instance = ...; # instantiate instance here } $instance; }

Replies are listed 'Best First'.
Re^2: Object singleton method
by sh1tn (Priest) on Jun 19, 2008 at 23:25 UTC
    The example is another pointer to Class singleton method and not instance one. All I wanted is:
    s = String.new "s" def s.singleton print "ok" end # later on s.ok

Log In?
Username:
Password:

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

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

    No recent polls found