1 package Object::Remote::Connector::SSH;
3 use Object::Remote::ModuleSender;
4 use Object::Remote::Handle;
7 with 'Object::Remote::Role::Connector::PerlInterpreter';
9 has ssh_to => (is => 'ro', required => 1);
11 has ssh_perl_command => (is => 'lazy');
13 has ssh_options => (is => 'ro', default => sub { [ '-A' ] });
15 has ssh_command => (is => 'ro', default => sub { 'ssh' });
17 #TODO properly integrate if this works
18 BEGIN { $ENV{TERM} = 'dumb'; }
20 sub _escape_shell_arg {
21 my ($self, $str) = (@_);
22 $str =~ s/((?:^|[^\\])(?:\\\\)*)'/$1\\'/g;
27 sub _build_ssh_perl_command {
29 my $perl_command = join('', @{$self->perl_command});
31 #TODO non-trivial to escape properly for ssh and shell
32 #this "works" but is not right, needs to be replaced
35 do { my $c = $self->ssh_command; ref($c) ? @$c : $c },
36 @{$self->ssh_options}, $self->ssh_to,
37 $self->_escape_shell_arg($perl_command),
41 sub final_perl_command { shift->ssh_perl_command }
45 push @Object::Remote::Connection::Guess, sub {
47 # 0-9 a-z _ - first char, those or . subsequent - hostnamish
48 if (defined and !ref and /^(?:.*?\@)?[\w\-][\w\-\.]/) {
50 return __PACKAGE__->new(@_, ssh_to => $host);