1 package MooseX::Singleton::Role::Object;
6 $VERSION = eval $VERSION;
8 sub instance { shift->new }
11 my ( $class, @args ) = @_;
13 my $existing = $class->meta->existing_singleton;
14 confess "Singleton is already initialized" if $existing;
16 return $class->new(@args);
20 my ( $class, @args ) = @_;
22 my $existing = $class->meta->existing_singleton;
23 confess "Singleton is already initialized" if $existing and @args;
25 # Otherwise BUILD will be called repeatedly on the existing instance.
27 return $existing if $existing and !@args;
34 $class->meta->clear_singleton;
47 MooseX::Singleton::Role::Object - Object class role for MooseX::Singleton
51 This just adds C<instance> as a shortcut for C<new>.