comparison Lib/IMPL/Object/Singleton.pm @ 312:75a78cbf7dcf

View refactoring: INIT blocks are deprecated
author cin
date Mon, 29 Apr 2013 01:10:42 +0400
parents 0f59b2de72af
children
comparison
equal deleted inserted replaced
311:d3b5a67ad2e8 312:75a78cbf7dcf
7 IMPL::Class::Meta 7 IMPL::Class::Meta
8 ); 8 );
9 9
10 __PACKAGE__->static_accessor_own(_instance => undef); 10 __PACKAGE__->static_accessor_own(_instance => undef);
11 11
12 my %instances; 12 sub InitInstance {
13 13 my $self = shift;
14 sub CTOR { 14 die IMPL::InvalidOperationException->new("Only one instance of the singleton can be created", $self)
15 die IMPL::InvalidOperationException->new("Only one instance of the singleton can be created",ref $_[0]) 15 if $self->_instance;
16 if $_[0]->_instance; 16
17 $self->_instance($self->new(@_));
17 } 18 }
18 19
19 sub instance { 20 sub instance {
20 my $this = shift; 21 my $this = shift;
21 return $this->_instance || $this->_instance($this->Activate()); 22 return $this->_instance || $this->_instance($this->Activate());