1 package Devel::REPL::Plugin::Completion;
2 use Devel::REPL::Plugin;
3 use Scalar::Util 'weaken';
5 use namespace::clean -except => [ 'meta' ];
7 has current_matches => (
11 default => sub { [] },
27 $self->term->Attribs->{attempted_completion_function} = sub {
28 $weakself->_completion(@_);
33 my ($self, $text, $line, $start, $end) = @_;
35 # we're discarding everything after the cursor for completion purposes
36 substr($line, $end) = '';
38 my $document = PPI::Document->new(\$line);
39 return unless defined($document);
41 my @matches = $self->complete($text, $document);
43 # iterate through the completions
44 return $self->term->completion_matches($text, sub {
45 my ($text, $state) = @_;
48 $self->current_matches(\@matches);
49 $self->match_index(0);
52 $self->match_index($self->match_index + 1);
55 return $self->current_matches->[$self->match_index];