198
|
1 package IMPL::Web::Handler::JSONView;
|
|
2 use strict;
|
|
3 use JSON;
|
|
4
|
|
5 use IMPL::lang qw(:declare :constants);
|
|
6 use IMPL::declare {
|
|
7 base => {
|
|
8 'IMPL::Object' => undef,
|
|
9 'IMPL::Object::Serializable' => undef,
|
|
10 'IMPL::Object::Autofill' => '@_'
|
|
11 }
|
|
12 };
|
|
13
|
206
|
14 sub contentType {
|
|
15 'application/json'
|
|
16 }
|
|
17
|
198
|
18 sub Invoke {
|
|
19 my ($this,$action,$next) = @_;
|
|
20
|
206
|
21 my $result = $next ? $next->($action) : undef;
|
198
|
22 $result = [$result] unless ref $result;
|
|
23
|
206
|
24 $action->response->contentType($this->contentType);
|
198
|
25
|
|
26 my $hout = $action->response->streamBody;
|
|
27
|
|
28 print $hout JSON->new->utf8->pretty->encode($result);
|
|
29 }
|
|
30
|
|
31 1;
|
|
32
|
|
33 __END__
|
|
34
|
|
35 =pod
|
|
36
|
|
37 =head1
|
|
38
|
|
39 =cut |