further detail OR->connect arguments, and document other bits
[scpubgit/Object-Remote.git] / lib / Object / Remote / Connector / SSH.pm
1 package Object::Remote::Connector::SSH;
2
3 use Object::Remote::ModuleSender;
4 use Object::Remote::Handle;
5 use String::ShellQuote;
6 use Moo;
7
8 with 'Object::Remote::Role::Connector::PerlInterpreter';
9
10 has ssh_to => (is => 'ro', required => 1);
11
12 has ssh_perl_command => (is => 'lazy');
13
14 has ssh_options => (is => 'ro', default => sub { [ '-A' ] });
15
16 has ssh_command => (is => 'ro', default => sub { 'ssh' });
17
18 sub _build_ssh_perl_command {
19   my ($self) = @_;
20   my $perl_command = $self->perl_command;
21
22   return [
23     do { my $c = $self->ssh_command; ref($c) ? @$c : $c },
24     @{$self->ssh_options}, $self->ssh_to,
25     shell_quote(@$perl_command),
26   ];
27 }
28
29 sub final_perl_command { shift->ssh_perl_command }
30
31 no warnings 'once';
32
33 push @Object::Remote::Connection::Guess, sub {
34   for ($_[0]) {
35     # 0-9 a-z _ - first char, those or . subsequent - hostnamish
36     if (defined and !ref and /^(?:.*?\@)?[\w\-][\w\-\.]/) {
37       my $host = shift(@_);
38       return __PACKAGE__->new(@_, ssh_to => $host);
39     }
40   }
41   return;
42 };
43
44 1;
45
46 =head1 NAME
47
48 Object::Remote::Connector::SSH - A connector for SSH servers
49
50 =head1 DESCRIPTION
51
52 Used to create a connector that talks to an SSH server. Invoked by
53 L<Object::Remote/connect> if the connection spec looks like a hostname or
54 user@hostname combo.
55
56 =head1 ARGUMENTS
57
58 Inherits arguments from L<Object::Remote::Role::Connector::PerlInterpreter> and
59 provides the following:
60
61 =head2 ssh_to
62
63 When invoked via L<Object::Remote/connect>, specified via the connection spec,
64 and not overridable.
65
66 String that contains hostname or user@hostname to connect to.
67
68 =head2 ssh_options
69
70 An arrayref containing a list of strings to be passed to L<IPC::Open3> with
71 options to be passed specifically to the ssh client. Defaults to C<-A>.
72
73 =head2 ssh_command
74
75 A string or arrayref of strings with the ssh command to be run. Defaults to
76 C<ssh>.
77
78 =head2 ssh_perl_command
79
80 An arrayref containing a list of strings to be passed to L<IPC::Open3> to open
81 the perl process. Defaults to constructing an ssh client incantation with the
82 other arguments here.
83
84 =cut