summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-07-10 01:13:42 -0400
committerJesse Luehrs <doy@tozt.net>2013-07-10 01:13:42 -0400
commit7f6fda3414fe5ad689f6fd732a6cb1ca6078d1d0 (patch)
tree259512cb41a0275d62d6f8209135d6cbe5c9d511
parent9ad70dd68d45203970fed6e7c2bdca13da13d8c4 (diff)
downloadreply-7f6fda3414fe5ad689f6fd732a6cb1ca6078d1d0.tar.gz
reply-7f6fda3414fe5ad689f6fd732a6cb1ca6078d1d0.zip
let plugins query for this info, rather than always publishing it
-rw-r--r--lib/Reply/Plugin/Autocomplete/Lexicals.pm18
-rw-r--r--lib/Reply/Plugin/Autocomplete/Methods.pm10
-rw-r--r--lib/Reply/Plugin/Defaults.pm9
-rw-r--r--lib/Reply/Plugin/LexicalPersistence.pm8
-rw-r--r--lib/Reply/Plugin/ResultCache.pm12
5 files changed, 14 insertions, 43 deletions
diff --git a/lib/Reply/Plugin/Autocomplete/Lexicals.pm b/lib/Reply/Plugin/Autocomplete/Lexicals.pm
index 204778a..c733fed 100644
--- a/lib/Reply/Plugin/Autocomplete/Lexicals.pm
+++ b/lib/Reply/Plugin/Autocomplete/Lexicals.pm
@@ -20,22 +20,6 @@ Perl code.
=cut
-sub new {
- my $class = shift;
-
- my $self = $class->SUPER::new(@_);
- $self->{env} = [];
-
- return $self;
-}
-
-sub lexical_environment {
- my $self = shift;
- my ($env) = @_;
-
- push @{ $self->{env} }, $env;
-}
-
sub tab_handler {
my $self = shift;
my ($line) = @_;
@@ -48,7 +32,7 @@ sub tab_handler {
# these can't be lexicals
return if $sigil eq '&' || $sigil eq '*';
- my $env = { map { %$_ } @{ $self->{env} } };
+ my $env = { map { %$_ } $self->publish('lexical_environment') };
my @env = keys %$env;
my @results;
diff --git a/lib/Reply/Plugin/Autocomplete/Methods.pm b/lib/Reply/Plugin/Autocomplete/Methods.pm
index b643fb2..35de87e 100644
--- a/lib/Reply/Plugin/Autocomplete/Methods.pm
+++ b/lib/Reply/Plugin/Autocomplete/Methods.pm
@@ -26,19 +26,11 @@ sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
- $self->{env} = [];
$self->{package} = 'main';
return $self;
}
-sub lexical_environment {
- my $self = shift;
- my ($env) = @_;
-
- push @{ $self->{env} }, $env;
-}
-
sub package {
my $self = shift;
my ($package) = @_;
@@ -61,7 +53,7 @@ sub tab_handler {
if ($invocant =~ /^\$/) {
# XXX should support globals here
my $env = {
- map { %$_ } @{ $self->{env} },
+ map { %$_ } $self->publish('lexical_environment'),
};
my $var = $env->{$invocant};
return unless $var && ref($var) eq 'REF' && blessed($$var);
diff --git a/lib/Reply/Plugin/Defaults.pm b/lib/Reply/Plugin/Defaults.pm
index adf5c0e..89c618e 100644
--- a/lib/Reply/Plugin/Defaults.pm
+++ b/lib/Reply/Plugin/Defaults.pm
@@ -21,7 +21,6 @@ sub new {
my $self = $class->SUPER::new(@_);
$self->{quit} = 0;
- $self->{env} = [];
$self->{package} = 'main';
return $self;
@@ -49,7 +48,7 @@ sub compile {
my $self = shift;
my ($next, $line, %args) = @_;
- my $env = { map { %$_ } @{ $self->{env} } };
+ my $env = { map { %$_ } $self->publish('lexical_environment') };
my $prefix = "package $self->{package};\n$PREFIX";
@@ -67,12 +66,6 @@ sub compile {
return $code;
}
-sub lexical_environment {
- my $self = shift;
- my ($env) = @_;
- push @{ $self->{env} }, $env;
-}
-
sub package {
my $self = shift;
my ($package) = @_;
diff --git a/lib/Reply/Plugin/LexicalPersistence.pm b/lib/Reply/Plugin/LexicalPersistence.pm
index 8437cbe..2e972bf 100644
--- a/lib/Reply/Plugin/LexicalPersistence.pm
+++ b/lib/Reply/Plugin/LexicalPersistence.pm
@@ -41,9 +41,13 @@ sub compile {
%{ peek_sub($code) },
};
- $self->publish('lexical_environment', $self->{env});
-
return $code;
}
+sub lexical_environment {
+ my $self = shift;
+
+ return $self->{env};
+}
+
1;
diff --git a/lib/Reply/Plugin/ResultCache.pm b/lib/Reply/Plugin/ResultCache.pm
index 5a241e3..6ecf9f6 100644
--- a/lib/Reply/Plugin/ResultCache.pm
+++ b/lib/Reply/Plugin/ResultCache.pm
@@ -44,13 +44,6 @@ sub execute {
push @{ $self->{results} }, \@res;
}
- $self->publish(
- 'lexical_environment',
- {
- "\@$self->{result_name}" => $self->{results},
- },
- );
-
return @res;
}
@@ -63,4 +56,9 @@ sub mangle_result {
. $result;
}
+sub lexical_environment {
+ my $self = shift;
+ return { "\@$self->{result_name}" => $self->{results} };
+}
+
1;