Mercurial > pub > Impl
diff Lib/IMPL/Web/Handler/JSONView.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 | 3cebcf6fdb9b |
children | 32aceba4ee6d |
line wrap: on
line diff
--- a/Lib/IMPL/Web/Handler/JSONView.pm Wed Oct 17 17:41:29 2012 +0400 +++ b/Lib/IMPL/Web/Handler/JSONView.pm Thu Oct 18 04:49:55 2012 +0400 @@ -4,7 +4,8 @@ use IMPL::declare { require => { - HttpResponse => 'IMPL::Web::HttpResponse' + HttpResponse => 'IMPL::Web::HttpResponse', + ViewResult => '-IMPL::Web::ViewResult' }, base => [ 'IMPL::Object' => undef, @@ -21,14 +22,18 @@ my ($this,$action,$next) = @_; my $result = $next ? $next->($action) : undef; - $result = [$result] unless ref $result; + - $action->response->contentType($this->contentType); - + my $model = ( ref $result and eval { $result->isa(ViewResult) } ) + ? $result->model + : $result; + + $model = [$model] unless ref $model; + return HttpResponse->new({ type => $this->contentType, charset => 'utf-8', - body => JSON->new->utf8->pretty->encode($result) + body => JSON->new->utf8->pretty->encode($model) }); }