From 848fe02434cc19f77a976763d563d76044496ea7 Mon Sep 17 00:00:00 2001 From: Shawn M Moore Date: Thu, 27 Jun 2013 14:24:33 -0400 Subject: First pass of pulling Package::Names out of %INC --- lib/Reply/Plugin/Autocomplete.pm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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; -- cgit v1.2.3-54-g00ecf