summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-06-26 13:52:02 -0400
committerJesse Luehrs <doy@tozt.net>2013-06-26 13:52:02 -0400
commit68371e78f12feffce4151d6fd9434c3ca46700bd (patch)
tree73c94f3e0ca365133be1b07974c067ae400bc4e3
parente3b56981b944b01084a51d5fc150ad596dd4a2fa (diff)
downloadreply-68371e78f12feffce4151d6fd9434c3ca46700bd.tar.gz
reply-68371e78f12feffce4151d6fd9434c3ca46700bd.zip
turn setting the current package into a parameter
-rw-r--r--lib/Reply/Plugin/Defaults.pm6
-rw-r--r--lib/Reply/Plugin/Packages.pm13
2 files changed, 10 insertions, 9 deletions
diff --git a/lib/Reply/Plugin/Defaults.pm b/lib/Reply/Plugin/Defaults.pm
index debed09..f1813fb 100644
--- a/lib/Reply/Plugin/Defaults.pm
+++ b/lib/Reply/Plugin/Defaults.pm
@@ -26,7 +26,6 @@ sub read_line {
}
(my $PREFIX = <<'PREFIX') =~ s/__PACKAGE__/__PACKAGE__/ge;
-package main;
BEGIN {
$^H = $__PACKAGE__::default_hints;
%^H = %$__PACKAGE__::default_hinthash;
@@ -47,8 +46,11 @@ sub compile {
$args{environment} = { map { %$_ } @envs }
}
+ my $package = delete $args{package} || 'main';
+ my $prefix = "package $package;\n$PREFIX";
+
return eval_closure(
- source => "sub {\n$PREFIX;\n$line\n}",
+ source => "sub {\n$prefix;\n$line\n}",
terse_error => 1,
%args,
);
diff --git a/lib/Reply/Plugin/Packages.pm b/lib/Reply/Plugin/Packages.pm
index eb69f96..d6fad68 100644
--- a/lib/Reply/Plugin/Packages.pm
+++ b/lib/Reply/Plugin/Packages.pm
@@ -36,7 +36,6 @@ sub mangle_line {
my $package = __PACKAGE__;
return <<LINE;
-package $self->{package};
$line
;
BEGIN {
@@ -47,16 +46,16 @@ LINE
sub compile {
my $self = shift;
- my ($next, @args) = @_;
+ my ($next, $line, %args) = @_;
+
+ $args{package} = $self->{package};
+
+ my @result = $next->($line, %args);
# XXX it'd be nice to avoid using globals here, but we can't use
# eval_closure's environment parameter since we need to access the
# information in a BEGIN block
- our $package = $self->{package};
-
- my @result = $next->(@args);
-
- $self->{package} = $package;
+ $self->{package} = our $package;
return @result;
}