}
}
-sub _sudo_perl_command {
+has sudo_perl_command => (is => 'lazy');
+
+sub _build_sudo_perl_command {
my ($self) = @_;
return
'sudo', '-S', '-u', $self->target_user, '-p', "[sudo] password please\n",
'perl', '-MPOSIX=dup2',
'-e', 'print STDERR "GO\n"; exec(@ARGV);',
- $self->_perl_command($self->target_user);
+ $self->perl_command;
}
sub _start_perl {
my $foreign_stdin,
my $foreign_stdout,
$sudo_stderr,
- $self->_sudo_perl_command(@_)
+ @{$self->sudo_perl_command}
) or die "open3 failed: $!";
chomp(my $line = <$sudo_stderr>);
if ($line eq "GO") {
has ssh_to => (is => 'ro', required => 1);
-around _perl_command => sub {
- my ($orig, $self) = @_;
- return 'ssh', '-A', $self->ssh_to, $self->$orig;
-};
+has ssh_perl_command => (is => 'lazy');
+
+sub _build_ssh_perl_command {
+ my ($self) = @_;
+ return [ 'ssh', '-A', $self->ssh_to, @{$self->perl_command} ];
+}
+
+sub final_perl_command { shift->ssh_perl_command }
no warnings 'once';
$self->_write_select->add($fh);
$self->_write_watches->{$fh} = $cb;
}
+ return;
}
sub unwatch_io {
requires '_open2_for';
+has timeout => (is => 'ro', default => sub { { after => 5 } });
+
sub connect {
my $self = shift;
my ($send_to_fh, $receive_from_fh, $child_pid) = $self->_open2_for(@_);
});
Object::Remote->current_loop
->watch_time(
- after => 5,
+ %{$self->timeout},
code => sub {
$f->fail("Connection timed out") unless $f->is_ready;
undef($channel);
return $hook ? $hook->sender : Object::Remote::ModuleSender->new;
}
+has perl_command => (is => 'lazy');
+
+sub _build_perl_command { [ 'perl', '-' ] }
+
around connect => sub {
my ($orig, $self) = (shift, shift);
my $f = $self->$start::start($orig => @_);
} 2;
};
-sub _perl_command { 'perl', '-' }
+sub final_perl_command { shift->perl_command }
sub _start_perl {
my $self = shift;
my $pid = open2(
my $foreign_stdout,
my $foreign_stdin,
- $self->_perl_command(@_),
+ @{$self->final_perl_command},
) or die "Failed to run perl at '$_[0]': $!";
return ($foreign_stdin, $foreign_stdout, $pid);
}