Since C<warnif> can make C library or system calls, C<warnif> can clobber C<errno> and thus C<$!>.
Please replace
error:
unless (defined wantarray) {
$connect_void_warned++ or
warnings::warnif($self, "Calling connect in void context is deprecated");
croak "Net::SSH2: failed to connect to $_[0]:$_[1]: $!"
}
return;
with
error:
unless (defined wantarray) {
my $errno = $!;
$connect_void_warned++ or
warnings::warnif($self, "Calling connect in void context is deprecated");
croak "Net::SSH2: failed to connect to $_[0]:$_[1]: $errno"
}
return;
or better yet with
error:
unless (defined wantarray) {
my $errno = $!;
$connect_void_warned++ or
warnings::warnif($self, "Calling connect in void context is deprecated");
$self->die_with_error();
}
return;