From: Jesse Luehrs Date: Tue, 2 Aug 2011 04:43:45 +0000 (-0500) Subject: stop compiling stuff in the Eval::Closure package directly X-Git-Tag: 0.07~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FEval-Closure.git;a=commitdiff_plain;h=a0e934a667e05d3a8b5556e257938472cd9d6243 stop compiling stuff in the Eval::Closure package directly --- diff --git a/lib/Eval/Closure.pm b/lib/Eval/Closure.pm index 787754c..45c36b6 100644 --- a/lib/Eval/Closure.pm +++ b/lib/Eval/Closure.pm @@ -202,7 +202,11 @@ sub _clean_eval_closure { unless (exists $compiler_cache{$source}) { local $@; local $SIG{__DIE__}; - my $compiler = eval $source; + my $compiler = do { + package # hide from PAUSE + Eval::Closure::Sandbox; + eval $source; + }; my $e = $@; $compiler_cache{$source} = [ $compiler, $e ]; } diff --git a/t/compiling-package.t b/t/compiling-package.t new file mode 100644 index 0000000..5c3764f --- /dev/null +++ b/t/compiling-package.t @@ -0,0 +1,17 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +use Eval::Closure; + +my $code = eval_closure( + source => 'no strict "refs"; sub { keys %{__PACKAGE__ . "::"} }', +); + +# defining the sub { } creates __ANON__, calling 'no strict' creates BEGIN +my @stash_keys = grep { $_ ne '__ANON__' && $_ ne 'BEGIN' } $code->(); + +is_deeply([@stash_keys], [], "compiled in an empty package"); + +done_testing;