diff options
Diffstat (limited to 'lib/Eval/Closure.pm')
-rw-r--r-- | lib/Eval/Closure.pm | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/Eval/Closure.pm b/lib/Eval/Closure.pm index 74b64a4..a610194 100644 --- a/lib/Eval/Closure.pm +++ b/lib/Eval/Closure.pm @@ -9,7 +9,6 @@ use Sub::Exporter -setup => { use Carp; use overload (); -use Memoize; use Scalar::Util qw(reftype); use Try::Tiny; @@ -193,14 +192,23 @@ sub _clean_eval_closure { return ($code, $e); } -sub _make_compiler { - local $@; - local $SIG{__DIE__}; - my $compiler = eval _make_compiler_source(@_); - my $e = $@; - return ($compiler, $e); +{ + my %compiler_cache; + + sub _make_compiler { + my $source = _make_compiler_source(@_); + + unless (exists $compiler_cache{$source}) { + local $@; + local $SIG{__DIE__}; + my $compiler = eval $source; + my $e = $@; + $compiler_cache{$source} = [ $compiler, $e ]; + } + + return @{ $compiler_cache{$source} }; + } } -memoize('_make_compiler'); sub _make_compiler_source { my ($source, @capture_keys) = @_; |