From f5b06133f50be80c0d4bd144df4bdb1f8d5ba1ee Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 9 Mar 2010 23:05:21 +0000 Subject: [PATCH] Don't use a separate argument for Domain, but still load it on demand. --- perl/lib/Net/REPL/Base.pm | 13 +++++++++---- perl/lib/Net/REPL/Client.pm | 10 ++++------ perl/lib/Net/REPL/Server.pm | 10 ++++------ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/perl/lib/Net/REPL/Base.pm b/perl/lib/Net/REPL/Base.pm index b4e1189..57ede17 100644 --- a/perl/lib/Net/REPL/Base.pm +++ b/perl/lib/Net/REPL/Base.pm @@ -22,6 +22,7 @@ length with the value as a bytestring. =cut use Data::Dumper; +use IO::Socket; =head3 lv_receive() @@ -120,12 +121,16 @@ sub formatted_eval { sub _create_socket { my ($self, %socket_args) = @_; - if (not $self->{'socket_class'}) { - die('socket_class argument is mandatory'); + my $domain = $socket_args{'Domain'}; + if (not defined($domain)) { + die('Socket "Domain" argument is mandatory'); } - eval "use $self->{'socket_class'};"; - return $self->{'socket_class'}->new( + my $pkg = $IO::Socket::domain2pkg[$domain]; + if (defined($pkg)) { + eval("use $pkg;"); + } + return IO::Socket->new( %socket_args, ); } diff --git a/perl/lib/Net/REPL/Client.pm b/perl/lib/Net/REPL/Client.pm index 2e35484..cad37ed 100644 --- a/perl/lib/Net/REPL/Client.pm +++ b/perl/lib/Net/REPL/Client.pm @@ -24,6 +24,7 @@ provide additional capabilities. use base qw(Net::REPL::Base); +use Socket qw(AF_UNIX); use Term::ReadLine; =head3 new(argument => value...) @@ -32,13 +33,10 @@ Arguments: =over -=item C - -E.g. L (the default) or L. - =item C -Hashref of arguments for the socket class. +Hashref of arguments for L configuration. Use C to +select a socket class. =item C @@ -52,7 +50,6 @@ sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = { - 'socket_class' => 'IO::Socket::UNIX', 'socket_args' => {}, 'prompt' => '', @_, @@ -60,6 +57,7 @@ sub new { bless($self, $class); my $client = $self->_create_socket( + 'Domain' => AF_UNIX, 'Proto' => 'SOCK_STREAM', %{$self->{'socket_args'}}, ); diff --git a/perl/lib/Net/REPL/Server.pm b/perl/lib/Net/REPL/Server.pm index ec61fb7..df176fe 100644 --- a/perl/lib/Net/REPL/Server.pm +++ b/perl/lib/Net/REPL/Server.pm @@ -26,6 +26,7 @@ exchanged bidirectionally. use base qw(Net::REPL::Base); use Data::Dumper; +use Socket qw(AF_UNIX); =head3 new(argument => value...) @@ -33,13 +34,10 @@ Arguments: =over -=item C - -E.g. L (the default) or L. - =item C -Hashref of arguments for the socket class. +Hashref of arguments for L configuration. Use C to +select a socket class. =item C @@ -53,7 +51,6 @@ sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = { - 'socket_class' => 'IO::Socket::UNIX', 'socket_args' => {}, @_, }; @@ -62,6 +59,7 @@ sub new { $self->debug('Server starting:', Dumper($self->{'socket_args'})); my $server = $self->_create_socket( + 'Domain' => AF_UNIX, 'Proto' => 'SOCK_STREAM', 'Reuse' => 1, 'Listen' => 1, -- 2.11.4.GIT