X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Singleton.git;a=blobdiff_plain;f=lib%2FMooseX%2FSingleton%2FRole%2FMeta%2FClass.pm;h=beda2d1f11ff173dda95804931e1c8143c7d7945;hp=fc8048b39c2655d9ee884b51d4361035043a3eb6;hb=0f22810a8a14902c7724ea80a9951829e42ac8eb;hpb=4c25692312665e52f72b16a0a3086046590cf46a diff --git a/lib/MooseX/Singleton/Role/Meta/Class.pm b/lib/MooseX/Singleton/Role/Meta/Class.pm index fc8048b..beda2d1 100644 --- a/lib/MooseX/Singleton/Role/Meta/Class.pm +++ b/lib/MooseX/Singleton/Role/Meta/Class.pm @@ -3,6 +3,7 @@ use Moose::Role; use MooseX::Singleton::Role::Meta::Instance; use MooseX::Singleton::Role::Meta::Method::Constructor; + sub existing_singleton { my ($class) = @_; my $pkg = $class->name; @@ -33,21 +34,41 @@ override _construct_instance => sub { my $pkg = $class->name; no strict 'refs'; + no warnings 'once'; return ${"$pkg\::singleton"} = super; }; +if ( $Moose::VERSION >= 1.9900 ) { + override _inline_params => sub { + my $self = shift; + + return + 'my $existing = do {', + 'no strict "refs";', + 'no warnings "once";', + '\${"$class\::singleton"};', + '};', + 'return ${$existing} if ${$existing};', + super(); + }; + + override _inline_extra_init => sub { + my $self = shift; + + return '${$existing} = $instance;'; + }; +} + no Moose::Role; 1; +# ABSTRACT: Metaclass role for MooseX::Singleton + __END__ =pod -=head1 NAME - -MooseX::Singleton::Role::Meta::Class - Metaclass role for MooseX::Singleton - =head1 DESCRIPTION This metaclass role makes sure that there is only ever one instance of an