annotate Lib/IMPL/Web/Handler/JSONView.pm @ 216:e9fd7ff3f54c

sync
author sergey
date Thu, 09 Aug 2012 17:24:07 +0400
parents c8fe3f84feba
children 3cebcf6fdb9b
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::lang qw(:declare :constants);
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
6 use IMPL::declare {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
7 base => {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
8 'IMPL::Object' => undef,
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
9 'IMPL::Object::Serializable' => undef,
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
10 'IMPL::Object::Autofill' => '@_'
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
11 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
12 };
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
13
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 199
diff changeset
14 sub contentType {
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 199
diff changeset
15 'application/json'
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 199
diff changeset
16 }
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 199
diff changeset
17
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
18 sub Invoke {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
19 my ($this,$action,$next) = @_;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
20
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 199
diff changeset
21 my $result = $next ? $next->($action) : undef;
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
22 $result = [$result] unless ref $result;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
23
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 199
diff changeset
24 $action->response->contentType($this->contentType);
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
25
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
26 my $hout = $action->response->streamBody;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
27
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
28 print $hout JSON->new->utf8->pretty->encode($result);
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
29 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
30
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
31 1;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
32
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
33 __END__
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
34
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
35 =pod
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
36
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
37 =head1
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
38
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
39 =cut