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