Subject: | Using Socket::Class breaks $! globally |
It seems that using Socket::Class breaks $! globally in a running Perl
program.
When $! or %! is used in a numeric/boolean/string context, it doesn't
behave properly while a Socket::Class object is active.
The value of $! is undef while it should contain the errno in numeric,
the error string in string context.
(Note, by trying to assign the value of $! to a variable, the proper $!
value can be extracted and thereafter $! works as expected).
Subject: | errno.t |
use strict;
use warnings;
use Socket::Class;
my $fn = 'nonexistent.file';
try_open($fn);
my $client = Socket::Class->new(
'remote_addr' => 'www.google.com',
'remote_port' => '80',
) or die Socket::Class->error;
try_open($fn);
sub try_open {
my $filename = shift;
if (!open(my $file, '<', $filename)) {
if ($! && $!{ENOENT}) {
print "I think it's no such file or dir...\n";
} else {
print "Some other error: $!\n";
my $error = $!;
print "Some other error now made visible: '$!' (error = '$error')\n";
}
}
}