Mercurial > pub > Impl
comparison Lib/IMPL/Web/Handler/View.pm @ 359:833e663796c4
TTView: added view variable to pass rendering context between controls
TTView: display function renamed to display_for
WebResource: resources now marked with roles for searching a desired resource by a role in the resource chain
author | sergey |
---|---|
date | Mon, 25 Nov 2013 02:19:31 +0400 |
parents | 9330835535b9 |
children | d5c8b955bf8d |
comparison
equal
deleted
inserted
replaced
358:248f95c1762a | 359:833e663796c4 |
---|---|
8 use IMPL::declare { | 8 use IMPL::declare { |
9 require => { | 9 require => { |
10 Factory => 'IMPL::Web::View::ObjectFactory', | 10 Factory => 'IMPL::Web::View::ObjectFactory', |
11 HttpResponse => 'IMPL::Web::HttpResponse', | 11 HttpResponse => 'IMPL::Web::HttpResponse', |
12 Loader => 'IMPL::Code::Loader', | 12 Loader => 'IMPL::Code::Loader', |
13 ViewResult => '-IMPL::Web::ViewResult' | 13 ViewResult => '-IMPL::Web::ViewResult', |
14 Security => 'IMPL::Security' | |
14 }, | 15 }, |
15 base => [ | 16 base => [ |
16 'IMPL::Object' => undef, | 17 'IMPL::Object' => undef, |
17 'IMPL::Object::Autofill' => '@_', | 18 'IMPL::Object::Autofill' => '@_', |
18 'IMPL::Object::Serializable' => undef | 19 'IMPL::Object::Serializable' => undef |
38 sub Invoke { | 39 sub Invoke { |
39 my ( $this, $action, $next ) = @_; | 40 my ( $this, $action, $next ) = @_; |
40 | 41 |
41 my $result = $next ? $next->($action) : undef; | 42 my $result = $next ? $next->($action) : undef; |
42 | 43 |
43 my ($model,$view,$template); | 44 my ($model,$template); |
44 if( ref $result and eval { $result->isa(ViewResult) } ) { | 45 if( ref $result and eval { $result->isa(ViewResult) } ) { |
45 $model = $result->model; | 46 $model = $result->model; |
46 $view = $result; | |
47 $template = $result->template; | 47 $template = $result->template; |
48 } else { | 48 } else { |
49 $model = $result; | 49 $model = $result; |
50 $view = ViewResult->new(model => $model); | 50 $result = ViewResult->new(model => $model); |
51 } | 51 } |
52 | 52 |
53 my $vars = { | 53 my $vars = { |
54 view => $view, | 54 result => $result, |
55 request => sub { $action }, | 55 request => sub { $action }, |
56 app => $action->application, | 56 app => $action->application, |
57 context => $action->context, | |
58 env => _cached($action->context->{environment}), | |
59 location => $action->context->{resourceLocation}, | 57 location => $action->context->{resourceLocation}, |
60 layout => $this->layout | 58 resource => $action->context->{resource}, |
59 layout => $this->layout, | |
60 document => {}, | |
61 session => sub { Security->context }, | |
62 user => sub { Security->principal } | |
61 }; | 63 }; |
62 | 64 |
63 my %responseParams = ( | 65 my %responseParams = ( |
64 type => $this->contentType, | 66 type => $this->contentType, |
65 charset => $this->contentCharset, | 67 charset => $this->contentCharset, |
68 $template || $this->SelectView( $action, ref $model ), | 70 $template || $this->SelectView( $action, ref $model ), |
69 $vars | 71 $vars |
70 ) | 72 ) |
71 ); | 73 ); |
72 | 74 |
73 $responseParams{status} = $view->status if $view->status; | 75 $responseParams{status} = $result->status if $result->status; |
74 $responseParams{cookies} = $view->cookies if ref $view->cookies eq 'HASH'; | 76 $responseParams{cookies} = $result->cookies if ref $result->cookies eq 'HASH'; |
75 $responseParams{headers} = $view->headers if ref $view->headers eq 'HASH'; | 77 $responseParams{headers} = $result->headers if ref $result->headers eq 'HASH'; |
76 | 78 |
77 return HttpResponse->new( | 79 return HttpResponse->new( |
78 %responseParams | 80 %responseParams |
79 ); | 81 ); |
80 } | |
81 | |
82 sub _cached { | |
83 my $arg = shift; | |
84 | |
85 return $arg unless ref $arg eq 'CODE'; | |
86 | |
87 return sub { | |
88 ref $arg eq 'CODE' ? $arg = &$arg() : $arg; | |
89 } | |
90 } | 82 } |
91 | 83 |
92 sub SelectView { | 84 sub SelectView { |
93 my ($this,$action) = @_; | 85 my ($this,$action) = @_; |
94 | 86 |