From: Jess Robinson Date: Tue, 16 Oct 2012 12:30:44 +0000 (+0100) Subject: Iniitial RCP support (from theorbtwo) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=295d53e414a4c8b0bd8149b520a67ae55c512e61;p=scpubgit%2FObject-Remote.git Iniitial RCP support (from theorbtwo) --- diff --git a/lib/Object/Remote/Connector/TCP.pm b/lib/Object/Remote/Connector/TCP.pm new file mode 100755 index 0000000..5376da6 --- /dev/null +++ b/lib/Object/Remote/Connector/TCP.pm @@ -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); +}