Mercurial > pub > Impl
comparison 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 |
comparison
equal
deleted
inserted
replaced
240:abc7c26bf615 | 241:f48a1a9f4fa2 |
---|---|
4 use List::Util qw(first); | 4 use List::Util qw(first); |
5 use IMPL::Const qw(:prop); | 5 use IMPL::Const qw(:prop); |
6 use IMPL::declare { | 6 use IMPL::declare { |
7 require => { | 7 require => { |
8 Factory => 'IMPL::Web::View::ObjectFactory', | 8 Factory => 'IMPL::Web::View::ObjectFactory', |
9 HttpResponse => 'IMPL::Web::HttpResponse' | 9 HttpResponse => 'IMPL::Web::HttpResponse', |
10 Loader => 'IMPL::Code::Loader', | |
11 ViewResult => '-IMPL::Web::ViewResult' | |
10 }, | 12 }, |
11 base => [ | 13 base => [ |
12 'IMPL::Object' => undef, | 14 'IMPL::Object' => undef, |
13 'IMPL::Object::Autofill' => '@_', | 15 'IMPL::Object::Autofill' => '@_', |
14 'IMPL::Object::Serializable' => undef | 16 'IMPL::Object::Serializable' => undef |
34 | 36 |
35 sub Invoke { | 37 sub Invoke { |
36 my ( $this, $action, $next ) = @_; | 38 my ( $this, $action, $next ) = @_; |
37 | 39 |
38 my $result = $next ? $next->($action) : undef; | 40 my $result = $next ? $next->($action) : undef; |
41 | |
42 my ($model,$view); | |
43 if( ref $result and eval { $result->isa(ViewResult) } ) { | |
44 $model = $result->model; | |
45 $view = $result; | |
46 } else { | |
47 $model = $result; | |
48 $view = ViewResult->new(model => $model); | |
49 } | |
50 | |
39 | 51 |
40 my $vars = { | 52 my $vars = { |
41 model => $result, | 53 view => $view, |
54 model => $model, | |
42 action => $action, | 55 action => $action, |
43 app => $action->application, | 56 app => $action->application, |
44 ImportClass => sub { | 57 ImportClass => sub { |
45 my $class = shift; | 58 my $class = shift; |
46 | 59 |
47 my $module = $class; | 60 $class = Loader->safe->Require($class); |
48 | 61 |
49 $module =~ s/::/\//g; | |
50 $module .= ".pm"; | |
51 | |
52 require $module; | |
53 return Factory->new($class); | 62 return Factory->new($class); |
54 } | 63 } |
55 }; | 64 }; |
56 | 65 |
57 my $doc = | 66 my $doc = |
59 $vars ); | 68 $vars ); |
60 | 69 |
61 return HttpResponse->new( | 70 return HttpResponse->new( |
62 type => $this->contentType, | 71 type => $this->contentType, |
63 charset => $this->contentCharset, | 72 charset => $this->contentCharset, |
64 body => $doc->Render($vars) | 73 body => $doc->Render() |
65 ); | 74 ); |
66 } | 75 } |
67 | 76 |
68 sub SelectView { | 77 sub SelectView { |
69 my ( $this, $action, $class ) = @_; | 78 my ( $this, $action, $class ) = @_; |