rename ActionRole::Serialize -> ActionRole::SerializeFormat
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / ActionRole / SerializeFormat.pm
CommitLineData
b92bf58f 1package Catalyst::ActionRole::SerializeFormat;
fc97153d 2use Moose::Role;
3use Catalyst::ControllerRole::SerializeConfig;
4use Moose::Util qw(does_role);
5use namespace::clean -except => 'meta';
6requires 'serialize';
7
8around execute => sub {
fc97153d 9 my $next = shift;
10 my ($self, $controller, $c, $arg) = @_;
b92bf58f 11
12 # XXX is ignoring the return value here correct? the original serialize
13 # actions never even called their body.
14 $self->$next($controller, $c, $arg)
15 if blessed $self;
16
fc97153d 17 Catalyst::ControllerRole::SerializeConfig->meta->apply($controller)
18 unless does_role($controller, 'Catalyst::ControllerRole::SerializeConfig');
19
20 my $stash_key = $controller->serialize_config->{stash_key} || 'rest';
21
22 my $output;
23 eval {
24 $output = $self->serialize(
25 $c->stash->{$stash_key},
26 $c,
27 $arg,
28 );
29 };
30 return $@ if $@;
31 # horrible, but the best I can do given the existing magic return value
32 # conventions.
33 return $output if $output eq '0';
34 $c->response->body($output) unless $c->response->body;
35 return 1;
36};
37
381;