view Lib/IMPL/Web/Handler/JSONView.pm @ 206:c8fe3f84feba

+IMPL::Web::Handlers::ViewSelector +IMPL::Web::Handlers::ErrorHandler *IMPL::Web::Handlers::RestController moved types mappings to ViewSelector
author sergey
date Thu, 03 May 2012 16:48:39 +0400
parents e743a8481327
children 3cebcf6fdb9b
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 contentType {
	'application/json'
}

sub Invoke {
	my ($this,$action,$next) = @_;
	
	my $result = $next ? $next->($action) : undef;
	$result = [$result] unless ref $result;
	
	$action->response->contentType($this->contentType);
    
    my $hout = $action->response->streamBody;
    
    print $hout JSON->new->utf8->pretty->encode($result);
}

1;

__END__

=pod

=head1

=cut