Subject: | Warn does not work for Perl 5.6.2 |
IO::Capture::Stderr isn't capturing warn and Carp on Perl 5.6.2 platforms.
Run the following on a Perl56 system and it doesn't work, it does work
on a Perl58 system.
#!/usr/bin/perl
use strict;
use Carp;
use IO::Capture::Stderr;
my $force = shift;
my $capture;
if ($force) {
$capture = IO::Capture::Stderr->new( {FORCE_CAPTURE_WARN => 1} );
}
else {
$capture = IO::Capture::Stderr->new( );
}
# Put this back and it does work in Perl56
#$SIG{__WARN__} = sub {print STDERR @_;} ;
print "This is Perl Version : $]\n";
print "IO::Capturer Version : $IO::Capture::VERSION\n";
print "FORCE_CAPTURE_WARN : $capture->{'FORCE_CAPTURE_WARN'}\n";
print "\$SIG{__WARN__} : $SIG{__WARN__}\n";
print "_capture_warn_check(): " . $capture->_capture_warn_check() . "\n";
print "\nTesting print STDERR...\n";
$capture->start();
print STDERR 'Foo';
$capture->stop();
my $line=$capture->read();
if ($line eq 'Foo') {
print "Captured STDERR Foo\n";
}
else {
print "Failed to capture STDERR Foo\n";
print "Captured output was >$line<\n";
}print "\nTesting warn...\n";
$capture->start();
warn('Foo');
$capture->stop();
$line=$capture->read();
if ($line =~ 'Foo') {
print "Captured warn Foo\n";
}
else {
print "Failed to capture warn Foo\n";
print "Captured output was >$line<\n";
}
print "\nTesting Carp...\n";
$capture->start();
carp('Foo');
$capture->stop();
$line=$capture->read();
if ($line =~ 'Foo') {
print "Captured carp Foo\n";
}
else {
print "Failed to capture carp Foo\n";
print "Captured output was >$line<\n";
}
print "Done.\n";
You will see that if you manually fiddle with the warn signal then it
does work as described. I don't know what's going wrong, the
_capture_warn_check doesn't appear to be detecting Perl56 correctly
either. Even manually setting FORCE_CAPTURE_WARN doesn't seem to help.
Your code looks simple enough, I can't see why it doesn't work.