From: Shawn M Moore Date: Sun, 16 Dec 2007 16:23:23 +0000 (+0000) Subject: Move actual singleton logic out of MooseX::Singleton::Object and into MooseX::Singlet... X-Git-Tag: 0.09_02~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3822ace201bf25804b3b760238b59df07890c634;p=gitmo%2FMooseX-Singleton.git Move actual singleton logic out of MooseX::Singleton::Object and into MooseX::Singleton::Meta::Class. --- diff --git a/lib/MooseX/Singleton/Meta/Class.pm b/lib/MooseX/Singleton/Meta/Class.pm index 447859d..51ca11c 100644 --- a/lib/MooseX/Singleton/Meta/Class.pm +++ b/lib/MooseX/Singleton/Meta/Class.pm @@ -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; diff --git a/lib/MooseX/Singleton/Object.pm b/lib/MooseX/Singleton/Object.pm index dc04e2f..08a4926 100644 --- a/lib/MooseX/Singleton/Object.pm +++ b/lib/MooseX/Singleton/Object.pm @@ -7,17 +7,6 @@ extends 'Moose::Object'; no strict 'refs'; -override new => sub { - my $class = shift; - - # create exactly one instance - if (!defined ${"$class\::singleton"}) { - ${"$class\::singleton"} = super; - } - - return ${"$class\::singleton"}; -}; - sub instance { shift->new } 1;