| 1 | package Object::Remote::Connector::UNIX; | ||
| 2 | |||
| 3 | use IO::Socket::UNIX; | ||
| 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::UNIX->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 /^(?:\.\/|\/)/) { | ||
| 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::UNIX - Connect to an Object::Remote server over a Unix socket | ||
| 35 | |||
| 36 | =head1 SYNOPSIS | ||
| 37 | |||
| 38 | use Object::Remote; | ||
| 39 | |||
| 40 | my $remote = Object::Remote->connect('/tmp/object-remote.sock'); | ||
| 41 | |||
| 42 | =head1 DESCRIPTION | ||
| 43 | |||
| 44 | C<Object::Remote::Connector::UNIX> provides the client-side connector for | ||
| 45 | connecting to an L<Object::Remote::ConnectionServer> instance over a Unix | ||
| 46 | domain socket. | ||
| 47 | |||
| 48 | It is selected automatically when the connection target looks like a Unix | ||
| 49 | socket path, such as one beginning with C</> or C<./>. | ||
| 50 | |||
| 51 | =head1 METHODS | ||
| 52 | |||
| 53 | This class is an internal connector implementation and does not provide a | ||
| 54 | public API beyond what is consumed by L<Object::Remote>. | ||
| 55 | |||
| 56 | =head1 SEE ALSO | ||
| 57 | |||
| 58 | L<Object::Remote>, L<Object::Remote::ConnectionServer>, L<IO::Socket::UNIX> | ||
| 59 | |||
| 60 | =cut |