fatnode over ssh works
Matt S Trout [Thu, 17 May 2012 19:44:26 +0000 (19:44 +0000)]
bin/object-remote-node
lib/Object/Remote/Connection.pm
lib/Object/Remote/Connector/Local.pm
lib/Object/Remote/Connector/SSH.pm [new file with mode: 0644]
lib/Object/Remote/Connector/STDIO.pm
lib/Object/Remote/Role/Connector.pm [new file with mode: 0644]
maint/mk-fat [new file with mode: 0755]

index 638b6bc..807f834 100755 (executable)
@@ -12,4 +12,6 @@ my $loop = Object::Remote->current_loop;
 
 $c->on_close(sub { $loop->stop });
 
+print { $c->send_to_fh } "Shere\n";
+
 $loop->run;
index 09d5712..a6df92c 100644 (file)
@@ -31,6 +31,8 @@ has receive_from_fh => (
 
 has on_close => (is => 'rw', default => sub {});
 
+has child_pid => (is => 'ro');
+
 has _receive_data_buffer => (is => 'ro', default => sub { my $x = ''; \$x });
 
 has local_objects_by_id => (is => 'ro', default => sub { {} });
index 4900037..c57d07d 100644 (file)
@@ -1,18 +1,15 @@
 package Object::Remote::Connector::Local;
 
 use IPC::Open2;
-use Object::Remote::Connection;
 use Moo;
 
-sub connect {
+with 'Object::Remote::Role::Connector';
+
+sub _open2_for {
   # XXX bin/ is wrong but meh, fix later
   my $pid = open2(my $its_stdout, my $its_stdin, 'bin/object-remote-node')
     or die "Couldn't start local node: $!";
-  Object::Remote::Connection->new(
-    send_to_fh => $its_stdin,
-    receive_from_fh => $its_stdout,
-    child_pid => $pid
-  );
+  return ($its_stdin, $its_stdout, $pid);
 }
 
 1;
diff --git a/lib/Object/Remote/Connector/SSH.pm b/lib/Object/Remote/Connector/SSH.pm
new file mode 100644 (file)
index 0000000..c9193d0
--- /dev/null
@@ -0,0 +1,23 @@
+package Object::Remote::Connector::SSH;
+
+use Object::Remote::FatNode;
+use Net::OpenSSH;
+use Moo;
+
+with 'Object::Remote::Role::Connector';
+
+has ssh_masters => (is => 'ro', default => sub { {} });
+
+sub _open2_for {
+  my $self = shift;
+  my @res = $self->_ssh_object_for(@_)->open2('perl','-',@_);
+  print { $res[0] } $Object::Remote::FatNode::DATA, "__END__\n";
+  return @res;
+}
+
+sub _ssh_object_for {
+  my ($self, $on) = @_;
+  $self->ssh_masters->{$on} ||= Net::OpenSSH->new($on);
+}
+
+1;
index 49cb0f9..adca748 100644 (file)
@@ -15,7 +15,7 @@ sub connect {
   open STDIN, '<', File::Spec->devnull or die "Re-opening stdin: $!";
   close STDOUT or die "Closing stdout: $!";
   open STDOUT, '>', File::Spec->devnull or die "Re-opening stdout: $!";
-  Object::Remote::Connection->new(
+  return Object::Remote::Connection->new(
     send_to_fh => $stdout,
     receive_from_fh => $stdin
   );
diff --git a/lib/Object/Remote/Role/Connector.pm b/lib/Object/Remote/Role/Connector.pm
new file mode 100644 (file)
index 0000000..9c7ac7b
--- /dev/null
@@ -0,0 +1,19 @@
+package Object::Remote::Role::Connector;
+
+use Object::Remote::Connection;
+use Moo::Role;
+
+requires '_open2_for';
+
+sub connect {
+  my $self = shift;
+  my %args;
+  @args{qw(send_to_fh receive_from_fh child_pid)} = $self->_open2_for(@_);
+  my $line = readline($args{receive_from_fh});
+  unless ($line eq "Shere\n") {
+    die "New remote container did not send Shere - got ${line}";
+  }
+  return Object::Remote::Connection->new(\%args);
+}
+
+1;
diff --git a/maint/mk-fat b/maint/mk-fat
new file mode 100755 (executable)
index 0000000..f137ac9
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+if [ -e fatlib ]; then rm -r fatlib; fi
+fatpack tree $(fatpack packlists-for strictures.pm Module/Runtime.pm Moo.pm JSON/PP.pm MRO/Compat.pm Class/C3.pm Algorithm/C3.pm Class/Method/Modifiers.pm Role/Tiny.pm CPS/Future.pm)
+rm lib/Object/Remote/FatNode.pm
+(
+  echo 'package Object::Remote::FatNode;
+our $DATA = do { local $/; <DATA> };
+1;
+__DATA__
+';
+  fatpack file;
+  cat bin/object-remote-node
+)>lib/Object/Remote/FatNode.pm
+rm -r fatlib