# HG changeset patch # User cin # Date 1367183442 -14400 # Node ID 75a78cbf7dcf668040778cea4c11be389ede6ab2 # Parent d3b5a67ad2e8f34e76b8ff999c472116e004751a View refactoring: INIT blocks are deprecated diff -r d3b5a67ad2e8 -r 75a78cbf7dcf Lib/IMPL/Object/Singleton.pm --- a/Lib/IMPL/Object/Singleton.pm Mon Apr 22 03:42:53 2013 +0400 +++ b/Lib/IMPL/Object/Singleton.pm Mon Apr 29 01:10:42 2013 +0400 @@ -9,11 +9,12 @@ __PACKAGE__->static_accessor_own(_instance => undef); -my %instances; - -sub CTOR { - die IMPL::InvalidOperationException->new("Only one instance of the singleton can be created",ref $_[0]) - if $_[0]->_instance; +sub InitInstance { + my $self = shift; + die IMPL::InvalidOperationException->new("Only one instance of the singleton can be created", $self) + if $self->_instance; + + $self->_instance($self->new(@_)); } sub instance { diff -r d3b5a67ad2e8 -r 75a78cbf7dcf Lib/IMPL/Web/View/TTFactory.pm --- a/Lib/IMPL/Web/View/TTFactory.pm Mon Apr 22 03:42:53 2013 +0400 +++ b/Lib/IMPL/Web/View/TTFactory.pm Mon Apr 29 01:10:42 2013 +0400 @@ -4,7 +4,7 @@ use Template::Context(); use Carp qw(carp); -use IMPL::lang qw(:hash); +use IMPL::lang qw(:hash is); use IMPL::Exception(); use Scalar::Util qw(weaken); @@ -23,13 +23,13 @@ ], props => [ template => PROP_RW, + activation => PROP_RW, context => PROP_RW, - instances => PROP_RW, baseLocation => PROP_RW, base => PROP_RW, registry => PROP_RO, blocks => PROP_RO, - initialized => PROP_RO + _instance => PROP_RW ] }; @@ -46,10 +46,10 @@ $context ||= new Template::Context(); my $baseLocation = join( '/', splice( @{[split(/\//,$path)]}, 0, -1 ) ); + $this->activation($template->activation || 'new'); $this->template($template); $this->context($context); $this->baseLocation($baseLocation); - $this->instances(0); $this->registry($registry); if (my $baseTplName = $template->extends) { @@ -126,30 +126,9 @@ sub CreateObject { my $this = shift; - $this->InitOnDemand(); - - my $instance = $this->SUPER::CreateObject(@_); - - my $count = $this->instances; - $count++; - $this->instances($count); - - return $instance; -} - -sub InitOnDemand { - my ($this) = @_; - - unless ($this->initialized) { - $this->initialized(1); - - $this->base->InitOnDemand() - if $this->base; - - if (my $init = $this->template->blocks->{INIT}) { - $this->context->process($init); - } - } + $this->activation eq 'singleton' ? + $this->_instance || $this->_instance($this->next::method(@_)) : + $this->next::method(@_); } sub CloneContext {