diff Lib/IMPL/Web/View/TTDocument.pm @ 289:85572f512abc

*TTView refactoring
author cin
date Wed, 20 Feb 2013 02:25:30 +0400
parents 3a9cfea098dd
children 7b0dad6117d5
line wrap: on
line diff
--- a/Lib/IMPL/Web/View/TTDocument.pm	Tue Feb 19 19:58:27 2013 +0400
+++ b/Lib/IMPL/Web/View/TTDocument.pm	Wed Feb 20 02:25:30 2013 +0400
@@ -23,7 +23,6 @@
     props => [
         layout => PROP_RW,
         loader => PROP_RW,
-        controls => PROP_RO,
     ]
 };
 
@@ -41,59 +40,14 @@
     $this->InitInstance();
 }
 
-sub templateVars {
-    my $this = shift;
-    my $name = shift;
-    if (@_) {
-        return $this->context->stash->set($name, shift);        
-    } else {
-        return $this->context->stash->get($name);
-    }
-}
-
-sub RequireControl {
-    my ($this, $control, $ctx) = @_;
-    
-    $ctx ||= $this->context;
-    
-    if (my $factory = $this->controls->{$control}) {
-        return $factory;
-    } else {
-        my $path = $control;
-        
-        if ( my $template = $this->loader->template($path) ) {
-           
-            $factory = new IMPL::Web::View::TTFactory(
-                $template->class || TTControl,
-                $template,
-                $ctx,
-                join( '/', splice( @{[split(/\//,$path)]}, 0, -1 ) )
-            );
-            
-            if ($template->class) {
-                Loader->safe->Require($template->class);
-            }
-            
-            $this->controls->{$control} = $factory;
-                        
-            return $factory;
-
-        } else {
-            die new IMPL::KeyNotFoundException($control);
-        }
-    }
-}
-
 sub Render {
     my ($this,$args) = @_;
 
     $args ||= {};
 
-    $this->context->localise();
-    
-    my $documentContext;
     my %controls;
     my $require;
+    my $documentContext;
     $require = sub {
         my $control = shift;
         if (my $factory = $controls{$control}) {
@@ -125,9 +79,13 @@
         }
     };
     
+    $this->context->localise();
+    $documentContext = _clone_context( $this->context );
+    my $self = $this;
+    weaken($self);
     $this->context->stash->set(require => $require);
-    $this->context->stash->set(document => $this);
-    $documentContext = Template::Context->new( { %{$this->context} } );
+    #$this->context->stash->set(document => sub { $self });
+    
     
     my $text = eval {
     
@@ -158,8 +116,12 @@
 	        return $this->next::method($args);
 	    }
     };
+
+    undef $require;
+    undef $documentContext;    
+    undef %controls;
+    $this->context->delocalise();
     
-    $this->context->delocalise();
     
     my $e = $@;
     if ($e) {
@@ -171,6 +133,13 @@
     
 }
 
+sub _clone_context {
+    my $args = { %{shift || {}} };
+    delete $args->{CONFIG};
+    
+    return Template::Context->new($args);
+}
+
 1;
 
 __END__