use Scalar::Util qw(weaken blessed refaddr openhandle);
use JSON::PP qw(encode_json);
use Moo;
+use Carp qw(croak);
BEGIN {
router()->exclude_forwarding;
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;
BEGIN { router()->exclude_forwarding }
has connection => (
- is => 'ro', required => 1,
+ is => 'ro', required => 1, handles => ['is_valid'],
coerce => sub {
blessed($_[0])
? $_[0]
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)
};
}
package Object::Remote::Proxy;
use strictures 1;
+use Carp qw(croak);
sub AUTOLOAD {
my $self = shift;
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 => @_);
}
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: $_" } @_;
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;
#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') }
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 {
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