Add some feedback to the test; shorten spinup delay.
[catagits/Catalyst-Engine-STOMP.git] / lib / Catalyst / Controller / MessageDriven.pm
CommitLineData
0a663589 1package Catalyst::Controller::MessageDriven;
2use Moose;
3
4BEGIN { extends 'Catalyst::Controller' }
5
6__PACKAGE__->config(
7 'default' => 'text/x-yaml',
8 'stash_key' => 'response',
9 'map' => { 'text/x-yaml' => 'YAML' },
10 );
11
12sub begin :ActionClass('Deserialize') { }
13
14sub end :ActionClass('Serialize') {
15 my ($self, $c) = @_;
16
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} );
19
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
26 }
27}
28
29sub default : Private {
30 my ($self, $c) = @_;
31
32 # Forward the request to the appropriate action, based on the
33 # message type.
34 my $action = $c->req->data->{type};
35 $c->forward($action, [$c->req->data]);
36}
37
38__PACKAGE__->meta->make_immutable;
39
401;