Commit | Line | Data |
47c83a13 |
1 | package Object::Remote::Connector::SSH; |
2 | |
84b04178 |
3 | use Object::Remote::ModuleSender; |
8ba4f2e3 |
4 | use Object::Remote::Handle; |
47c83a13 |
5 | use Moo; |
6 | |
a9fdb55e |
7 | with 'Object::Remote::Role::Connector::PerlInterpreter'; |
47c83a13 |
8 | |
fbd3b8ec |
9 | has ssh_to => (is => 'ro', required => 1); |
10 | |
498c4ad5 |
11 | has ssh_perl_command => (is => 'lazy'); |
12 | |
6ec765ba |
13 | has ssh_options => (is => 'ro', default => sub { [ '-A' ] }); |
14 | |
15 | has ssh_command => (is => 'ro', default => sub { 'ssh' }); |
16 | |
69aaad21 |
17 | #TODO properly integrate if this works |
18 | BEGIN { $ENV{TERM} = 'dumb'; } |
19 | |
498c4ad5 |
20 | sub _build_ssh_perl_command { |
21 | my ($self) = @_; |
6ec765ba |
22 | return [ |
23 | do { my $c = $self->ssh_command; ref($c) ? @$c : $c }, |
24 | @{$self->ssh_options}, $self->ssh_to, |
25 | @{$self->perl_command} |
26 | ]; |
498c4ad5 |
27 | } |
28 | |
29 | sub final_perl_command { shift->ssh_perl_command } |
84b04178 |
30 | |
7efea51f |
31 | no warnings 'once'; |
32 | |
84b04178 |
33 | push @Object::Remote::Connection::Guess, sub { |
34 | for ($_[0]) { |
35 | # 0-9 a-z _ - first char, those or . subsequent - hostnamish |
a9fdb55e |
36 | if (defined and !ref and /^(?:.*?\@)?[\w\-][\w\-\.]/) { |
69aaad21 |
37 | my $host = shift(@_); |
38 | return __PACKAGE__->new(@_, ssh_to => $host); |
84b04178 |
39 | } |
40 | } |
41 | return; |
42 | }; |
43 | |
47c83a13 |
44 | 1; |