Commit | Line | Data |
---|---|---|
443f4253 | 1 | package MooseX::Singleton; |
2 | ||
3 | use Moose::Role; | |
4 | ||
5 | our $VERSION = 0.01; | |
6 | ||
7 | override new => sub { | |
8 | my ($class) = @_; | |
9 | ||
10 | no strict qw/refs/; | |
11 | ||
12 | my $instance = super; | |
13 | ||
14 | ${"$class\::singleton"} = $instance; | |
15 | ||
16 | return $instance; | |
17 | }; | |
18 | ||
19 | sub instance { | |
20 | my ($class) = @_; | |
21 | ||
22 | no strict qw/refs/; | |
23 | ||
24 | return ${"$class\::singleton"}; | |
25 | } | |
26 | ||
27 | 1; | |
28 |