1 package Catalyst::Controller::MessageDriven;
4 BEGIN { extends 'Catalyst::Controller' }
7 'default' => 'text/x-yaml',
8 'stash_key' => 'response',
9 'map' => { 'text/x-yaml' => 'YAML' },
12 sub begin :ActionClass('Deserialize') { }
14 sub end :ActionClass('Serialize') {
17 # Engine will send our reply based on the value of this header.
18 $c->response->headers->header( 'X-Reply-Address' => $c->req->data->{reply_to} );
20 # Custom error handler - steal errors from catalyst and dump them into
21 # the stash, to get them serialized out as the reply.
22 if (scalar @{$c->error}) {
23 my $error = join "\n", @{$c->error};
24 $c->stash->{response} = { status => 'ERROR', error => $error };
25 $c->error(0); # clear errors, so our response isn't clobbered
29 sub default : Private {
32 # Forward the request to the appropriate action, based on the
34 my $action = $c->req->data->{type};
35 $c->forward($action, [$c->req->data]);
38 __PACKAGE__->meta->make_immutable;