summaryrefslogtreecommitdiffstats
path: root/lib/Reply/Plugin/Autocomplete
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Reply/Plugin/Autocomplete')
-rw-r--r--lib/Reply/Plugin/Autocomplete/Commands.pm19
-rw-r--r--lib/Reply/Plugin/Autocomplete/Functions.pm51
-rw-r--r--lib/Reply/Plugin/Autocomplete/Globals.pm101
-rw-r--r--lib/Reply/Plugin/Autocomplete/Keywords.pm27
-rw-r--r--lib/Reply/Plugin/Autocomplete/Lexicals.pm55
-rw-r--r--lib/Reply/Plugin/Autocomplete/Methods.pm63
-rw-r--r--lib/Reply/Plugin/Autocomplete/Packages.pm24
7 files changed, 163 insertions, 177 deletions
diff --git a/lib/Reply/Plugin/Autocomplete/Commands.pm b/lib/Reply/Plugin/Autocomplete/Commands.pm
index e3b653d..5bc0661 100644
--- a/lib/Reply/Plugin/Autocomplete/Commands.pm
+++ b/lib/Reply/Plugin/Autocomplete/Commands.pm
@@ -1,9 +1,9 @@
-package Reply::Plugin::Autocomplete::Commands;
+package main;
use strict;
use warnings;
# ABSTRACT: tab completion for reply commands
-use base 'Reply::Plugin';
+use mop;
=head1 SYNOPSIS
@@ -17,16 +17,15 @@ This plugin registers a tab key handler to autocomplete Reply commands.
=cut
-sub tab_handler {
- my $self = shift;
- my ($line) = @_;
+class Reply::Plugin::Autocomplete::Commands extends Reply::Plugin {
+ method tab_handler ($line) {
+ my ($prefix) = $line =~ /^#(.*)/;
+ return unless defined $prefix;
- my ($prefix) = $line =~ /^#(.*)/;
- return unless defined $prefix;
+ my @commands = $self->publish('commands');
- my @commands = $self->publish('commands');
-
- return map { "#$_" } sort grep { index($_, $prefix) == 0 } @commands;
+ return map { "#$_" } sort grep { index($_, $prefix) == 0 } @commands;
+ }
}
1;
diff --git a/lib/Reply/Plugin/Autocomplete/Functions.pm b/lib/Reply/Plugin/Autocomplete/Functions.pm
index 205841e..2f1f583 100644
--- a/lib/Reply/Plugin/Autocomplete/Functions.pm
+++ b/lib/Reply/Plugin/Autocomplete/Functions.pm
@@ -1,9 +1,9 @@
-package Reply::Plugin::Autocomplete::Functions;
+package main;
use strict;
use warnings;
# ABSTRACT: tab completion for function names
-use base 'Reply::Plugin';
+use mop;
use Module::Runtime '$module_name_rx';
use Package::Stash;
@@ -21,31 +21,30 @@ code, including imported functions.
=cut
-sub tab_handler {
- my $self = shift;
- my ($line) = @_;
-
- my ($before, $fragment) = $line =~ /(.*?)(${module_name_rx}(::)?)$/;
- return unless $fragment;
- return if $before =~ /^#/; # commands
-
- my $current_package = ($self->publish('package'))[-1];
-
- my ($package, $func);
- if ($fragment =~ /:/) {
- ($package, $func) = ($fragment =~ /^(.+:)(\w*)$/);
- $func = '' unless defined $func;
- $package =~ s/:{1,2}$//;
+class Reply::Plugin::Autocomplete::Functions extends Reply::Plugin {
+ method tab_handler ($line) {
+ my ($before, $fragment) = $line =~ /(.*?)(${module_name_rx}(::)?)$/;
+ return unless $fragment;
+ return if $before =~ /^#/; # commands
+
+ my $current_package = ($self->publish('package'))[-1];
+
+ my ($package, $func);
+ if ($fragment =~ /:/) {
+ ($package, $func) = ($fragment =~ /^(.+:)(\w*)$/);
+ $func = '' unless defined $func;
+ $package =~ s/:{1,2}$//;
+ }
+ else {
+ $package = $current_package;
+ $func = $fragment;
+ }
+
+ return
+ map { $package eq $current_package ? $_ : "$package\::$_" }
+ grep { $func ? /^\Q$func/ : 1 }
+ Package::Stash->new($package)->list_all_symbols('CODE');
}
- else {
- $package = $current_package;
- $func = $fragment;
- }
-
- return
- map { $package eq $current_package ? $_ : "$package\::$_" }
- grep { $func ? /^\Q$func/ : 1 }
- 'Package::Stash'->new($package)->list_all_symbols('CODE');
}
1;
diff --git a/lib/Reply/Plugin/Autocomplete/Globals.pm b/lib/Reply/Plugin/Autocomplete/Globals.pm
index ac2ca3e..2bdd673 100644
--- a/lib/Reply/Plugin/Autocomplete/Globals.pm
+++ b/lib/Reply/Plugin/Autocomplete/Globals.pm
@@ -1,9 +1,9 @@
-package Reply::Plugin::Autocomplete::Globals;
+package main;
use strict;
use warnings;
# ABSTRACT: tab completion for global variables
-use base 'Reply::Plugin';
+use mop;
use Package::Stash;
@@ -22,61 +22,52 @@ Perl code.
=cut
-sub new {
- my $class = shift;
-
- my $self = $class->SUPER::new(@_);
-
- return $self;
-}
-
-sub tab_handler {
- my $self = shift;
- my ($line) = @_;
-
- my ($maybe_var) = $line =~ /($fq_varname_rx)$/;
- return unless $maybe_var;
- $maybe_var =~ s/\s+//g;
-
- my ($sigil, $rest) = $maybe_var =~ /(.)(.*)/;
-
- my @parts = split '::', $rest, -1;
- return if grep { /:/ } @parts;
- return if @parts && $parts[0] =~ /^[0-9]/;
-
- my $var_prefix = pop @parts;
- $var_prefix = '' unless defined $var_prefix;
-
- my $stash_name = join('::', @parts);
- my $stash = eval {
- Package::Stash->new(@parts ? $stash_name : 'main')
- };
- return unless $stash;
-
- my @symbols = map { s/^(.)main::/$1/; $_ } _recursive_symbols($stash);
-
- my $prefix = $stash_name
- ? $stash_name . '::' . $var_prefix
- : $var_prefix;
-
- my @results;
- for my $global (@symbols) {
- my ($global_sigil, $global_name) = $global =~ /(.)(.*)/;
- next unless index($global_name, $prefix) == 0;
-
- # this is weird, not sure why % gets stripped but not $ or @
- if ($sigil eq $global_sigil) {
- push @results, $sigil eq '%' ? $global : $global_name;
+class Reply::Plugin::Autocomplete::Globals extends Reply::Plugin {
+ method tab_handler ($line) {
+ my ($maybe_var) = $line =~ /($fq_varname_rx)$/;
+ return unless $maybe_var;
+ $maybe_var =~ s/\s+//g;
+
+ my ($sigil, $rest) = $maybe_var =~ /(.)(.*)/;
+
+ my @parts = split '::', $rest, -1;
+ return if grep { /:/ } @parts;
+ return if @parts && $parts[0] =~ /^[0-9]/;
+
+ my $var_prefix = pop @parts;
+ $var_prefix = '' unless defined $var_prefix;
+
+ my $stash_name = join('::', @parts);
+ my $stash = eval {
+ Package::Stash->new(@parts ? $stash_name : 'main')
+ };
+ return unless $stash;
+
+ my @symbols = map { s/^(.)main::/$1/; $_ } _recursive_symbols($stash);
+
+ my $prefix = $stash_name
+ ? $stash_name . '::' . $var_prefix
+ : $var_prefix;
+
+ my @results;
+ for my $global (@symbols) {
+ my ($global_sigil, $global_name) = $global =~ /(.)(.*)/;
+ next unless index($global_name, $prefix) == 0;
+
+ # this is weird, not sure why % gets stripped but not $ or @
+ if ($sigil eq $global_sigil) {
+ push @results, $sigil eq '%' ? $global : $global_name;
+ }
+ elsif ($global_sigil eq '@' && $sigil eq '$') {
+ push @results, "$global_name\[";
+ }
+ elsif ($global_sigil eq '%') {
+ push @results, "$global_name\{";
+ }
}
- elsif ($global_sigil eq '@' && $sigil eq '$') {
- push @results, "$global_name\[";
- }
- elsif ($global_sigil eq '%') {
- push @results, "$global_name\{";
- }
- }
- return @results;
+ return @results;
+ }
}
sub _recursive_symbols {
diff --git a/lib/Reply/Plugin/Autocomplete/Keywords.pm b/lib/Reply/Plugin/Autocomplete/Keywords.pm
index ee863d1..a17ec41 100644
--- a/lib/Reply/Plugin/Autocomplete/Keywords.pm
+++ b/lib/Reply/Plugin/Autocomplete/Keywords.pm
@@ -1,9 +1,9 @@
-package Reply::Plugin::Autocomplete::Keywords;
+package main;
use strict;
use warnings;
# ABSTRACT: tab completion for perl keywords
-use base 'Reply::Plugin';
+use mop;
use B::Keywords qw/@Functions @Barewords/;
@@ -19,20 +19,19 @@ This plugin registers a tab key handler to autocomplete keywords in Perl code.
=cut
-sub tab_handler {
- my $self = shift;
- my ($line) = @_;
+class Reply::Plugin::Autocomplete::Keywords extends Reply::Plugin {
+ method tab_handler ($line) {
+ my ($before, $last_word) = $line =~ /(.*?)(\w+)$/;
+ return unless $last_word;
+ return if $before =~ /^#/; # command
+ return if $before =~ /::$/; # Package::function call
+ return if $before =~ /->\s*$/; # method call
+ return if $before =~ /[\$\@\%\&\*]\s*$/;
- my ($before, $last_word) = $line =~ /(.*?)(\w+)$/;
- return unless $last_word;
- return if $before =~ /^#/; # command
- return if $before =~ /::$/; # Package::function call
- return if $before =~ /->\s*$/; # method call
- return if $before =~ /[\$\@\%\&\*]\s*$/;
+ my $re = qr/^\Q$last_word/;
- my $re = qr/^\Q$last_word/;
-
- return grep { $_ =~ $re } @Functions, @Barewords;
+ return grep { $_ =~ $re } @Functions, @Barewords;
+ }
}
1;
diff --git a/lib/Reply/Plugin/Autocomplete/Lexicals.pm b/lib/Reply/Plugin/Autocomplete/Lexicals.pm
index c733fed..c3468de 100644
--- a/lib/Reply/Plugin/Autocomplete/Lexicals.pm
+++ b/lib/Reply/Plugin/Autocomplete/Lexicals.pm
@@ -1,9 +1,9 @@
-package Reply::Plugin::Autocomplete::Lexicals;
+package main;
use strict;
use warnings;
# ABSTRACT: tab completion for lexical variables
-use base 'Reply::Plugin';
+use mop;
use Reply::Util qw($varname_rx);
@@ -20,40 +20,39 @@ Perl code.
=cut
-sub tab_handler {
- my $self = shift;
- my ($line) = @_;
+class Reply::Plugin::Autocomplete::Lexicals extends Reply::Plugin {
+ method tab_handler ($line) {
+ my ($var) = $line =~ /($varname_rx)$/;
+ return unless $var;
- my ($var) = $line =~ /($varname_rx)$/;
- return unless $var;
+ my ($sigil, $name_prefix) = $var =~ /(.)(.*)/;
- my ($sigil, $name_prefix) = $var =~ /(.)(.*)/;
+ # these can't be lexicals
+ return if $sigil eq '&' || $sigil eq '*';
- # these can't be lexicals
- return if $sigil eq '&' || $sigil eq '*';
+ my $env = { map { %$_ } $self->publish('lexical_environment') };
+ my @env = keys %$env;
- my $env = { map { %$_ } $self->publish('lexical_environment') };
- my @env = keys %$env;
+ my @results;
+ for my $env_var (@env) {
+ my ($env_sigil, $env_name) = $env_var =~ /(.)(.*)/;
- my @results;
- for my $env_var (@env) {
- my ($env_sigil, $env_name) = $env_var =~ /(.)(.*)/;
+ next unless index($env_name, $name_prefix) == 0;
- next unless index($env_name, $name_prefix) == 0;
-
- # this is weird, not sure why % gets stripped but not $ or @
- if ($sigil eq $env_sigil) {
- push @results, $sigil eq '%' ? $env_var : $env_name;
- }
- elsif ($env_sigil eq '@' && $sigil eq '$') {
- push @results, "$env_name\[";
- }
- elsif ($env_sigil eq '%') {
- push @results, "$env_name\{";
+ # this is weird, not sure why % gets stripped but not $ or @
+ if ($sigil eq $env_sigil) {
+ push @results, $sigil eq '%' ? $env_var : $env_name;
+ }
+ elsif ($env_sigil eq '@' && $sigil eq '$') {
+ push @results, "$env_name\[";
+ }
+ elsif ($env_sigil eq '%') {
+ push @results, "$env_name\{";
+ }
}
- }
- return @results;
+ return @results;
+ }
}
1;
diff --git a/lib/Reply/Plugin/Autocomplete/Methods.pm b/lib/Reply/Plugin/Autocomplete/Methods.pm
index 45a6507..f1fd8b0 100644
--- a/lib/Reply/Plugin/Autocomplete/Methods.pm
+++ b/lib/Reply/Plugin/Autocomplete/Methods.pm
@@ -1,9 +1,9 @@
-package Reply::Plugin::Autocomplete::Methods;
+package main;
use strict;
use warnings;
# ABSTRACT: tab completion for methods
-use base 'Reply::Plugin';
+use mop;
use Scalar::Util 'blessed';
@@ -22,37 +22,36 @@ code.
=cut
-sub tab_handler {
- my $self = shift;
- my ($line) = @_;
-
- my ($invocant, $method_prefix) = $line =~ /($fq_varname_rx|$fq_ident_rx)->($ident_rx)?$/;
- return unless $invocant;
- # XXX unicode
- return unless $invocant =~ /^[\$A-Z_a-z]/;
-
- $method_prefix = '' unless defined $method_prefix;
-
- my $class;
- if ($invocant =~ /^\$/) {
- # XXX should support globals here
- my $env = {
- map { %$_ } $self->publish('lexical_environment'),
- };
- my $var = $env->{$invocant};
- return unless $var && ref($var) eq 'REF' && blessed($$var);
- $class = blessed($$var);
+class Reply::Plugin::Autocomplete::Methods extends Reply::Plugin {
+ method tab_handler ($line) {
+ my ($invocant, $method_prefix) = $line =~ /($fq_varname_rx|$fq_ident_rx)->($ident_rx)?$/;
+ return unless $invocant;
+ # XXX unicode
+ return unless $invocant =~ /^[\$A-Z_a-z]/;
+
+ $method_prefix = '' unless defined $method_prefix;
+
+ my $class;
+ if ($invocant =~ /^\$/) {
+ # XXX should support globals here
+ my $env = {
+ map { %$_ } $self->publish('lexical_environment'),
+ };
+ my $var = $env->{$invocant};
+ return unless $var && ref($var) eq 'REF' && blessed($$var);
+ $class = blessed($$var);
+ }
+ else {
+ $class = $invocant;
+ }
+
+ my @results;
+ for my $method (methods($class)) {
+ push @results, $method if index($method, $method_prefix) == 0;
+ }
+
+ return sort @results;
}
- else {
- $class = $invocant;
- }
-
- my @results;
- for my $method (methods($class)) {
- push @results, $method if index($method, $method_prefix) == 0;
- }
-
- return sort @results;
}
1;
diff --git a/lib/Reply/Plugin/Autocomplete/Packages.pm b/lib/Reply/Plugin/Autocomplete/Packages.pm
index c2bb6a0..aaf3afc 100644
--- a/lib/Reply/Plugin/Autocomplete/Packages.pm
+++ b/lib/Reply/Plugin/Autocomplete/Packages.pm
@@ -1,9 +1,9 @@
-package Reply::Plugin::Autocomplete::Packages;
+package main;
use strict;
use warnings;
# ABSTRACT: tab completion for package names
-use base 'Reply::Plugin';
+use mop;
use Module::Runtime '$module_name_rx';
@@ -22,18 +22,18 @@ code.
=cut
-sub tab_handler {
- my $self = shift;
- my ($line) = @_;
+class Reply::Plugin::Autocomplete::Packages extends Reply::Plugin {
+ method tab_handler ($line) {
- # $module_name_rx does not permit trailing ::
- my ($before, $package_fragment) = $line =~ /(.*?)(${module_name_rx}:?:?)$/;
- return unless $package_fragment;
- return if $before =~ /^#/; # command
- return if $before =~ /->\s*$/; # method call
- return if $before =~ /[\$\@\%\&\*]\s*$/;
+ # $module_name_rx does not permit trailing ::
+ my ($before, $package_fragment) = $line =~ /(.*?)(${module_name_rx}:?:?)$/;
+ return unless $package_fragment;
+ return if $before =~ /^#/; # command
+ return if $before =~ /->\s*$/; # method call
+ return if $before =~ /[\$\@\%\&\*]\s*$/;
- return sort grep { index($_, $package_fragment) == 0 } all_packages();
+ return sort grep { index($_, $package_fragment) == 0 } all_packages();
+ }
}
1;