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
|
|
14 sub Invoke {
|
|
15 my ($this,$action,$next) = @_;
|
|
16
|
|
17 my $result = $next->($action);
|
|
18 $result = [$result] unless ref $result;
|
|
19
|
|
20 $action->response->contentType('text/javascript');
|
|
21
|
|
22 my $hout = $action->response->streamBody;
|
|
23
|
|
24 print $hout JSON->new->utf8->pretty->encode($result);
|
|
25 }
|
|
26
|
|
27 1;
|
|
28
|
|
29 __END__
|
|
30
|
|
31 =pod
|
|
32
|
|
33 =head1
|
|
34
|
|
35 =cut |