Move actual singleton logic out of MooseX::Singleton::Object and into MooseX::Singlet...
[gitmo/MooseX-Singleton.git] / lib / MooseX / Singleton / Meta / Class.pm
index 447859d..51ca11c 100644 (file)
@@ -16,5 +16,19 @@ sub initialize {
     );
 };
 
+override construct_instance => sub {
+    my ($class) = @_;
+    my $pkg = $class->name;
+
+    no strict 'refs';
+
+    # create exactly one instance
+    if (!defined ${"$pkg\::singleton"}) {
+        ${"$pkg\::singleton"} = super;
+    }
+
+    return ${"$pkg\::singleton"};
+};
+
 1;