1 package Devel::REPL::Plugin::CompletionDriver::INC;
2 use Devel::REPL::Plugin;
5 use namespace::clean -except => [ 'meta' ];
7 around complete => sub {
9 my ($self, $text, $document) = @_;
11 my $last = $self->last_ppi_element($document, 'PPI::Statement::Include');
14 unless $last->isa('PPI::Statement::Include');
16 my @elements = $last->children;
17 shift @elements; # use or require
19 # too late for us to care, they're completing on something like
21 # OR they just have "use " and are tab completing. we'll spare them the flood
25 my $package = shift @elements;
28 my $keep_extension = 0;
31 if ($package->isa('PPI::Token::Quote'))
33 $outsep = $insep = '/';
36 elsif ($package =~ /'/)
38 # the goofball is using the ancient ' package sep, we'll humor him
43 my @directories = split $insep, $package;
45 # split drops trailing fields
46 push @directories, '' if $package =~ /(?:$insep)$/;
47 my $final = pop @directories;
48 my $final_re = qr/^\Q$final/;
55 for my $subdir (@directories)
57 $path = File::Spec->catdir($path, $subdir);
61 opendir((my $dirhandle), $path);
62 for my $match (grep { $_ =~ $final_re } readdir $dirhandle)
64 $match =~ s/\..*// unless $keep_extension;
65 push @found, join $outsep, @directories, $match;
69 return $orig->(@_), @found;