_clear_instance and tests
[gitmo/MooseX-Singleton.git] / lib / MooseX / Singleton / Object.pm
index 8ad2a4d..312e472 100644 (file)
@@ -1,7 +1,6 @@
 #!/usr/bin/env perl
 package MooseX::Singleton::Object;
 use Moose;
-use metaclass 'MooseX::Singleton::Meta::Class';
 
 extends 'Moose::Object';
 
@@ -22,9 +21,20 @@ sub new {
   my $existing = $class->meta->existing_singleton;
   confess "Singleton is already initialized" if $existing and @args;
 
+  # Otherwise BUILD will be called repeatedly on the existing instance.
+  # -- rjbs, 2008-02-03
+  return $existing if $existing and ! @args;
+
   return $class->SUPER::new(@args);
 }
 
+sub _clear_instance {
+  my ($class) = @_;
+  $class->meta->clear_singleton;
+}
+
+no Moose;
+
 1;
 
 __END__