sub _make_compiler {
my $source = _make_compiler_source(@_);
+ my @caller = caller(2); # XXX make sure this stays in sync
- return @{ _clean_eval($source) };
+ return @{ _clean_eval($source, $caller[8]) };
}
$Eval::Closure::SANDBOX_ID = 0;
package Eval::Closure::Sandbox_$Eval::Closure::SANDBOX_ID;
local \$@;
local \$SIG{__DIE__};
+BEGIN { \$^H = $_[1] }
my \$compiler = eval \$_[0];
my \$e = \$@;
[ \$compiler, \$e ];
my $foo = [1, 2, 3];
my $code = eval_closure(
- # not sure if strict leaking into evals is intended, i think i remember
- # it being changed in newer perls
source => 'do { no strict; sub { $foo } }',
);
--- /dev/null
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Fatal;
+
+use Eval::Closure;
+
+{
+ my $source = 'sub { ++$foo }';
+
+ {
+ like(
+ exception {
+ eval_closure(source => $source);
+ },
+ qr/Global symbol "\$foo/,
+ "errors with strict enabled"
+ );
+ }
+
+ {
+ no strict;
+ my $c1;
+ is(
+ exception {
+ $c1 = eval_closure(source => $source);
+ },
+ undef,
+ "no errors with no strict"
+ );
+ is($c1->(), 1);
+ is($c1->(), 2);
+ }
+}
+
+{
+ my $source = 'our $less; BEGIN { $less = $^H{less} } sub { $less }';
+
+ {
+ my $c1 = eval_closure(source => $source);
+ is($c1->(), undef, "nothing in the hint hash");
+ }
+
+ {
+ local $TODO = 'not sure how exactly to get %^H copied';
+ use less "stuff";
+ my $c1 = eval_closure(source => $source);
+ is($c1->(), 'stuff', "use less put stuff in the hints hash");
+ }
+}
+
+done_testing;