2 package MooseX::Singleton::Object;
5 extends 'Moose::Object';
7 sub instance { shift->new }
10 my ($class, @args) = @_;
12 my $existing = $class->meta->existing_singleton;
13 confess "Singleton is already initialized" if $existing;
15 return $class->SUPER::new(@args);
19 my ($class, @args) = @_;
21 my $existing = $class->meta->existing_singleton;
22 confess "Singleton is already initialized" if $existing and @args;
24 # Otherwise BUILD will be called repeatedly on the existing instance.
26 return $existing if $existing and ! @args;
28 return $class->SUPER::new(@args);
41 MooseX::Singleton::Object - base class for MooseX::Singleton
45 This just adds C<instance> as a shortcut for C<new>.