# HG changeset patch # User wizard # Date 1278618409 -14400 # Node ID d9dd3500ead3eea53850f94839c991f4b69fdea9 # Parent 4c9849f0f879f5434d70236d00dfe661a494c8ce Singleton behavior changed diff -r 4c9849f0f879 -r d9dd3500ead3 Lib/IMPL/Object/Singleton.pm --- a/Lib/IMPL/Object/Singleton.pm Wed Jul 07 17:30:40 2010 +0400 +++ b/Lib/IMPL/Object/Singleton.pm Thu Jul 08 23:46:49 2010 +0400 @@ -4,10 +4,15 @@ my %instances; +sub CTOR { + die new IMPL::InvalidOperationException("Only one instance of the singleton can be created",ref $_[0], $instances{ref $_[0]}) if $instances{ref $_[0]}; + $instances{ref $_[0]} = $_[0]; +} + sub instance { my $self = shift; - $instances{$self} || ($instances{$self} = $self->new(@_)); + $instances{$_[0]}; } 1;