From 7f6fda3414fe5ad689f6fd732a6cb1ca6078d1d0 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 10 Jul 2013 01:13:42 -0400 Subject: let plugins query for this info, rather than always publishing it --- lib/Reply/Plugin/Autocomplete/Lexicals.pm | 18 +----------------- lib/Reply/Plugin/Autocomplete/Methods.pm | 10 +--------- lib/Reply/Plugin/Defaults.pm | 9 +-------- lib/Reply/Plugin/LexicalPersistence.pm | 8 ++++++-- lib/Reply/Plugin/ResultCache.pm | 12 +++++------- 5 files changed, 14 insertions(+), 43 deletions(-) (limited to 'lib') 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; -- cgit v1.2.3-54-g00ecf