diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/Web/Handler/JSONView.pm	Fri Apr 20 16:06:36 2012 +0400
@@ -0,0 +1,35 @@
+package IMPL::Web::Handler::JSONView;
+use strict;
+use JSON;
+
+use IMPL::lang qw(:declare :constants);
+use IMPL::declare {
+	base => {
+		'IMPL::Object' => undef,
+		'IMPL::Object::Serializable' => undef,
+		'IMPL::Object::Autofill' => '@_'
+	}
+};
+
+sub Invoke {
+	my ($this,$action,$next) = @_;
+	
+	my $result = $next->($action);
+	$result = [$result] unless ref $result;
+	
+	$action->response->contentType('text/javascript');
+    
+    my $hout = $action->response->streamBody;
+    
+    print $hout JSON->new->utf8->pretty->encode($result);
+}
+
+1;
+
+__END__
+
+=pod
+
+=head1
+
+=cut
\ No newline at end of file