operator precedence fail
[scpubgit/Object-Remote.git] / lib / Object / Remote / Connector / SSH.pm
CommitLineData
47c83a13 1package Object::Remote::Connector::SSH;
2
3use Object::Remote::FatNode;
84b04178 4use Object::Remote::ModuleSender;
8ba4f2e3 5use Object::Remote::Handle;
84b04178 6use IPC::Open2;
47c83a13 7use Moo;
8
9with 'Object::Remote::Role::Connector';
10
47c83a13 11sub _open2_for {
12 my $self = shift;
84b04178 13 my $pid = open2(my $ssh_stdout, my $ssh_stdin, 'ssh', $_[0], 'perl', '-')
14 or die "Failed to start ssh connection: $!";;
15 print $ssh_stdin $Object::Remote::FatNode::DATA, "__END__\n";
16 return ($ssh_stdin, $ssh_stdout, $pid);
47c83a13 17}
18
84b04178 19around connect => sub {
20 my ($orig, $self) = (shift, shift);
21 my $conn = $self->$orig(@_);
8ba4f2e3 22 Object::Remote::Handle->new(
84b04178 23 connection => $conn,
24 class => 'Object::Remote::ModuleLoader',
25 args => { module_sender => Object::Remote::ModuleSender->new }
26 )->disarm_free;
27 return $conn;
28};
29
47c83a13 30sub _ssh_object_for {
31 my ($self, $on) = @_;
32 $self->ssh_masters->{$on} ||= Net::OpenSSH->new($on);
33}
34
84b04178 35push @Object::Remote::Connection::Guess, sub {
36 for ($_[0]) {
37 # 0-9 a-z _ - first char, those or . subsequent - hostnamish
38 if (defined and !ref and /^(?:.*?\@)?[\w\-][\w\-\.]*/) {
39 return __PACKAGE__->new->connect($_[0]);
40 }
41 }
42 return;
43};
44
47c83a13 451;