3 package Devel::REPL::Plugin::CompletionDriver::Methods;
5 our $VERSION = '1.003027';
7 use Devel::REPL::Plugin;
8 use Devel::REPL::Plugin::Completion; # die early if cannot load
9 use namespace::autoclean;
13 for (qw/Completion FindVariable/) {
14 $self->load_plugin($_);
18 around complete => sub {
20 my ($self, $text, $document) = @_;
22 my $last = $self->last_ppi_element($document);
25 # handle an incomplete method name, and back up to the ->
26 if ($last->isa('PPI::Token::Word')) {
27 my $previous = $last->sprevious_sibling
28 or return $orig->(@_);
29 $previous->isa('PPI::Token::Operator') && $previous->content eq '->'
30 or return $orig->(@_);
31 $incomplete = $last->content;
37 unless $last->isa('PPI::Token::Operator')
38 && $last->content eq '->';
40 # ..which is preceded by a word (class name)
41 my $previous = $last->sprevious_sibling
42 or return $orig->(@_);
43 $previous->isa('PPI::Token::Word') || $previous->isa('PPI::Token::Symbol')
44 or return $orig->(@_);
47 # we have a variable, need to look up its class
48 if ($previous->isa('PPI::Token::Symbol')) {
49 my $object_ref = $self->find_variable($previous->content)
50 or return $orig->(@_);
51 $class = blessed($$object_ref)
52 or return $orig->(@_);
55 $class = $previous->content;
58 # now we have $class->$incomplete
60 my $metaclass = Class::MOP::Class->initialize($class);
62 my $re = qr/^\Q$incomplete/;
67 $metaclass->get_all_methods;
76 Devel::REPL::Plugin::CompletionDriver::Methods - Complete class or object method names
80 Shawn M Moore, C<< <sartak at gmail dot com> >>