$c->on_close(sub { $loop->stop });
+print { $c->send_to_fh } "Shere\n";
+
$loop->run;
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 { {} });
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;
--- /dev/null
+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;
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
);
--- /dev/null
+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;
--- /dev/null
+#!/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