From: Matt S Trout Date: Thu, 17 May 2012 19:44:26 +0000 (+0000) Subject: fatnode over ssh works X-Git-Tag: v0.001001~60 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=47c83a1379a33fc8baa4a128edc1d75d780776b0;p=scpubgit%2FObject-Remote.git fatnode over ssh works --- diff --git a/bin/object-remote-node b/bin/object-remote-node index 638b6bc..807f834 100755 --- a/bin/object-remote-node +++ b/bin/object-remote-node @@ -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; diff --git a/lib/Object/Remote/Connection.pm b/lib/Object/Remote/Connection.pm index 09d5712..a6df92c 100644 --- a/lib/Object/Remote/Connection.pm +++ b/lib/Object/Remote/Connection.pm @@ -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 { {} }); diff --git a/lib/Object/Remote/Connector/Local.pm b/lib/Object/Remote/Connector/Local.pm index 4900037..c57d07d 100644 --- a/lib/Object/Remote/Connector/Local.pm +++ b/lib/Object/Remote/Connector/Local.pm @@ -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 index 0000000..c9193d0 --- /dev/null +++ b/lib/Object/Remote/Connector/SSH.pm @@ -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; diff --git a/lib/Object/Remote/Connector/STDIO.pm b/lib/Object/Remote/Connector/STDIO.pm index 49cb0f9..adca748 100644 --- a/lib/Object/Remote/Connector/STDIO.pm +++ b/lib/Object/Remote/Connector/STDIO.pm @@ -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 index 0000000..9c7ac7b --- /dev/null +++ b/lib/Object/Remote/Role/Connector.pm @@ -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 index 0000000..f137ac9 --- /dev/null +++ b/maint/mk-fat @@ -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 $/; }; +1; +__DATA__ +'; + fatpack file; + cat bin/object-remote-node +)>lib/Object/Remote/FatNode.pm +rm -r fatlib