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 | |
f465980c | 9 | our $VERSION = '0.81'; |
10 | $VERSION = eval $VERSION; | |
11 | ||
e601adda | 12 | sub 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 | 26 | sub serialize { |
546f2871 | 27 | my $self = shift; |
e9073a60 | 28 | encode_json( shift ); |
546f2871 | 29 | } |
30 | ||
e601adda | 31 | 1; |