Re-implementation. This uses a bit of Moose meta magic to get real singletons.
[gitmo/MooseX-Singleton.git] / lib / MooseX / Singleton / Object.pm
CommitLineData
109b110b 1#!/usr/bin/env perl
2package MooseX::Singleton::Object;
3use Moose;
4use metaclass 'MooseX::Singleton::Meta::Class';
5
6extends 'Moose::Object';
7
8no strict 'refs';
9
10override new => sub {
11 my $class = shift;
12
13 # create exactly one instance
14 if (!defined ${"$class\::singleton"}) {
15 ${"$class\::singleton"} = super;
16 }
17
18 return ${"$class\::singleton"};
19};
20
21sub instance { shift->new }
22
231;
24