annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
1 package IMPL::Web::Handler::JSONView;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
2 use strict;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
3 use JSON;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
4
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
5 use IMPL::declare {
233
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 206
diff changeset
6 require => {
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 233
diff changeset
7 HttpResponse => 'IMPL::Web::HttpResponse',
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 233
diff changeset
8 ViewResult => '-IMPL::Web::ViewResult'
233
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 206
diff changeset
9 },
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 206
diff changeset
10 base => [
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
11 'IMPL::Object' => undef,
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
12 'IMPL::Object::Serializable' => undef,
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
13 'IMPL::Object::Autofill' => '@_'
233
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 206
diff changeset
14 ]
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
15 };
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
16
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 199
diff changeset
17 sub contentType {
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 199
diff changeset
18 'application/json'
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 199
diff changeset
19 }
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 199
diff changeset
20
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
21 sub Invoke {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
22 my ($this,$action,$next) = @_;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
23
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 199
diff changeset
24 my $result = $next ? $next->($action) : undef;
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 233
diff changeset
25
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
26
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 233
diff changeset
27 my $model = ( ref $result and eval { $result->isa(ViewResult) } )
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 233
diff changeset
28 ? $result->model
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 233
diff changeset
29 : $result;
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 233
diff changeset
30
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 233
diff changeset
31 $model = [$model] unless ref $model;
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 233
diff changeset
32
233
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 206
diff changeset
33 return HttpResponse->new({
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 206
diff changeset
34 type => $this->contentType,
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 206
diff changeset
35 charset => 'utf-8',
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 233
diff changeset
36 body => JSON->new->utf8->pretty->encode($model)
233
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 206
diff changeset
37 });
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
38 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
39
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
40 1;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
41
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
42 __END__
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
43
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
44 =pod
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
45
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
46 =head1
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
47
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
48 =cut