From 41f767bb6fa8f33b2f4ace0b909969dbcbbc37d5 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 8 Jun 2013 14:13:31 -0500 Subject: allow multiple independent lexical environments --- lib/Reply/Plugin/Defaults.pm | 9 +++++++++ lib/Reply/Plugin/ResultCache.pm | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Reply/Plugin/Defaults.pm b/lib/Reply/Plugin/Defaults.pm index b0c4e88..debed09 100644 --- a/lib/Reply/Plugin/Defaults.pm +++ b/lib/Reply/Plugin/Defaults.pm @@ -38,6 +38,15 @@ sub compile { my $self = shift; my ($next, $line, %args) = @_; + my @envs = ( + ($args{environment} ? ($args{environment}) : ()), + values %{ $args{environments} }, + ); + + if (@envs) { + $args{environment} = { map { %$_ } @envs } + } + return eval_closure( source => "sub {\n$PREFIX;\n$line\n}", terse_error => 1, diff --git a/lib/Reply/Plugin/ResultCache.pm b/lib/Reply/Plugin/ResultCache.pm index a973d05..91fda37 100644 --- a/lib/Reply/Plugin/ResultCache.pm +++ b/lib/Reply/Plugin/ResultCache.pm @@ -36,8 +36,9 @@ sub compile { my $self = shift; my ($next, $line, %args) = @_; - $args{environment} ||= {}; - $args{environment}{'@' . $self->{result_name}} = $self->{results}; + $args{environments}{''.__PACKAGE__} = { + "\@$self->{result_name}" => $self->{results}, + }; $next->($line, %args); } -- cgit v1.2.3-54-g00ecf