Documentation and little fixes. This one (0.03) is heading to CPAN
[gitmo/MooseX-Singleton.git] / lib / MooseX / Singleton / Meta / Class.pm
index 447859d..28b1437 100644 (file)
@@ -16,5 +16,35 @@ 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;
 
+__END__
+
+=pod
+
+=head1 NAME
+
+MooseX::Singleton::Meta::Class
+
+=head1 DESCRIPTION
+
+This metaclass is where the forcing of one instance occurs. The first call to
+C<construct_instance> is run normally (and then cached). Subsequent calls will
+return the cached version.
+
+=cut
+