This queue is for tickets about the Net-Ping CPAN distribution.

Report information
The Basics
Id:
134332
Status:
open
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
dd-b [...] dd-b.net
Cc:
AdminCc:

BugTracker
Severity:
(no value)
Broken in:
(no value)
Fixed in:
(no value)



Subject: Hash params to new largely don't work
Date: Thu, 4 Feb 2021 12:24:38 -0500
To: bug-Net-Ping@rt.cpan.org
From: David Dyer-Bennet <dd-b@dd-b.net>
I'll use timeout as the example, but it applies to quite a few others as well; that's just the one I encountered it on.

I'm on Ubuntu 20.04.2, perl 05.30.0, Net::Ping version 2.71 (seen in Ping.pm) (perl and Net::Ping installed with default Ubuntu packages). 

Simple example:

$ cat t004.pl
#!/usr/bin/env perl

use strict;
use warnings;
use Data::Dumper;
use Net::Ping;

# Like tcp protocol, but with many hosts
my $p = Net::Ping->new({
    proto => "syn",
    timeout => 2,     # but dumping $p shows 5??
});
print "p ", Dumper ($p), "\n";

$ ./t004.pl
p $VAR1 = bless( {
                 'wbits' => '',
                 'syn' => {},
                 'port_num' => 7,
                 'data' => '',
                 'device' => undef,
                 'family' => 2,
                 'tos' => undef,
                 'econnrefused' => undef,
                 'stop_time' => 0,
                 'retrans' => '1.2',
                 'data_size' => 0,
                 'local_addr' => undef,
                 'seq' => 0,
                 'proto' => 'syn',
                 'timeout' => 5,
                 'proto_num' => 6,
                 'bad' => {}
               }, 'Net::Ping' );

Note that timeout is 5 in the Dumper output when t004.pl is run, although it was initialized to 2 in the hash passed to Net::Ping->new().

The reason this happens is that the code for new() in Ping.pm first checks if $proto is a hashref, and if it is moves the possible parameters out of it into $self (lines 110-129).

Then it goes through and applies default values to the parameter variables if they are not set; $timeout is set at line 135. $timeout will not be set in the case where the parameters were passed in as a hashref, so line 135 will set $timeout to $def_timeout (which is 5).

Line 138 is:

Show quoted text

  $self->{timeout} = $timeout;

And that will overwrite the value copied into $self from $proto up in lines 110-129.

Bunch of obvious ways to fix this. Same thing would appear to happen to $device and $tos just after line 138, and probably others elsewhere. It looks like the change to allow a hashref to be passed in with all the named parameters didn't adequately deal with how defaults were handled later in the code.


-- 
David Dyer-Bennet, dd-b@dd-b.net; http://dd-b.net/
Words Over Windows: http://WordsOverWindows.dd-b.net/
Oops, will investigate. Can you please file that again over at my GitHub? https://github.com/rurban/Net-Ping/issues This here is dead soon -- Reini Urban
Subject: Re: [rt.cpan.org #134332] Hash params to new largely don't work
Date: Thu, 4 Feb 2021 16:38:10 -0500
To: bug-Net-Ping@rt.cpan.org
From: David Dyer-Bennet <dd-b@dd-b.net>
On 2/4/21 2:34 PM, Reini Urban via RT wrote:
Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=134332 > > > Oops, will investigate.
Thanks!
Show quoted text
> Can you please file that again over at my GitHub? > > https://github.com/rurban/Net-Ping/issues
Will do!
Show quoted text
> This here is dead soon
Glad to see the maintainer responding promptly! -- David Dyer-Bennet, dd-b@dd-b.net; http://dd-b.net/ Words Over Windows: http://WordsOverWindows.dd-b.net/
Subject: Re: [rt.cpan.org #134332] Hash params to new largely don't work
Date: Thu, 4 Feb 2021 16:44:25 -0500
To: bug-Net-Ping@rt.cpan.org
From: David Dyer-Bennet <dd-b@dd-b.net>
On 2/4/21 2:34 PM, Reini Urban via RT wrote:
Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=134332 > > > Oops, will investigate. > Can you please file that again over at my GitHub? > > https://github.com/rurban/Net-Ping/issues
Done, issue #26 there -- David Dyer-Bennet, dd-b@dd-b.net; http://dd-b.net/ Words Over Windows: http://WordsOverWindows.dd-b.net/


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.