view Lib/IMPL/Web/Handler/JSONView.pm @ 238:b8c724f6de36

DOM model refactoring TT view refactoring, controls are no longer derived from DOM nodes bugfixes
author sergey
date Tue, 16 Oct 2012 01:33:06 +0400
parents 3cebcf6fdb9b
children f48a1a9f4fa2
line wrap: on
line source

package IMPL::Web::Handler::JSONView;
use strict;
use JSON;

use IMPL::declare {
    require => {
        HttpResponse => 'IMPL::Web::HttpResponse'        
    },
	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);
    
    return HttpResponse->new({
        type => $this->contentType,
        charset => 'utf-8',             
        body => JSON->new->utf8->pretty->encode($result)
    });
}

1;

__END__

=pod

=head1

=cut