annotate Lib/IMPL/Web/Handler/JSONView.pm @ 233:3cebcf6fdb9b

refactoring, cleaning code
author sergey
date Thu, 11 Oct 2012 04:53:08 +0400
parents c8fe3f84feba
children f48a1a9f4fa2
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 => {
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 206
diff changeset
7 HttpResponse => 'IMPL::Web::HttpResponse'
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 206
diff changeset
8 },
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 206
diff changeset
9 base => [
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
10 'IMPL::Object' => undef,
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
11 'IMPL::Object::Serializable' => undef,
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
12 'IMPL::Object::Autofill' => '@_'
233
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 206
diff changeset
13 ]
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
14 };
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
15
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 199
diff changeset
16 sub contentType {
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 199
diff changeset
17 'application/json'
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 199
diff changeset
18 }
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 199
diff changeset
19
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
20 sub Invoke {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
21 my ($this,$action,$next) = @_;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
22
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 199
diff changeset
23 my $result = $next ? $next->($action) : undef;
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
24 $result = [$result] unless ref $result;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
25
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 199
diff changeset
26 $action->response->contentType($this->contentType);
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
27
233
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 206
diff changeset
28 return HttpResponse->new({
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 206
diff changeset
29 type => $this->contentType,
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 206
diff changeset
30 charset => 'utf-8',
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 206
diff changeset
31 body => JSON->new->utf8->pretty->encode($result)
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 206
diff changeset
32 });
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
33 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
34
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
35 1;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
36
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
37 __END__
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
38
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
39 =pod
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
40
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
41 =head1
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
42
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
43 =cut