annotate Lib/IMPL/Web/Handler/JSONView.pm @ 202:5146e17a7b76

IMPL::Web::Application::RestResource fixes, documentation
author sergey
date Wed, 25 Apr 2012 02:49:23 +0400
parents e743a8481327
children c8fe3f84feba
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
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents: 198
diff changeset
20 #$action->response->contentType('text/javascript');
198
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