From: Tomas Doran (t0m) Date: Sat, 6 Jun 2009 22:06:31 +0000 (+0100) Subject: Whitespace nazism to remove trailing and tabs X-Git-Tag: 0.05~15 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Engine-STOMP.git;a=commitdiff_plain;h=5ec5e0b187aea2b3e930da2d061910bf4d345345;hp=1b67123aedf3f11f9097a1a04a73ac940f4ec971 Whitespace nazism to remove trailing and tabs --- diff --git a/lib/Catalyst/Controller/MessageDriven.pm b/lib/Catalyst/Controller/MessageDriven.pm index 1969bfd..cdc129e 100644 --- a/lib/Catalyst/Controller/MessageDriven.pm +++ b/lib/Catalyst/Controller/MessageDriven.pm @@ -14,10 +14,10 @@ Catalyst::Controller::MessageDriven use Moose; BEGIN { extends 'Catalyst::Controller::MessageDriven' } - sub some_action : Local { + sub some_action : Local { my ($self, $c, $message) = @_; - # Handle message + # Handle message # Reply with a minimal response message my $response = { type => 'testaction_response' }; @@ -28,84 +28,83 @@ Catalyst::Controller::MessageDriven A Catalyst controller base class for use with Catalyst::Engine::Stomp, which handles YAML-serialized messages. A top-level "type" key in the -YAML determines the action dispatched to. +YAML determines the action dispatched to. =cut __PACKAGE__->config( serializer => 'YAML' ); -sub begin : Private { - my ($self, $c) = @_; - - # Deserialize the request message +sub begin : Private { + my ($self, $c) = @_; + + # Deserialize the request message my $message; - my $serializer = $self->config->{serializer}; - my $s = Data::Serializer->new( serializer => $serializer ); - eval { - my $body = $c->request->body; - open my $IN, "$body" or die "can't open temp file $body"; - $message = $s->raw_deserialize(do { local $/; <$IN> }); - }; - if ($@) { - # can't reply - reply_to is embedded in the message - $c->error("exception in deserialize: $@"); - } - else { - $c->stash->{request} = $message; - } + my $serializer = $self->config->{serializer}; + my $s = Data::Serializer->new( serializer => $serializer ); + eval { + my $body = $c->request->body; + open my $IN, "$body" or die "can't open temp file $body"; + $message = $s->raw_deserialize(do { local $/; <$IN> }); + }; + if ($@) { + # can't reply - reply_to is embedded in the message + $c->error("exception in deserialize: $@"); + } + else { + $c->stash->{request} = $message; + } } sub end : Private { - my ($self, $c) = @_; - - # Engine will send our reply based on the value of this header. - $c->response->headers->header( 'X-Reply-Address' => $c->stash->{request}->{reply_to} ); - - # The wire response - my $output; - - # Load a serializer - my $serializer = $self->config->{serializer}; - my $s = Data::Serializer->new( serializer => $serializer ); - - # Custom error handler - steal errors from catalyst and dump them into - # the stash, to get them serialized out as the reply. - if (scalar @{$c->error}) { - my $error = join "\n", @{$c->error}; - $c->stash->{response} = { status => 'ERROR', error => $error }; - $output = $s->serialize( $c->stash->{response} ); - $c->clear_errors; - $c->response->status(400); - } - - # Serialize the response - eval { - $output = $s->raw_serialize( $c->stash->{response} ); - }; - if ($@) { - my $error = "exception in serialize: $@"; - $c->stash->{response} = { status => 'ERROR', error => $error }; - $output = $s->serialize( $c->stash->{response} ); - $c->response->status(400); - } - - $c->response->output( $output ); + my ($self, $c) = @_; + + # Engine will send our reply based on the value of this header. + $c->response->headers->header( 'X-Reply-Address' => $c->stash->{request}->{reply_to} ); + + # The wire response + my $output; + + # Load a serializer + my $serializer = $self->config->{serializer}; + my $s = Data::Serializer->new( serializer => $serializer ); + + # Custom error handler - steal errors from catalyst and dump them into + # the stash, to get them serialized out as the reply. + if (scalar @{$c->error}) { + my $error = join "\n", @{$c->error}; + $c->stash->{response} = { status => 'ERROR', error => $error }; + $output = $s->serialize( $c->stash->{response} ); + $c->clear_errors; + $c->response->status(400); + } + + # Serialize the response + eval { + $output = $s->raw_serialize( $c->stash->{response} ); + }; + if ($@) { + my $error = "exception in serialize: $@"; + $c->stash->{response} = { status => 'ERROR', error => $error }; + $output = $s->serialize( $c->stash->{response} ); + $c->response->status(400); + } + + $c->response->output( $output ); } sub default : Private { - my ($self, $c) = @_; - - # Forward the request to the appropriate action, based on the - # message type. - my $action = $c->stash->{request}->{type}; - if (defined $action) { - $c->forward($action, [$c->stash->{request}]); - } - else { - $c->error('no message type specified'); - } + my ($self, $c) = @_; + + # Forward the request to the appropriate action, based on the + # message type. + my $action = $c->stash->{request}->{type}; + if (defined $action) { + $c->forward($action, [$c->stash->{request}]); + } + else { + $c->error('no message type specified'); + } } __PACKAGE__->meta->make_immutable; -1; diff --git a/lib/Catalyst/Engine/Stomp.pm b/lib/Catalyst/Engine/Stomp.pm index b619c06..49a0bab 100644 --- a/lib/Catalyst/Engine/Stomp.pm +++ b/lib/Catalyst/Engine/Stomp.pm @@ -22,7 +22,7 @@ Catalyst::Engine::Stomp - write message handling apps with Catalyst. BEGIN { $ENV{CATALYST_ENGINE} = 'Stomp'; require Catalyst::Engine::Stomp; - } + } MyApp->config->{Engine::Stomp} = { @@ -46,7 +46,7 @@ Catalyst::Engine::Stomp - write message handling apps with Catalyst. =head1 DESCRIPTION Write a Catalyst app connected to a Stomp messagebroker, not HTTP. You -need a controller that understands messaging, as well as this engine. +need a controller that understands messaging, as well as this engine. This is single-threaded and single process - you need to run multiple instances of this engine to get concurrency, and configure your broker @@ -54,8 +54,8 @@ to load-balance across multiple consumers of the same queue. Controllers are mapped to Stomp queues, and a controller base class is provided, Catalyst::Controller::MessageDriven, which implements -YAML-serialized messages, mapping a top-level YAML "type" key to -the action. +YAML-serialized messages, mapping a top-level YAML "type" key to +the action. =head1 METHODS @@ -95,8 +95,8 @@ sub run { foreach my $queue (@queues) { my $queue_name = "/queue/$queue"; $self->connection->subscribe({ - destination => $queue_name, - ack => 'client' + destination => $queue_name, + ack => 'client' }); } @@ -202,7 +202,7 @@ Log any Stomp error frames we receive. sub handle_stomp_error { my ($self, $app, $frame) = @_; - + my $error = $frame->headers->{message}; $app->log->debug("Got Stomp error: $error"); }