Question

What is the correct implementation of singleton pattern in perl6?

I've tried this but I dont' know how to use static keyword in perl6:

Was it helpful?

Solution

It one of the few reasons that require using bless method

class Singleton {
    my Singleton $instance;
    method new {!!!}
    submethod instance {
        $instance = Singleton.bless unless $instance;
        $instance;
    }
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top