Subject: | Capture::Tiny::capture() stomps on $@ set by enclosed eval() on MSWin32 |
Please see attached demo script with console sessions.
Subject: | capture-eval-die.pl |
#!/usr/bin/perl
# $Id: capture-eval-die.pl,v 1.4 2011-01-26 05:15:08 dpchrist Exp $
# by David Paul Christensen dpchrist@holgerdanske.com
use strict;
use warnings;
use Carp;
use Capture::Tiny qw( capture );
use Data::Dumper;
use Log::Log4perl qw( :easy );
Log::Log4perl->easy_init($DEBUG);
$Data::Dumper::Sortkeys = 1;
$| = 1;
my ($stdout, $stderr);
print "### calling capture\n";
($stdout, $stderr) = capture {
print __FILE__, __LINE__;
print STDERR __FILE__, __LINE__;
};
print join ' ', __FILE__, __LINE__,
Data::Dumper->Dump([$stdout, $stderr], [qw(stdout stderr)]);
print "### calling eval - die\n";
eval {
die __FILE__, __LINE__;
};
print Data::Dumper->Dump([$@], [qw(@)]);
print "### calling capture - eval - die\n";
($stdout, $stderr) = capture {
eval {
die __FILE__, __LINE__;
};
print Data::Dumper->Dump([$@], [qw(@)]);
};
print Data::Dumper->Dump([$stdout, $stderr, $@], [qw(stdout stderr @)]);
__END__
### console session on Debian GNU/Linux showing correct operation:
2011-01-25 20:58:02 dpchrist@p43400e ~/sandbox
$ cat /etc/debian_version
5.0.8
2011-01-25 20:58:28 dpchrist@p43400e ~/sandbox
$ perl -v
This is perl, v5.10.0 built for i486-linux-gnu-thread-multi
Copyright 1987-2007, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
2011-01-25 20:58:52 dpchrist@p43400e ~/sandbox
$ perl -MCapture::Tiny -e 'print $Capture::Tiny::VERSION, "\n"'
0.06
2011-01-25 20:59:26 dpchrist@p43400e ~/sandbox
$ perl capture-eval-die.pl
### calling capture
capture-eval-die.pl 18 $stdout = 'capture-eval-die.pl15';
$stderr = 'capture-eval-die.pl16';
### calling eval - die
$@ = 'capture-eval-die.pl23 at capture-eval-die.pl line 23.
';
### calling capture - eval - die
$stdout = '$@ = \'capture-eval-die.pl30 at capture-eval-die.pl line 30.
\';
';
$stderr = '';
$@ = 'capture-eval-die.pl30 at capture-eval-die.pl line 30.
';
### console session on Windows XP showing incorrect operation --
### Capture::Tiny::capture() stomps on $@ set by enclosed eval():
C:\Documents and Settings\Administrator\My Documents\sandbox>ver
Microsoft Windows XP [Version 5.1.2600]
C:\Documents and Settings\Administrator\My Documents\sandbox>perl -v
This is perl, v5.10.1 (*) built for MSWin32-x86-multi-thread
Copyright 1987-2009, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
C:\Documents and Settings\Administrator\My Documents\sandbox>perl -MCapture::Tin
y -e "print $Capture::Tiny::VERSION"
0.08
C:\Documents and Settings\Administrator\My Documents\sandbox>perl capture-eval-d
ie.pl
### calling capture
capture-eval-die.pl 18 $stdout = 'capture-eval-die.pl15';
$stderr = 'capture-eval-die.pl16';
### calling eval - die
$@ = 'capture-eval-die.pl23 at capture-eval-die.pl line 23.
';
### calling capture - eval - die
$stdout = '$@ = \'capture-eval-die.pl30 at capture-eval-die.pl line 30.
\';
';
$stderr = '';
$@ = '';