diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-07-04 13:07:16 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-07-04 13:07:16 -0400 |
commit | 903b05bdb8c1224deabd9674bb4be1bae5195312 (patch) | |
tree | a9a8d7bf1e8cf44de16981d62bf7b61da1b35c3c /lib/Reply | |
parent | ff42543cec4d93057cdff1ae3a635268d00c0296 (diff) | |
download | reply-903b05bdb8c1224deabd9674bb4be1bae5195312.tar.gz reply-903b05bdb8c1224deabd9674bb4be1bae5195312.zip |
refactor this to avoid some duplication
Diffstat (limited to 'lib/Reply')
-rw-r--r-- | lib/Reply/Plugin/Autocomplete/Globals.pm | 7 | ||||
-rw-r--r-- | lib/Reply/Plugin/Autocomplete/Lexicals.pm | 10 | ||||
-rw-r--r-- | lib/Reply/Plugin/Autocomplete/Methods.pm | 6 | ||||
-rw-r--r-- | lib/Reply/Util.pm | 17 |
4 files changed, 32 insertions, 8 deletions
diff --git a/lib/Reply/Plugin/Autocomplete/Globals.pm b/lib/Reply/Plugin/Autocomplete/Globals.pm index 99ab864..ac2ca3e 100644 --- a/lib/Reply/Plugin/Autocomplete/Globals.pm +++ b/lib/Reply/Plugin/Autocomplete/Globals.pm @@ -7,6 +7,8 @@ use base 'Reply::Plugin'; use Package::Stash; +use Reply::Util qw($fq_ident_rx $fq_varname_rx); + =head1 SYNOPSIS ; .replyrc @@ -32,7 +34,7 @@ sub tab_handler { my $self = shift; my ($line) = @_; - my ($maybe_var) = $line =~ /([\$\@\%\&\*]\s*[0-9A-Z_a-z:]*)$/; + my ($maybe_var) = $line =~ /($fq_varname_rx)$/; return unless $maybe_var; $maybe_var =~ s/\s+//g; @@ -90,8 +92,7 @@ sub _recursive_symbols { # to not also block out punctuation variables. # XXX fix for unicode # XXX fix for variables like ${^GLOBAL_PHASE} - next unless $name =~ /^[A-Z_a-z][0-9A-Z_a-z]*(?:::)?$/ - || length($name) == 1; + next unless $name =~ /^$fq_ident_rx(?:::)?$/ || length($name) == 1; if ($name =~ s/::$//) { my $next = Package::Stash->new(join('::', $stash_name, $name)); diff --git a/lib/Reply/Plugin/Autocomplete/Lexicals.pm b/lib/Reply/Plugin/Autocomplete/Lexicals.pm index 08d4c02..dd953bf 100644 --- a/lib/Reply/Plugin/Autocomplete/Lexicals.pm +++ b/lib/Reply/Plugin/Autocomplete/Lexicals.pm @@ -5,6 +5,8 @@ use warnings; use base 'Reply::Plugin'; +use Reply::Util qw($varname_rx); + =head1 SYNOPSIS ; .replyrc @@ -18,9 +20,6 @@ Perl code. =cut -# XXX unicode? -my $var_name_rx = qr/[\$\@\%]\s*(?:[A-Z_a-z][0-9A-Z_a-z]*)?/; - sub new { my $class = shift; @@ -41,11 +40,14 @@ sub tab_handler { my $self = shift; my ($line) = @_; - my ($var) = $line =~ /($var_name_rx)$/; + my ($var) = $line =~ /($varname_rx)$/; return unless $var; my ($sigil, $name_prefix) = $var =~ /(.)(.*)/; + # these can't be lexicals + return if $sigil eq '&' || $sigil eq '*'; + my $env = { map { %$_ } values %{ $self->{env} } }; my @env = keys %$env; diff --git a/lib/Reply/Plugin/Autocomplete/Methods.pm b/lib/Reply/Plugin/Autocomplete/Methods.pm index 4b1c4f5..7421226 100644 --- a/lib/Reply/Plugin/Autocomplete/Methods.pm +++ b/lib/Reply/Plugin/Autocomplete/Methods.pm @@ -9,6 +9,8 @@ use MRO::Compat; use Package::Stash; use Scalar::Util 'blessed'; +use Reply::Util qw($ident_rx $fq_ident_rx $fq_varname_rx); + =head1 SYNOPSIS ; .replyrc @@ -50,8 +52,10 @@ sub tab_handler { my $self = shift; my ($line) = @_; - my ($invocant, $method) = $line =~ /((?:\$\s*)?[A-Z_a-z][0-9A-Z_a-z:]*)->([A-Z_a-z][0-9A-Z_a-z]*)?$/; + my ($invocant, $method) = $line =~ /($fq_varname_rx|$fq_ident_rx)->($ident_rx)?$/; return unless $invocant; + # XXX unicode + return unless $invocant =~ /^[\$A-Z_a-z]/; $method = '' unless defined $method; diff --git a/lib/Reply/Util.pm b/lib/Reply/Util.pm new file mode 100644 index 0000000..cb33466 --- /dev/null +++ b/lib/Reply/Util.pm @@ -0,0 +1,17 @@ +package Reply::Util; +use strict; +use warnings; + +use Exporter 'import'; +our @EXPORT_OK = qw($ident_rx $varname_rx $fq_ident_rx $fq_varname_rx); + +# XXX this should be updated for unicode +our $varstart_rx = qr/[A-Z_a-z]/; +our $varcont_rx = qr/[0-9A-Z_a-z]/; +our $ident_rx = qr/${varstart_rx}${varcont_rx}*/; +our $sigil_rx = qr/[\$\@\%\&\*]/; +our $varname_rx = qr/$sigil_rx\s*$ident_rx/; +our $fq_ident_rx = qr/$ident_rx(?:::$varcont_rx+)?/; +our $fq_varname_rx = qr/$varname_rx(?:::$varcont_rx+)?/; + +1; |