remove incomplete non-blocking support; make select() timeout duration configurable...
[scpubgit/Object-Remote.git] / lib / Object / Remote / Connector / SSH.pm
CommitLineData
47c83a13 1package Object::Remote::Connector::SSH;
2
84b04178 3use Object::Remote::ModuleSender;
8ba4f2e3 4use Object::Remote::Handle;
47c83a13 5use Moo;
6
a9fdb55e 7with 'Object::Remote::Role::Connector::PerlInterpreter';
47c83a13 8
fbd3b8ec 9has ssh_to => (is => 'ro', required => 1);
10
498c4ad5 11has ssh_perl_command => (is => 'lazy');
12
6ec765ba 13has ssh_options => (is => 'ro', default => sub { [ '-A' ] });
14
15has ssh_command => (is => 'ro', default => sub { 'ssh' });
16
b9baacc2 17sub _escape_shell_arg {
18 my ($self, $str) = (@_);
19 $str =~ s/((?:^|[^\\])(?:\\\\)*)'/$1\\'/g;
20 return "$str";
21}
22
23
498c4ad5 24sub _build_ssh_perl_command {
25 my ($self) = @_;
b9baacc2 26 my $perl_command = join('', @{$self->perl_command});
27
28 #TODO non-trivial to escape properly for ssh and shell
29 #this "works" but is not right, needs to be replaced
30 #after testing
6ec765ba 31 return [
32 do { my $c = $self->ssh_command; ref($c) ? @$c : $c },
33 @{$self->ssh_options}, $self->ssh_to,
b9baacc2 34 $self->_escape_shell_arg($perl_command),
6ec765ba 35 ];
498c4ad5 36}
37
38sub final_perl_command { shift->ssh_perl_command }
84b04178 39
7efea51f 40no warnings 'once';
41
84b04178 42push @Object::Remote::Connection::Guess, sub {
43 for ($_[0]) {
44 # 0-9 a-z _ - first char, those or . subsequent - hostnamish
a9fdb55e 45 if (defined and !ref and /^(?:.*?\@)?[\w\-][\w\-\.]/) {
c824fdf3 46 my $host = shift(@_);
47 return __PACKAGE__->new(@_, ssh_to => $host);
84b04178 48 }
49 }
50 return;
51};
52
47c83a13 531;