Mercurial > pub > Impl
comparison 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 |
comparison
equal
deleted
inserted
replaced
232:5c82eec23bb6 | 233:3cebcf6fdb9b |
---|---|
1 package IMPL::Web::Handler::JSONView; | 1 package IMPL::Web::Handler::JSONView; |
2 use strict; | 2 use strict; |
3 use JSON; | 3 use JSON; |
4 | 4 |
5 use IMPL::lang qw(:declare :constants); | |
6 use IMPL::declare { | 5 use IMPL::declare { |
7 base => { | 6 require => { |
7 HttpResponse => 'IMPL::Web::HttpResponse' | |
8 }, | |
9 base => [ | |
8 'IMPL::Object' => undef, | 10 'IMPL::Object' => undef, |
9 'IMPL::Object::Serializable' => undef, | 11 'IMPL::Object::Serializable' => undef, |
10 'IMPL::Object::Autofill' => '@_' | 12 'IMPL::Object::Autofill' => '@_' |
11 } | 13 ] |
12 }; | 14 }; |
13 | 15 |
14 sub contentType { | 16 sub contentType { |
15 'application/json' | 17 'application/json' |
16 } | 18 } |
21 my $result = $next ? $next->($action) : undef; | 23 my $result = $next ? $next->($action) : undef; |
22 $result = [$result] unless ref $result; | 24 $result = [$result] unless ref $result; |
23 | 25 |
24 $action->response->contentType($this->contentType); | 26 $action->response->contentType($this->contentType); |
25 | 27 |
26 my $hout = $action->response->streamBody; | 28 return HttpResponse->new({ |
27 | 29 type => $this->contentType, |
28 print $hout JSON->new->utf8->pretty->encode($result); | 30 charset => 'utf-8', |
31 body => JSON->new->utf8->pretty->encode($result) | |
32 }); | |
29 } | 33 } |
30 | 34 |
31 1; | 35 1; |
32 | 36 |
33 __END__ | 37 __END__ |