1 package Object::Remote::Role::Connector::PerlInterpreter;
4 use Object::Remote::ModuleSender;
5 use Object::Remote::Handle;
6 use Scalar::Util qw(blessed);
9 with 'Object::Remote::Role::Connector';
11 has module_sender => (is => 'lazy');
13 sub _build_module_sender {
15 grep {blessed($_) && $_->isa('Object::Remote::ModuleLoader::Hook') }
17 return $hook ? $hook->sender : Object::Remote::ModuleSender->new;
20 around connect => sub {
21 my ($orig, $self) = (shift, shift);
22 my $conn = $self->$orig(@_);
23 Object::Remote::Handle->new(
25 class => 'Object::Remote::ModuleLoader',
26 args => { module_sender => $self->module_sender }
31 sub _perl_command { 'perl', '-' }
38 $self->_perl_command(@_),
39 ) or die "Failed to run perl at '$_[0]': $!";
40 return ($foreign_stdin, $foreign_stdout, $pid);
45 my ($foreign_stdin, $foreign_stdout, $pid) = $self->_start_perl(@_);
46 print $foreign_stdin 'BEGIN { $ENV{OBJECT_REMOTE_DEBUG} = 1 }'."\n"
47 if $ENV{OBJECT_REMOTE_DEBUG};
48 print $foreign_stdin $self->fatnode_text
49 or die "Failed to send fatpacked data to new node on '$_[0]': $!";
50 return ($foreign_stdin, $foreign_stdout, $pid);
55 require Object::Remote::FatNode;
57 $text .= 'BEGIN { $ENV{OBJECT_REMOTE_DEBUG} = 1 }'."\n"
58 if $ENV{OBJECT_REMOTE_DEBUG};
60 $INC{'Object/Remote/FatNode.pm'} = __FILE__;
61 $Object::Remote::FatNode::DATA = <<'ENDFAT';
63 $text .= $Object::Remote::FatNode::DATA;
66 eval $Object::Remote::FatNode::DATA;