remove shbang from modules
[gitmo/MooseX-Singleton.git] / lib / MooseX / Singleton / Role / Object.pm
1 package MooseX::Singleton::Role::Object;
2 use Moose::Role;
3
4 sub instance { shift->new }
5
6 sub initialize {
7   my ($class, @args) = @_;
8
9   my $existing = $class->meta->existing_singleton;
10   confess "Singleton is already initialized" if $existing;
11
12   return $class->new(@args);
13 }
14
15 override new => sub {
16   my ($class, @args) = @_;
17
18   my $existing = $class->meta->existing_singleton;
19   confess "Singleton is already initialized" if $existing and @args;
20
21   # Otherwise BUILD will be called repeatedly on the existing instance.
22   # -- rjbs, 2008-02-03
23   return $existing if $existing and ! @args;
24
25   return super();
26 };
27
28 sub _clear_instance {
29   my ($class) = @_;
30   $class->meta->clear_singleton;
31 }
32
33 no Moose;
34
35 1;
36
37 __END__
38
39 =pod
40
41 =head1 NAME
42
43 MooseX::Singleton::Object - Object class role for MooseX::Singleton
44
45 =head1 DESCRIPTION
46
47 This just adds C<instance> as a shortcut for C<new>.
48
49 =cut
50