Iniitial RCP support (from theorbtwo) tcpip_support
Jess Robinson [Tue, 16 Oct 2012 12:30:44 +0000 (13:30 +0100)]
lib/Object/Remote/Connector/TCP.pm [new file with mode: 0755]

diff --git a/lib/Object/Remote/Connector/TCP.pm b/lib/Object/Remote/Connector/TCP.pm
new file mode 100755 (executable)
index 0000000..5376da6
--- /dev/null
@@ -0,0 +1,33 @@
+package Object::Remote::Connector::TCP;
+
+use IO::Socket::INET;
+use Moo;
+
+with 'Object::Remote::Role::Connector';
+
+has host => (is => 'ro', required => 1);
+has port => (is => 'ro', required => 1);
+has sock => (is => 'rw');
+
+{
+  no warnings 'once';
+  
+  push @Object::Remote::Connection::Guess, sub {
+    for ($_[0]) {
+      # FIXME: Use Regexp::Common regex for a hostname, or check this against spec.
+      print STDERR "tcp guess for $_\n";
+      if (defined and !ref and m!^tcp://([a-z0-9.]+):(\d+)/!i) {
+       return __PACKAGE__->new(host => $1, port => $2);
+      }
+    }
+    return;
+  };
+}
+
+sub _open2_for {
+  my ($self) = @_;
+  my $sock = IO::Socket::INET->new(PeerHost => $self->host, PeerPort => $self->port)
+    or die "Couldn't open connection: $!";
+  
+  ($sock, $sock, undef);
+}