Peta::Shell::Complete#
what Tab offers in ipps
SYNOPSIS#
use Peta::Shell::Complete;
my $complete = Peta::Shell::Complete->new(session => $session);
my ($from, @words) = $complete->complete('my $n = $cou', 12);
## $from is 8, @words is ('$count', '$country'):
## each word replaces the line's text from offset 8 to the cursor
DESCRIPTION#
Given a line and the position of the cursor in it, this module says what the word in front of the cursor can become. It looks only at what exists: the variables of a Peta::Shell::Session, the packages and subs of the interpreter, the modules on the search path, the files on disk. It runs no code of the line, so it cannot complete through the result of a call.
What is offered depends on what stands in front of the cursor:
$na,@na,%naThe variables of the session and of the current package. After
$an array is offered as$name[and a hash as$name{; after@a hash is offered as@name{, the slice.$Some::Package::naoffers the variables of that package.$hash{ke,$ref->{ke,$data{list}[0]{keThe keys of that hash, with the closing brace. Only keys that can be written without quotes are offered.
$object->me,Class->meThe methods of the object’s or the named class, inherited ones included. Those that start with an underscore are offered only after an underscore.
use Mo,no Mo,require MoThe modules that are built into pperl or on the search path, one level at a time:
File::TeoffersFile::Temp, and a namespace that has modules below it asFile::Spec::."dir/fi(inside a string)The files of that directory. A directory gets its
/.! command fiThe files of that directory, for the last word of a line that is handed to the shell.
na(a plain word)The subs of the current package, Perl’s functions and keywords, the loaded packages, and at the start of a line the macros.
Some::Package::naoffers the subs and packages below it.:coThe commands of ipps, and after some of them what they take: a setting after
:set, a file after:loadand:save, a module after:whichand:install, a sub after:source.
METHODS#
new#
my $complete = Peta::Shell::Complete->new(%options);
Options:
session
The Peta::Shell::Session whose variables and current package are offered. Without one, only what does not need it is offered, in the package
main.commands
A code reference that returns the names of the commands, without the colon.
command
A code reference that gets a command as typed, maybe shortened, and returns its full name or nothing.
settings
A code reference that returns the names of the settings.
macros
A code reference that returns the names of the macros.
complete#
my ($from, @words) = $complete->complete($line, $cursor);
Returns the offset in $line from which the text up to $cursor is replaced, and the words it can be replaced with, sorted, each once. Returns the empty list when there is nothing to offer. $cursor defaults to the end of the line.