comparison 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
comparison
equal deleted inserted replaced
240:abc7c26bf615 241:f48a1a9f4fa2
2 use strict; 2 use strict;
3 use JSON; 3 use JSON;
4 4
5 use IMPL::declare { 5 use IMPL::declare {
6 require => { 6 require => {
7 HttpResponse => 'IMPL::Web::HttpResponse' 7 HttpResponse => 'IMPL::Web::HttpResponse',
8 ViewResult => '-IMPL::Web::ViewResult'
8 }, 9 },
9 base => [ 10 base => [
10 'IMPL::Object' => undef, 11 'IMPL::Object' => undef,
11 'IMPL::Object::Serializable' => undef, 12 'IMPL::Object::Serializable' => undef,
12 'IMPL::Object::Autofill' => '@_' 13 'IMPL::Object::Autofill' => '@_'
19 20
20 sub Invoke { 21 sub Invoke {
21 my ($this,$action,$next) = @_; 22 my ($this,$action,$next) = @_;
22 23
23 my $result = $next ? $next->($action) : undef; 24 my $result = $next ? $next->($action) : undef;
24 $result = [$result] unless ref $result;
25 25
26 $action->response->contentType($this->contentType); 26
27 27 my $model = ( ref $result and eval { $result->isa(ViewResult) } )
28 ? $result->model
29 : $result;
30
31 $model = [$model] unless ref $model;
32
28 return HttpResponse->new({ 33 return HttpResponse->new({
29 type => $this->contentType, 34 type => $this->contentType,
30 charset => 'utf-8', 35 charset => 'utf-8',
31 body => JSON->new->utf8->pretty->encode($result) 36 body => JSON->new->utf8->pretty->encode($model)
32 }); 37 });
33 } 38 }
34 39
35 1; 40 1;
36 41