Move :Tab introspection from main:: to RevBank::Plugin
- Exposes the introspection as a public method. - Removes undocumented support for NOABORT special-case.
This commit is contained in:
parent
4f0954b2dc
commit
8956d8a483
3 changed files with 30 additions and 27 deletions
|
@ -3,16 +3,42 @@ package RevBank::Plugin;
|
||||||
use v5.28;
|
use v5.28;
|
||||||
use warnings;
|
use warnings;
|
||||||
use experimental 'signatures'; # stable since v5.36
|
use experimental 'signatures'; # stable since v5.36
|
||||||
|
use attributes;
|
||||||
|
|
||||||
require RevBank::Global;
|
require RevBank::Global;
|
||||||
|
|
||||||
sub new($class) {
|
sub new($class) {
|
||||||
return bless { }, $class;
|
return bless { }, $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub command($self, $cart, $command, @) {
|
sub command($self, $cart, $command, @) {
|
||||||
return RevBank::Global::NEXT();
|
return RevBank::Global::NEXT();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub Tab($self, $method) {
|
||||||
|
my %completions;
|
||||||
|
|
||||||
|
my $attr = attributes::get(
|
||||||
|
ref $method ? $method : $self->can($method)
|
||||||
|
) or return;
|
||||||
|
|
||||||
|
my ($tab) = $attr =~ /Tab \( (.*?) \)/x;
|
||||||
|
for my $keyword (split /\s*,\s*/, $tab) {
|
||||||
|
if ($keyword =~ /^&(.*)/) {
|
||||||
|
my $method = $1;
|
||||||
|
@completions{ $self->$method } = ();
|
||||||
|
} else {
|
||||||
|
$completions{ $keyword }++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delete $completions{USERS}) {
|
||||||
|
$completions{$_}++ for grep !RevBank::Users::is_hidden($_),
|
||||||
|
RevBank::Users::names();
|
||||||
|
}
|
||||||
|
|
||||||
|
return keys %completions;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ sub arg :Tab(USERS) ($self, $cart, $arg, @) {
|
||||||
}
|
}
|
||||||
|
|
||||||
# finish
|
# finish
|
||||||
sub reason :Tab(bbq,NOABORT) ($self, $cart, $reason, @) {
|
sub reason :Tab(bbq) ($self, $cart, $reason, @) {
|
||||||
return REJECT, "'$reason' is a username, not a description :)."
|
return REJECT, "'$reason' is a username, not a description :)."
|
||||||
if parse_user($reason);
|
if parse_user($reason);
|
||||||
return REJECT, "'$reason' is an amount, not a description :)."
|
return REJECT, "'$reason' is an amount, not a description :)."
|
||||||
|
|
29
revbank
29
revbank
|
@ -5,9 +5,8 @@ use warnings;
|
||||||
use feature qw(signatures);
|
use feature qw(signatures);
|
||||||
no warnings "experimental::signatures";
|
no warnings "experimental::signatures";
|
||||||
|
|
||||||
use attributes;
|
|
||||||
use IO::Select;
|
use IO::Select;
|
||||||
use List::Util ();
|
use List::Util qw(uniq);
|
||||||
use Term::ReadLine;
|
use Term::ReadLine;
|
||||||
require Term::ReadLine::Gnu; # The other one sucks.
|
require Term::ReadLine::Gnu; # The other one sucks.
|
||||||
|
|
||||||
|
@ -163,30 +162,8 @@ OUTER: for (;;) {
|
||||||
call_hooks "prompt", $cart, $prompt;
|
call_hooks "prompt", $cart, $prompt;
|
||||||
my $split_input = !ref($method) && $method eq 'command';
|
my $split_input = !ref($method) && $method eq 'command';
|
||||||
|
|
||||||
my %completions = qw(abort 1);
|
my @completions = uniq 'abort', map $_->Tab($method), @plugins;
|
||||||
for my $plugin (@plugins) {
|
my $input = prompt $prompt, \@plugins, \@completions;
|
||||||
my $attr = attributes::get(
|
|
||||||
ref $method ? $method : $plugin->can($method)
|
|
||||||
) or next;
|
|
||||||
my ($tab) = $attr =~ /Tab \( (.*?) \)/x;
|
|
||||||
for my $keyword (split /\s*,\s*/, $tab) {
|
|
||||||
if ($keyword =~ /^&(.*)/) {
|
|
||||||
my $method = $1;
|
|
||||||
@completions{ $plugin->$method } = ();
|
|
||||||
} else {
|
|
||||||
$completions{ $keyword }++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (delete $completions{USERS}) {
|
|
||||||
$completions{$_}++ for grep !RevBank::Users::is_hidden($_),
|
|
||||||
RevBank::Users::names;
|
|
||||||
}
|
|
||||||
if (delete $completions{NOABORT}) {
|
|
||||||
delete $completions{abort};
|
|
||||||
}
|
|
||||||
|
|
||||||
my $input = prompt $prompt, \@plugins, [ keys %completions ];
|
|
||||||
|
|
||||||
call_hooks "input", $cart, $input, $split_input;
|
call_hooks "input", $cart, $input, $split_input;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue