Mercurial > pub > Impl
annotate Lib/IMPL/Web/Handler/JSONView.pm @ 250:129e48bb5afb
DOM refactoring
ObjectToDOM methods are virtual
QueryToDOM uses inflators
Fixed transform for the complex values in the ObjectToDOM
QueryToDOM doesn't allow to use complex values (HASHes) as values for nodes (overpost problem)
author | sergey |
---|---|
date | Wed, 07 Nov 2012 04:17:53 +0400 |
parents | f48a1a9f4fa2 |
children | 32aceba4ee6d |
rev | line source |
---|---|
198 | 1 package IMPL::Web::Handler::JSONView; |
2 use strict; | |
3 use JSON; | |
4 | |
5 use IMPL::declare { | |
233 | 6 require => { |
241
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
233
diff
changeset
|
7 HttpResponse => 'IMPL::Web::HttpResponse', |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
233
diff
changeset
|
8 ViewResult => '-IMPL::Web::ViewResult' |
233 | 9 }, |
10 base => [ | |
198 | 11 'IMPL::Object' => undef, |
12 'IMPL::Object::Serializable' => undef, | |
13 'IMPL::Object::Autofill' => '@_' | |
233 | 14 ] |
198 | 15 }; |
16 | |
206 | 17 sub contentType { |
18 'application/json' | |
19 } | |
20 | |
198 | 21 sub Invoke { |
22 my ($this,$action,$next) = @_; | |
23 | |
206 | 24 my $result = $next ? $next->($action) : undef; |
241
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
233
diff
changeset
|
25 |
198 | 26 |
241
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
233
diff
changeset
|
27 my $model = ( ref $result and eval { $result->isa(ViewResult) } ) |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
233
diff
changeset
|
28 ? $result->model |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
233
diff
changeset
|
29 : $result; |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
233
diff
changeset
|
30 |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
233
diff
changeset
|
31 $model = [$model] unless ref $model; |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
233
diff
changeset
|
32 |
233 | 33 return HttpResponse->new({ |
34 type => $this->contentType, | |
35 charset => 'utf-8', | |
241
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
233
diff
changeset
|
36 body => JSON->new->utf8->pretty->encode($model) |
233 | 37 }); |
198 | 38 } |
39 | |
40 1; | |
41 | |
42 __END__ | |
43 | |
44 =pod | |
45 | |
46 =head1 | |
47 | |
48 =cut |