summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-08-02 01:10:22 -0500
committerJesse Luehrs <doy@tozt.net>2011-08-02 01:44:09 -0500
commit794dc9df98d2aaf2f143f32ac7dfa42fa46ce07e (patch)
treeb69e18746bb51909368fa7679de263031c3e18d7 /t
parent0fb2ea464c6eb6c52831d44ef541a0d4d5c95a92 (diff)
downloadeval-closure-794dc9df98d2aaf2f143f32ac7dfa42fa46ce07e.tar.gz
eval-closure-794dc9df98d2aaf2f143f32ac7dfa42fa46ce07e.zip
compile each thing in a separate package, to avoid leakage
Diffstat (limited to 't')
-rw-r--r--t/compiling-package.t29
1 files changed, 23 insertions, 6 deletions
diff --git a/t/compiling-package.t b/t/compiling-package.t
index 5c3764f..09b4d0b 100644
--- a/t/compiling-package.t
+++ b/t/compiling-package.t
@@ -5,13 +5,30 @@ use Test::More;
use Eval::Closure;
-my $code = eval_closure(
- source => 'no strict "refs"; sub { keys %{__PACKAGE__ . "::"} }',
-);
+{
+ 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->();
+ # 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");
+ is_deeply([@stash_keys], [], "compiled in an empty package");
+}
+
+{
+ # the more common case where you'd run into this is imported subs
+ # for instance, Bread::Board::as vs Moose::Util::TypeConstraints::as
+ my $c1 = eval_closure(
+ source => 'no strict "vars"; sub { ++$foo }',
+ );
+ my $c2 = eval_closure(
+ source => 'no strict "vars"; sub { --$foo }',
+ );
+ is($c1->(), 1);
+ is($c1->(), 2);
+ is($c2->(), -1);
+ is($c2->(), -2);
+}
done_testing;