| 1 | package Reply::Plugin::Autocomplete::Keywords; | ||
| 2 | our $AUTHORITY = 'cpan:DOY'; | ||
| 3 | $Reply::Plugin::Autocomplete::Keywords::VERSION = '0.42'; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | # ABSTRACT: tab completion for perl keywords | ||
| 7 | |||
| 8 | use base 'Reply::Plugin'; | ||
| 9 | |||
| 10 | use B::Keywords qw/@Functions @Barewords/; | ||
| 11 | |||
| 12 | |||
| 13 | sub tab_handler { | ||
| 14 | my $self = shift; | ||
| 15 | my ($line) = @_; | ||
| 16 | |||
| 17 | my ($before, $last_word) = $line =~ /(.*?)(\w+)$/; | ||
| 18 | return unless $last_word; | ||
| 19 | return if $before =~ /^#/; # command | ||
| 20 | return if $before =~ /::$/; # Package::function call | ||
| 21 | return if $before =~ /->\s*$/; # method call | ||
| 22 | return if $before =~ /[\$\@\%\&\*]\s*$/; | ||
| 23 | |||
| 24 | my $re = qr/^\Q$last_word/; | ||
| 25 | |||
| 26 | return grep { $_ =~ $re } @Functions, @Barewords; | ||
| 27 | } | ||
| 28 | |||
| 29 | 1; | ||
| 30 | |||
| 31 | __END__ |