From: Sartak Date: Mon, 26 May 2008 03:19:17 +0000 (+0000) Subject: Have Methods completion driver use FindVariable to complete object methods X-Git-Tag: v1.003015~100 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDevel-REPL.git;a=commitdiff_plain;h=d13b1087ff1a7c97ac6edb2dd9e11bdd50e8c13c;hp=e93892cd24b9c3a90f80dd4445043513b05211a1 Have Methods completion driver use FindVariable to complete object methods git-svn-id: http://dev.catalyst.perl.org/repos/bast/trunk/Devel-REPL@4409 bd8105ee-0ff8-0310-8827-fb3f25b6796d --- diff --git a/lib/Devel/REPL/Plugin/CompletionDriver/Methods.pm b/lib/Devel/REPL/Plugin/CompletionDriver/Methods.pm index 14e0fcc..f9d4e60 100644 --- a/lib/Devel/REPL/Plugin/CompletionDriver/Methods.pm +++ b/lib/Devel/REPL/Plugin/CompletionDriver/Methods.pm @@ -2,6 +2,8 @@ package Devel::REPL::Plugin::CompletionDriver::Methods; use Devel::REPL::Plugin; use namespace::clean -except => [ 'meta' ]; +with 'Devel::REPL::Plugin::FindVariable'; + around complete => sub { my $orig = shift; my ($self, $text, $document) = @_; @@ -27,9 +29,20 @@ around complete => sub { # ..which is preceded by a word (class name) my $previous = $last->sprevious_sibling or return $orig->(@_); - $previous->isa('PPI::Token::Word') + $previous->isa('PPI::Token::Word') || $previous->isa('PPI::Token::Symbol') or return $orig->(@_); - my $class = $previous->content; + my $class; + + # we have a variable, need to look up its class + if ($previous->isa('PPI::Token::Symbol')) { + my $object_ref = $self->find_variable($previous->content) + or return $orig->(@_); + $class = blessed($$object_ref) + or return $orig->(@_); + } + else { + $class = $previous->content; + } # now we have $class->$incomplete