changeset 298:78f767765706

TT view refactoring
author cin
date Tue, 19 Mar 2013 02:02:37 +0400
parents 52aae1b85084
children bd79145657e5
files Lib/IMPL/Web/View/TTDocument.pm Lib/IMPL/Web/View/TTFactory.pm
diffstat 2 files changed, 12 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/Web/View/TTDocument.pm	Mon Mar 11 01:22:24 2013 +0400
+++ b/Lib/IMPL/Web/View/TTDocument.pm	Tue Mar 19 02:02:37 2013 +0400
@@ -67,17 +67,12 @@
             if ( my $template = $self->loader->template($path) ) {
                
                 $factory = new IMPL::Web::View::TTFactory(
-                    $template->class || TTControl,
                     $template,
                     $documentContext,
                     join( '/', splice( @{[split(/\//,$path)]}, 0, -1 ) ),
                     $require
                 );
                 
-                if ($template->class) {
-                    Loader->safe->Require($template->class);
-                }
-                
                 $controls{$control} = $factory;
                             
                 return $factory;
--- a/Lib/IMPL/Web/View/TTFactory.pm	Mon Mar 11 01:22:24 2013 +0400
+++ b/Lib/IMPL/Web/View/TTFactory.pm	Tue Mar 19 02:02:37 2013 +0400
@@ -10,8 +10,13 @@
 
 use IMPL::Const qw(:prop);
 use IMPL::declare {
+    require => {
+        Loader => 'IMPL::Code::Loader'
+    },
     base => [
-        'IMPL::Object::Factory' => '@_'
+        'IMPL::Object::Factory' => sub {
+            shift->class || 'IMPL::Web::View::TTControl'
+        }
     ],
     props => [
         template => PROP_RW,
@@ -23,10 +28,13 @@
 };
 
 sub CTOR {
-    my ($this,$factory,$template,$context,$base,$require) = @_;
+    my ($this,$template,$context,$base,$require) = @_;
     
     die IMPL::ArgumentException("A template is required") unless $template;
     
+    Loader->safe->Require($this->factory)
+        if $this->factory and not ref $this->factory;
+    
     $context ||= new Template::Context();
     
     $this->template($template);
@@ -36,12 +44,6 @@
     $this->require($require);
 }
 
-our %CTOR = (
-    'IMPL::Object::Factory' => sub {
-        $_[0]
-    }
-);
-
 sub MergeParameters {
     my ($this,$name,$refProps) = @_;
     
@@ -50,6 +52,8 @@
         $name = (ref $refProps eq 'HASH' and ($refProps->{name} || $refProps->{id})) || '*anonymous*';
     }
     
+    $refProps->{factory} = $this;
+    
     my $base = $this->base;
     
     $this->context->localise();