but... that breaks memoization, so disable that for now
[gitmo/Eval-Closure.git] / t / compiling-package.t
CommitLineData
a0e934a6 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5
6use Eval::Closure;
7
794dc9df 8{
9 my $code = eval_closure(
10 source => 'no strict "refs"; sub { keys %{__PACKAGE__ . "::"} }',
11 );
a0e934a6 12
794dc9df 13 # defining the sub { } creates __ANON__, calling 'no strict' creates BEGIN
14 my @stash_keys = grep { $_ ne '__ANON__' && $_ ne 'BEGIN' } $code->();
a0e934a6 15
794dc9df 16 is_deeply([@stash_keys], [], "compiled in an empty package");
17}
18
19{
20 # the more common case where you'd run into this is imported subs
21 # for instance, Bread::Board::as vs Moose::Util::TypeConstraints::as
22 my $c1 = eval_closure(
23 source => 'no strict "vars"; sub { ++$foo }',
24 );
25 my $c2 = eval_closure(
26 source => 'no strict "vars"; sub { --$foo }',
27 );
28 is($c1->(), 1);
29 is($c1->(), 2);
30 is($c2->(), -1);
31 is($c2->(), -2);
32}
a0e934a6 33
fa287851 34{
35 my $source = 'no strict "vars"; sub { ++$foo }';
36 my $c1 = eval_closure(source => $source);
37 my $c2 = eval_closure(source => $source);
38 is($c1->(), 1);
39 is($c1->(), 2);
40 is($c2->(), 1);
41 is($c2->(), 2);
42}
43
a0e934a6 44done_testing;