#!./perl
-print "1..30\n";
+print "1..37\n";
eval 'print "ok 1\n";';
my $x = 25;
eval <<'EOT'; die if $@;
- sub do_eval {
+ print "# $x\n"; # clone into eval's pad
+ sub do_eval1 {
eval $_[0]; die if $@;
}
EOT
-do_eval('print "ok $x\n"');
+do_eval1('print "ok $x\n"');
$x++;
-do_eval('eval q[print "ok $x\n"]');
+do_eval1('eval q[print "ok $x\n"]');
$x++;
-do_eval('sub { eval q[print "ok $x\n"] }->()');
+do_eval1('sub { eval q[print "ok $x\n"] }->()');
+$x++;
+
+# calls from within eval'' should clone outer lexicals
+
+eval <<'EOT'; die if $@;
+ sub do_eval2 {
+ eval $_[0]; die if $@;
+ }
+do_eval2('print "ok $x\n"');
+$x++;
+do_eval2('eval q[print "ok $x\n"]');
+$x++;
+do_eval2('sub { eval q[print "ok $x\n"] }->()');
+$x++;
+EOT
+
+# calls outside eval'' should NOT clone lexicals from called context
+
+$main::x = 'ok';
+eval <<'EOT'; die if $@;
+ # $x unbound here
+ sub do_eval3 {
+ eval $_[0]; die if $@;
+ }
+EOT
+do_eval3('print "$x ' . $x . '\n"');
+$x++;
+do_eval3('eval q[print "$x ' . $x . '\n"]');
+$x++;
+do_eval3('sub { eval q[print "$x ' . $x . '\n"] }->()');
$x++;
# can recursive subroutine-call inside eval'' see its own lexicals?
}
$x++;
+# Have we cured panic which occurred with require/eval in die handler ?
+$SIG{__DIE__} = sub { eval {1}; die shift };
+eval { die "ok ".$x++,"\n" };
+print $@;
+