changes to allow objects instead of classes for Serializers
[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
f465980c 9our $VERSION = '0.81';
10$VERSION = eval $VERSION;
11
e601adda 12sub execute {
13 my $self = shift;
14 my ( $controller, $c ) = @_;
15
faf5c20b 16 my $stash_key = (
07682cbc 17 $controller->{'serialize'} ?
18 $controller->{'serialize'}->{'stash_key'} :
19 $controller->{'stash_key'}
faf5c20b 20 ) || 'rest';
7f36b63e 21 my $output = $self->serialize( $c->stash->{$stash_key} );
e601adda 22 $c->response->output( $output );
23 return 1;
24}
25
485b5160 26sub serialize {
546f2871 27 my $self = shift;
e9073a60 28 encode_json( shift );
546f2871 29}
30
e601adda 311;