view Lib/IMPL/Web/Handler/JSONView.pm @ 199:e743a8481327

Added REST support for forms (with only get and post methods)
author sergey
date Mon, 23 Apr 2012 01:36:52 +0400
parents 2ffe6f661605
children c8fe3f84feba
line wrap: on
line source

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