Do a bit of fixing. instance and new are one and the same. More tests to ensure that...
[gitmo/MooseX-Singleton.git] / lib / MooseX / Singleton.pm
1 package MooseX::Singleton;
2 use Moose::Role;
3
4 our $VERSION = 0.02;
5
6 override new => sub {
7     my ($class) = @_;
8
9     no strict 'refs';
10
11     # create our instance if we don't already have one
12     if (!defined ${"$class\::singleton"}) {
13         ${"$class\::singleton"} = super;
14     }
15
16     return ${"$class\::singleton"};
17 };
18
19 # instance really is the same as new. any ideas for a better implementation?
20 sub instance {
21     shift->new(@_);
22 }
23
24 1;
25