diff Lib/IMPL/Object/Singleton.pm @ 143:d9dd3500ead3

Singleton behavior changed
author wizard
date Thu, 08 Jul 2010 23:46:49 +0400
parents 0d2337e203c0
children b56ebc31bf18
line wrap: on
line diff
--- 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;