Commit | Line | Data |
---|---|---|
e601adda | 1 | package Catalyst::Action::Serialize::JSON; |
2 | ||
930013e6 | 3 | use Moose; |
4 | use namespace::autoclean; | |
e601adda | 5 | |
930013e6 | 6 | extends 'Catalyst::Action'; |
ebba5325 | 7 | use JSON qw(encode_json); |
e601adda | 8 | |
9 | sub 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'; |
7f36b63e | 18 | my $output = $self->serialize( $c->stash->{$stash_key} ); |
e601adda | 19 | $c->response->output( $output ); |
20 | return 1; | |
21 | } | |
22 | ||
485b5160 | 23 | sub serialize { |
546f2871 | 24 | my $self = shift; |
e9073a60 | 25 | encode_json( shift ); |
546f2871 | 26 | } |
27 | ||
e601adda | 28 | 1; |