diff Lib/IMPL/Web/Handler/TTView.pm @ 241:f48a1a9f4fa2

+Added ViewResult to allow implementation of the view environment. *TTDocuments now storing creation parameters *TTControls automatically propagating layout and title meta to their attributes +Added UnauthorizaedException web exception *minor fixes
author sergey
date Thu, 18 Oct 2012 04:49:55 +0400
parents abc7c26bf615
children cd2b1f121029
line wrap: on
line diff
--- a/Lib/IMPL/Web/Handler/TTView.pm	Wed Oct 17 17:41:29 2012 +0400
+++ b/Lib/IMPL/Web/Handler/TTView.pm	Thu Oct 18 04:49:55 2012 +0400
@@ -6,7 +6,9 @@
 use IMPL::declare {
     require => {
         Factory      => 'IMPL::Web::View::ObjectFactory',
-        HttpResponse => 'IMPL::Web::HttpResponse'
+        HttpResponse => 'IMPL::Web::HttpResponse',
+        Loader       => 'IMPL::Code::Loader',
+        ViewResult   => '-IMPL::Web::ViewResult'
       },
       base => [
         'IMPL::Object'               => undef,
@@ -36,20 +38,27 @@
     my ( $this, $action, $next ) = @_;
 
     my $result = $next ? $next->($action) : undef;
+    
+    my ($model,$view);
+    if( ref $result and eval { $result->isa(ViewResult) } ) {
+        $model = $result->model;
+        $view = $result;      
+    } else {
+        $model = $result;
+        $view = ViewResult->new(model => $model);
+    }
+    
 
     my $vars = {
-        model       => $result,
+        view        => $view,
+        model       => $model,
         action      => $action,
         app         => $action->application,
         ImportClass => sub {
             my $class = shift;
 
-            my $module = $class;
-
-            $module =~ s/::/\//g;
-            $module .= ".pm";
-
-            require $module;
+            $class = Loader->safe->Require($class);
+            
             return Factory->new($class);
         }
     };
@@ -61,7 +70,7 @@
     return HttpResponse->new(
         type => $this->contentType,
         charset => $this->contentCharset,
-        body => $doc->Render($vars)
+        body => $doc->Render()
     );
 }