From: Matt S Trout Date: Fri, 28 Oct 2011 20:40:15 +0000 (+0000) Subject: switch Request to invocant + method, clean up Remote using a coderef method X-Git-Tag: v0.001001~34 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ca30c15e4b434c7ba6dbe61ed2df9125806d93ab;p=scpubgit%2FTak.git switch Request to invocant + method, clean up Remote using a coderef method --- diff --git a/lib/Tak/Remote.pm b/lib/Tak/Remote.pm index 7d1d7d6..821de86 100644 --- a/lib/Tak/Remote.pm +++ b/lib/Tak/Remote.pm @@ -8,22 +8,11 @@ has name => (is => 'ro', required => 1); sub blocking_request { my ($self, @payload) = @_; - local our $Request = $self->router->send_request($self, $self->name, @payload); - local our $Done; - local our @Result; - $self->router->run_until($Done); - return @Result; -} - -sub send_response { - my ($self, $tag, @result) = @_; - { - our $Request; - die "Out of order response ${\$Request->tag}, expecting ${tag}" - if $Request->tag ne $tag; - } - our @Result = @result; - our $Done = 1; + my ($done, @result); + my $cb = sub { my ($self, $tag, @r) = @_; @result = @r; $done = 1; }; + $self->router->send_request($self, $cb, $self->name, @payload); + $self->router->run_until($done); + return @result; } 1; diff --git a/lib/Tak/Request.pm b/lib/Tak/Request.pm index 669e027..2ba8262 100644 --- a/lib/Tak/Request.pm +++ b/lib/Tak/Request.pm @@ -6,9 +6,11 @@ has tag => (is => 'ro', required => 1); has respond_to => (is => 'ro', required => 1, weak_ref => 1); +has respond_with => (is => 'ro', required => 1); + sub respond { my $self = shift; - $self->respond_to->send_response($self->tag => @_); + $self->respond_to->${\$self->respond_with}($self->tag => @_); } 1; diff --git a/lib/Tak/Router.pm b/lib/Tak/Router.pm index 214455c..d48f28b 100644 --- a/lib/Tak/Router.pm +++ b/lib/Tak/Router.pm @@ -65,7 +65,7 @@ sub receive_request { my $request = $self->requests_received->{$tag} = Tak::Request->new( - tag => $tag, respond_to => $self + tag => $tag, respond_to => $self, respond_with => 'send_response', ); $handler->start_request($request => @payload); } @@ -77,13 +77,14 @@ sub send_response { } sub send_request { - my ($self, $respond_to, @payload) = @_; + my ($self, $respond_to, $respond_with, @payload) = @_; my $tag = $self->next_serial; my $request = $self->requests_sent->{$tag} = Tak::Request->new( tag => $tag, - respond_to => $respond_to + respond_to => $respond_to, + respond_with => $respond_with, ); $self->channel->send(REQUEST => $tag => @payload); return $request;