X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FSingleton%2FObject.pm;h=312e472a415d01bd7eec23fddd1670a9cec9b03e;hb=03e1b8df86e9ad4dd27d689d506324942bd20652;hp=8ad2a4dd7fe31eb1e3d807e1f049fd9afcdc78c2;hpb=d928ce3a26634463da667f6bdba903e94b31ebac;p=gitmo%2FMooseX-Singleton.git diff --git a/lib/MooseX/Singleton/Object.pm b/lib/MooseX/Singleton/Object.pm index 8ad2a4d..312e472 100644 --- a/lib/MooseX/Singleton/Object.pm +++ b/lib/MooseX/Singleton/Object.pm @@ -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__