From: Shawn M Moore Date: Sun, 16 Dec 2007 19:11:16 +0000 (+0000) Subject: Optimization: it's really slow to go through new_object for every access so X-Git-Tag: 0.09_02~26 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ef266b1fc2be836aebc622df0d05eb2e9e546789;p=gitmo%2FMooseX-Singleton.git Optimization: it's really slow to go through new_object for every access so return the singleton if we see it already exists, which it will every single except the first. It's not particularly Moosey but it'll do for a first CPAN release. --- diff --git a/lib/MooseX/Singleton/Meta/Instance.pm b/lib/MooseX/Singleton/Meta/Instance.pm index e9c2522..b78953c 100644 --- a/lib/MooseX/Singleton/Meta/Instance.pm +++ b/lib/MooseX/Singleton/Meta/Instance.pm @@ -9,6 +9,13 @@ sub get_singleton_instance { my ($self, $instance) = @_; return $instance if blessed $instance; + + # optimization: it's really slow to go through new_object for every access + # so return the singleton if we see it already exists, which it will every + # single except the first. + no strict 'refs'; + return ${"$instance\::singleton"} if defined ${"$instance\::singleton"}; + return $instance->instance; }