do not allow double initialization
[gitmo/MooseX-Singleton.git] / lib / MooseX / Singleton / Object.pm
1 #!/usr/bin/env perl
2 package MooseX::Singleton::Object;
3 use Moose;
4 use metaclass 'MooseX::Singleton::Meta::Class';
5
6 extends 'Moose::Object';
7
8 sub instance { shift->new }
9
10 sub new {
11   my ($class, @args) = @_;
12
13   my $existing = $class->meta->existing_singleton;
14   confess "Singleton is already initialized" if $existing and @args;
15
16   return $class->SUPER::new(@args);
17 }
18
19 1;
20
21 __END__
22
23 =pod
24
25 =head1 NAME
26
27 MooseX::Singleton::Object - base class for MooseX::Singleton
28
29 =head1 DESCRIPTION
30
31 This just adds C<instance> as a shortcut for C<new>.
32
33 =cut
34