Skip Menu |

This queue is for tickets about the IO-Socket-IP CPAN distribution.

Report information
The Basics
Id: 101456
Status: resolved
Priority: 0/
Queue: IO-Socket-IP

People
Owner: Nobody in particular
Requestors: TEAM [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.36
Fixed in: 0.37



Subject: Enforce scalar return on ->peerhost/->peerport
At the moment, peerhost and peerport can return empty lists. Being able to rely on them always returning a single scalar (i.e. undef rather than () if there's no current value) would simplify some calling code. From a casual glance at the current implementation, it would be quite easy to assume that scalar context is already enforced: sub peerhost { my $self = shift; ( $self->_get_host_service( $self->peername, NI_NUMERICHOST, NIx_NOSERV ) )[0] } sub peerport { my $self = shift; ( $self->_get_host_service( $self->peername, NI_NUMERICSERV, NIx_NOHOST ) )[1] } which of course isn't the case, since _get_host_service could be returning an empty list. At the moment, you can't use them in a hash or as fixed-position sub parameters: my %details = ( host => $sock->peerhost, port => $sock->peerport, ... ); => could end up as { host => 'port' } cheers, Tom
Fixed -- Paul Evans
Subject: rt101456.patch
=== modified file 'lib/IO/Socket/IP.pm' --- lib/IO/Socket/IP.pm 2015-01-10 21:04:10 +0000 +++ lib/IO/Socket/IP.pm 2015-01-11 16:30:55 +0000 @@ -820,11 +820,11 @@ =cut -sub sockhost { my $self = shift; ( $self->_get_host_service( $self->sockname, NI_NUMERICHOST, NIx_NOSERV ) )[0] } -sub sockport { my $self = shift; ( $self->_get_host_service( $self->sockname, NI_NUMERICSERV, NIx_NOHOST ) )[1] } +sub sockhost { my $self = shift; scalar +( $self->_get_host_service( $self->sockname, NI_NUMERICHOST, NIx_NOSERV ) )[0] } +sub sockport { my $self = shift; scalar +( $self->_get_host_service( $self->sockname, NI_NUMERICSERV, NIx_NOHOST ) )[1] } -sub sockhostname { my $self = shift; ( $self->_get_host_service( $self->sockname, 0, NIx_NOSERV ) )[0] } -sub sockservice { my $self = shift; ( $self->_get_host_service( $self->sockname, 0, NIx_NOHOST ) )[1] } +sub sockhostname { my $self = shift; scalar +( $self->_get_host_service( $self->sockname, 0, NIx_NOSERV ) )[0] } +sub sockservice { my $self = shift; scalar +( $self->_get_host_service( $self->sockname, 0, NIx_NOHOST ) )[1] } =head2 $addr = $sock->sockaddr @@ -873,11 +873,11 @@ =cut -sub peerhost { my $self = shift; ( $self->_get_host_service( $self->peername, NI_NUMERICHOST, NIx_NOSERV ) )[0] } -sub peerport { my $self = shift; ( $self->_get_host_service( $self->peername, NI_NUMERICSERV, NIx_NOHOST ) )[1] } +sub peerhost { my $self = shift; scalar +( $self->_get_host_service( $self->peername, NI_NUMERICHOST, NIx_NOSERV ) )[0] } +sub peerport { my $self = shift; scalar +( $self->_get_host_service( $self->peername, NI_NUMERICSERV, NIx_NOHOST ) )[1] } -sub peerhostname { my $self = shift; ( $self->_get_host_service( $self->peername, 0, NIx_NOSERV ) )[0] } -sub peerservice { my $self = shift; ( $self->_get_host_service( $self->peername, 0, NIx_NOHOST ) )[1] } +sub peerhostname { my $self = shift; scalar +( $self->_get_host_service( $self->peername, 0, NIx_NOSERV ) )[0] } +sub peerservice { my $self = shift; scalar +( $self->_get_host_service( $self->peername, 0, NIx_NOHOST ) )[1] } =head2 $addr = $peer->peeraddr === modified file 't/02local-server-v4.t' --- t/02local-server-v4.t 2015-01-02 19:39:50 +0000 +++ t/02local-server-v4.t 2015-01-11 16:30:55 +0000 @@ -43,6 +43,10 @@ ok( eval { $testserver->peerport; 1 }, "\$testserver->peerport does not die for $socktype" ) or do { chomp( my $e = $@ ); diag( "Exception was: $e" ) }; + is_deeply( { host => $testserver->peerhost, port => $testserver->peerport }, + { host => undef, port => undef }, + 'peerhost/peersock yield scalar' ); + my $socket = IO::Socket::INET->new( PeerHost => "127.0.0.1", PeerPort => $testserver->sockport,
Released in 0.37 -- Paul Evans