1 package MooseX::Singleton::Role::Object;
4 sub instance { shift->new }
7 my ($class, @args) = @_;
9 my $existing = $class->meta->existing_singleton;
10 confess "Singleton is already initialized" if $existing;
12 return $class->new(@args);
16 my ($class, @args) = @_;
18 my $existing = $class->meta->existing_singleton;
19 confess "Singleton is already initialized" if $existing and @args;
21 # Otherwise BUILD will be called repeatedly on the existing instance.
23 return $existing if $existing and ! @args;
30 $class->meta->clear_singleton;
43 MooseX::Singleton::Role::Object - Object class role for MooseX::Singleton
47 This just adds C<instance> as a shortcut for C<new>.