1 package Devel::REPL::Plugin::CompletionDriver::Methods;
2 use Devel::REPL::Plugin;
3 use namespace::clean -except => [ 'meta' ];
5 with 'Devel::REPL::Plugin::FindVariable';
7 around complete => sub {
9 my ($self, $text, $document) = @_;
11 my $last = $self->last_ppi_element($document);
14 # handle an incomplete method name, and back up to the ->
15 if ($last->isa('PPI::Token::Word')) {
16 my $previous = $last->sprevious_sibling
17 or return $orig->(@_);
18 $previous->isa('PPI::Token::Operator') && $previous->content eq '->'
19 or return $orig->(@_);
20 $incomplete = $last->content;
26 unless $last->isa('PPI::Token::Operator')
27 && $last->content eq '->';
29 # ..which is preceded by a word (class name)
30 my $previous = $last->sprevious_sibling
31 or return $orig->(@_);
32 $previous->isa('PPI::Token::Word') || $previous->isa('PPI::Token::Symbol')
33 or return $orig->(@_);
36 # we have a variable, need to look up its class
37 if ($previous->isa('PPI::Token::Symbol')) {
38 my $object_ref = $self->find_variable($previous->content)
39 or return $orig->(@_);
40 $class = blessed($$object_ref)
41 or return $orig->(@_);
44 $class = $previous->content;
47 # now we have $class->$incomplete
49 my $metaclass = Class::MOP::Class->initialize($class);
51 my $re = qr/^\Q$incomplete/;
56 $metaclass->compute_all_applicable_methods;
65 Devel::REPL::Plugin::CompletionDriver::Methods - Complete class or object method names
69 Shawn M Moore, C<< <sartak at gmail dot com> >>