Perl中的单例实现

teo*_*jan 6 singleton perl6 raku

perl6中单例模式的正确实现是什么?

我试过这个,但我不知道如何在perl6中使用static关键字:

teo*_*jan 2

bless这是需要使用方法的少数原因之一

class Singleton {
    my Singleton $instance;
    method new {!!!}
    submethod instance {
        $instance = Singleton.bless unless $instance;
        $instance;
    }
 }
Run Code Online (Sandbox Code Playgroud)