diff Lib/IMPL/Web/View/TTFactory.pm @ 312:75a78cbf7dcf

View refactoring: INIT blocks are deprecated
author cin
date Mon, 29 Apr 2013 01:10:42 +0400
parents 5e4e7c8fbca1
children 86336d451b82
line wrap: on
line diff
--- 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 {