proxy dies() when a method is invoked and the handle is not valid; add 2 more exclusi...
Tyler Riddle [Fri, 30 Nov 2012 01:36:37 +0000 (17:36 -0800)]
lib/Object/Remote/Connection.pm
lib/Object/Remote/Handle.pm
lib/Object/Remote/Proxy.pm
lib/Object/Remote/Role/Connector.pm
lib/Object/Remote/Role/Connector/PerlInterpreter.pm
lib/Object/Remote/Role/LogForwarder.pm
lib/Object/Remote/WatchDog.pm

index e47b8fc..4120395 100644 (file)
@@ -16,6 +16,7 @@ use Module::Runtime qw(use_module);
 use Scalar::Util qw(weaken blessed refaddr openhandle);
 use JSON::PP qw(encode_json);
 use Moo;
+use Carp qw(croak);
 
 BEGIN { 
   router()->exclude_forwarding;
@@ -343,7 +344,7 @@ sub _send {
   my $fh = $self->send_to_fh;
   
   unless ($self->is_valid) {
-    die "Attempt to invoke _send on a connection that is not valid";
+    croak "Attempt to invoke _send on a connection that is not valid";
   }
   
   Dlog_trace { "Starting to serialize data in argument to _send for connection $_" } $self->_id;
index 8b1bd31..7e9c218 100644 (file)
@@ -14,7 +14,7 @@ use Moo;
 BEGIN { router()->exclude_forwarding }
 
 has connection => (
-  is => 'ro', required => 1,
+  is => 'ro', required => 1, handles => ['is_valid'],
   coerce => sub {
     blessed($_[0])
       ? $_[0]
@@ -58,11 +58,14 @@ sub BUILD {
 sub call {
   my ($self, $method, @args) = @_;
   my $w = wantarray;
-  log_trace { my $def = defined $w ? 1 : 0; "call() has been invoked on a remote handle; wantarray: '$def'" };
+  my $id = $self->id;
   
   $method = "start::${method}" if (caller(0)||'') eq 'start';
+  log_trace { "call('$method') has been invoked on remote handle '$id'; creating future" };
+
   future {
-    $self->connection->send(call => $self->id, $w, $method, @args)
+    log_debug { "Invoking send on connection for handle '$id' method $method" };
+    $self->connection->send(call => $id, $w, $method, @args)
   };
 }
 
index 3c46eeb..68706bd 100644 (file)
@@ -1,6 +1,7 @@
 package Object::Remote::Proxy;
 
 use strictures 1;
+use Carp qw(croak);
 
 sub AUTOLOAD {
   my $self = shift;
@@ -9,6 +10,11 @@ sub AUTOLOAD {
   if ((caller(0)||'') eq 'start') {
     $to_fire = "start::${to_fire}";
   }
+  
+  unless ($self->{remote}->is_valid) {
+    croak "Attempt to use Object::Remote::Proxy backed by an invalid handle";
+  }
+  
   $self->{remote}->$to_fire($method => @_);
 }
 
index 747341c..d294517 100644 (file)
@@ -2,13 +2,15 @@ package Object::Remote::Role::Connector;
 
 use Module::Runtime qw(use_module);
 use Object::Remote::Future;
-use Object::Remote::Logging qw(:log :dlog );
+use Object::Remote::Logging qw(:log :dlog router);
 use Moo::Role;
 
 requires '_open2_for';
 
 has timeout => (is => 'ro', default => sub { 10 });
 
+BEGIN { router()->exclude_forwarding; }
+
 sub connect {
   my $self = shift;
   Dlog_debug { "Preparing to create connection with args of: $_" } @_;
index 16bf6a6..0a7ad67 100644 (file)
@@ -4,7 +4,7 @@ use IPC::Open2;
 use IPC::Open3; 
 use IO::Handle;
 use Symbol; 
-use Object::Remote::Logging qw( :log :dlog router );
+use Object::Remote::Logging qw(:log :dlog router);
 use Object::Remote::ModuleSender;
 use Object::Remote::Handle;
 use Object::Remote::Future;
@@ -25,6 +25,8 @@ has connection_id => (is => 'rwp');
 #of the child will be connected to stderr of the parent
 has stderr => ( is => 'rw', default => sub { undef } );
 
+BEGIN { router()->exclude_forwarding; }
+
 sub _build_module_sender {
   my ($hook) =
     grep {blessed($_) && $_->isa('Object::Remote::ModuleLoader::Hook') }
index 1ff8e5f..cad2572 100644 (file)
@@ -23,7 +23,11 @@ after _deliver_message => sub {
   
   local $reentrant = $package;
   
-  $destination->_deliver_message($level, $generator, $args, $metadata);
+  eval { $destination->_deliver_message($level, $generator, $args, $metadata) };
+  
+  if ($@ && $@ !~ /^Attempt to use Object::Remote::Proxy backed by an invalid handle/) {
+    die $@;
+  }
 };
 
 sub exclude_forwarding {
index 3d47ac4..7e4d1fe 100644 (file)
@@ -1,18 +1,20 @@
 package Object::Remote::WatchDog; 
 
 use Object::Remote::MiniLoop; 
-use Object::Remote::Logging qw ( :log :dlog );
+use Object::Remote::Logging qw (:log :dlog router);
 use Moo; 
 
 has timeout => ( is => 'ro', required => 1 );
 
+BEGIN { router()->exclude_forwarding; }
+
 around new => sub {
   my ($orig, $self, @args) = @_; 
   our ($WATCHDOG);
     
   return $WATCHDOG if defined $WATCHDOG;
   log_trace { "Constructing new instance of global watchdog" };
-  return $WATCHDOG = $self->$orig(@args);    
+  return $WATCHDOG = $self->$orig(@args);
 };
 
 #start the watchdog