do not allow double initialization
[gitmo/MooseX-Singleton.git] / lib / MooseX / Singleton / Object.pm
CommitLineData
109b110b 1#!/usr/bin/env perl
2package MooseX::Singleton::Object;
3use Moose;
4use metaclass 'MooseX::Singleton::Meta::Class';
5
6extends 'Moose::Object';
7
109b110b 8sub instance { shift->new }
9
1de95613 10sub 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
109b110b 191;
20
b375b147 21__END__
22
23=pod
24
25=head1 NAME
26
27MooseX::Singleton::Object - base class for MooseX::Singleton
28
29=head1 DESCRIPTION
30
31This just adds C<instance> as a shortcut for C<new>.
32
33=cut
34