further detail OR->connect arguments, and document other bits
[scpubgit/Object-Remote.git] / lib / Object / Remote / Connector / INET.pm
1 package Object::Remote::Connector::INET;
2
3 use IO::Socket::INET;
4 use Moo;
5
6 with 'Object::Remote::Role::Connector';
7
8 has socket_path => (is => 'ro', required => 1);
9
10 sub _open2_for {
11   my ($self) = @_;
12   my $path = $self->socket_path;
13   my $sock = IO::Socket::INET->new($path)
14     or die "Couldn't open socket ${path}: $!";
15   ($sock, $sock, undef);
16 }
17
18 no warnings 'once';
19
20 push @Object::Remote::Connection::Guess, sub {
21   for ($_[0]) {
22     if (defined and !ref and /^.+:\d+$/) {
23       my $socket = shift(@_);
24       return __PACKAGE__->new(@_, socket_path => $socket);
25     }
26   }
27   return;
28 };
29
30 1;
31
32 =head1 NAME
33
34 Object::Remote::Connector::INET - A connector for INET sockets
35
36 =head1 DESCRIPTION
37
38 Used to create a connector that talks to an INET socket. Invoked by
39 L<Object::Remote/connect> if the connection spec is in C<host:port> format.
40
41 =head1 ARGUMENTS
42
43 Inherits arguments from L<Object::Remote::Role::Connector> and provides the
44 following:
45
46 =head2 socket_path
47
48 When invoked via L<Object::Remote/connect>, specified via the connection spec,
49 and not overridable.
50
51 The remote address to connect to. Expected to be understandable by
52 L<IO::Socket::INET> for its C<PeerAddr> argument.
53
54 =cut