2 package MooseX::Singleton::Object;
4 use metaclass 'MooseX::Singleton::Meta::Class';
6 extends 'Moose::Object';
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->SUPER::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;
29 return $class->SUPER::new(@args);
42 MooseX::Singleton::Object - base class for MooseX::Singleton
46 This just adds C<instance> as a shortcut for C<new>.