annotate Lib/IMPL/Web/Handler/JSONView.pm @ 198:2ffe6f661605

Implemented IMPL::Web::Handler::RestController fixes in IMPL::Serialization completed IMPL::Web::Application::RestResource added IMPL::Web::Handler::JSONView added IMPL::Web::RestContract
author cin
date Fri, 20 Apr 2012 16:06:36 +0400
parents
children e743a8481327
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
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
14 sub Invoke {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
15 my ($this,$action,$next) = @_;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
16
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
17 my $result = $next->($action);
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
18 $result = [$result] unless ref $result;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
19
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
20 $action->response->contentType('text/javascript');
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
21
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
22 my $hout = $action->response->streamBody;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
23
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
24 print $hout JSON->new->utf8->pretty->encode($result);
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
25 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
26
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
27 1;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
28
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
29 __END__
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
30
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
31 =pod
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
32
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
33 =head1
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
34
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
35 =cut