3 package Devel::REPL::Plugin::CompletionDriver::Methods;
4 # ABSTRACT: Complete class or object method names
6 our $VERSION = '1.003027';
8 use Devel::REPL::Plugin;
9 use Devel::REPL::Plugin::Completion; # die early if cannot load
10 use namespace::autoclean;
14 for (qw/Completion FindVariable/) {
15 $self->load_plugin($_);
19 around complete => sub {
21 my ($self, $text, $document) = @_;
23 my $last = $self->last_ppi_element($document);
26 # handle an incomplete method name, and back up to the ->
27 if ($last->isa('PPI::Token::Word')) {
28 my $previous = $last->sprevious_sibling
29 or return $orig->(@_);
30 $previous->isa('PPI::Token::Operator') && $previous->content eq '->'
31 or return $orig->(@_);
32 $incomplete = $last->content;
38 unless $last->isa('PPI::Token::Operator')
39 && $last->content eq '->';
41 # ..which is preceded by a word (class name)
42 my $previous = $last->sprevious_sibling
43 or return $orig->(@_);
44 $previous->isa('PPI::Token::Word') || $previous->isa('PPI::Token::Symbol')
45 or return $orig->(@_);
48 # we have a variable, need to look up its class
49 if ($previous->isa('PPI::Token::Symbol')) {
50 my $object_ref = $self->find_variable($previous->content)
51 or return $orig->(@_);
52 $class = blessed($$object_ref)
53 or return $orig->(@_);
56 $class = $previous->content;
59 # now we have $class->$incomplete
61 my $metaclass = Class::MOP::Class->initialize($class);
63 my $re = qr/^\Q$incomplete/;
68 $metaclass->get_all_methods;
79 Shawn M Moore, C<< <sartak at gmail dot com> >>