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