Port Serialize classes except for View.
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Serialize / JSON.pm
CommitLineData
e601adda 1package Catalyst::Action::Serialize::JSON;
2
930013e6 3use Moose;
4use namespace::autoclean;
e601adda 5
930013e6 6extends 'Catalyst::Action';
ebba5325 7use JSON qw(encode_json);
e601adda 8
9sub execute {
10 my $self = shift;
11 my ( $controller, $c ) = @_;
12
faf5c20b 13 my $stash_key = (
07682cbc 14 $controller->{'serialize'} ?
15 $controller->{'serialize'}->{'stash_key'} :
16 $controller->{'stash_key'}
faf5c20b 17 ) || 'rest';
71cbfa6b 18 my $output = $self->serialize( $c->stash->{$stash_key} );
e601adda 19 $c->response->output( $output );
20 return 1;
21}
22
485b5160 23sub serialize {
546f2871 24 my $self = shift;
e9073a60 25 encode_json( shift );
546f2871 26}
27
e601adda 281;