Fix RT bug #46086
[gitmo/MooseX-Singleton.git] / lib / MooseX / Singleton / Role / Meta / Class.pm
index c8d4162..beda2d1 100644 (file)
@@ -3,8 +3,6 @@ use Moose::Role;
 use MooseX::Singleton::Role::Meta::Instance;
 use MooseX::Singleton::Role::Meta::Method::Constructor;
 
-our $VERSION = '0.22';
-$VERSION = eval $VERSION;
 
 sub existing_singleton {
     my ($class) = @_;
@@ -36,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