summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn M Moore <code@sartak.org>2013-06-27 14:24:33 -0400
committerShawn M Moore <code@sartak.org>2013-06-27 14:24:33 -0400
commit848fe02434cc19f77a976763d563d76044496ea7 (patch)
treeee9af92d94d7d74fd79830dd62d7736419957cce
parentc437b3ded1a8a0700cab205c3801a854969c77c9 (diff)
downloadreply-848fe02434cc19f77a976763d563d76044496ea7.tar.gz
reply-848fe02434cc19f77a976763d563d76044496ea7.zip
First pass of pulling Package::Names out of %INC
-rw-r--r--lib/Reply/Plugin/Autocomplete.pm26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/Reply/Plugin/Autocomplete.pm b/lib/Reply/Plugin/Autocomplete.pm
index 621a832..8a64521 100644
--- a/lib/Reply/Plugin/Autocomplete.pm
+++ b/lib/Reply/Plugin/Autocomplete.pm
@@ -6,6 +6,7 @@ use warnings;
use base 'Reply::Plugin';
use B::Keywords qw/@Functions @Barewords/;
+use Module::Runtime '$module_name_rx';
=head1 SYNOPSIS
@@ -23,6 +24,7 @@ sub tab_handler {
return (
$self->_tab_keyword($line),
+ $self->_tab_package_loaded($line),
);
}
@@ -37,4 +39,28 @@ sub _tab_keyword {
return grep { $_ =~ $re } @Functions, @Barewords;
}
+sub _tab_package_loaded {
+ my ($self, $line) = @_;
+
+ # $module_name_rx does not permit trailing ::
+ my ($package_fragment) = $line =~ /($module_name_rx(?:::)?)$/;
+ return unless $package_fragment;
+
+ my $file_fragment = $package_fragment;
+ $file_fragment =~ s{::}{/}g;
+
+ my $re = qr/^\Q$file_fragment/;
+
+ my @results;
+ for my $inc (keys %INC) {
+ if ($inc =~ $re) {
+ $inc =~ s{/}{::}g;
+ $inc =~ s{\.pm$}{};
+ push @results, $inc;
+ }
+ }
+
+ return @results;
+}
+
1;