Psh::Strategy - a Perl Shell Evaluation Strategy (base class)
use Psh::Strategy;
Psh::Strategy offers a procedural strategy list interface and a base class for developing strategies.
Psh::Strategy::list()
Returns a list of active Psh::Strategy objects.
my $obj= Psh::Strategy::get('name')
Loads and initializes a certain Psh::Strategy object
Psh::Strategy::add($obj [, $suggest_position])
Adds a strategy object to the list of active strategies
Psh::Strategy::remove($name)
Removes a strategy
@list= Psh::Strategy::available_list()
Lists available strategies
my $pos= find($name)
Finds the position of the named strategy
my $flag= active($name)
Returns true if the named strategy is currently active
You have to inherit from Psh::Strategy and you MUST at least override the functions consumes, applies, execute. You CAN also override the function runs_before
consumes
applies
execute
runs_before
Returns either CONSUME_LINE, CONSUME_WORDS, CONSUME_TOKENS. CONSUME_LINE means you want to receive the whole input line unparsed. CONSUME_WORDS means you want to receive the whole input line tokenized (currenty unimplemented). CONSUME_TOKENS means that you want to receive a sub-part of the line, tokenized (this is probably what you want)
Returns undef if the strategy does not want to handle the input. Returns a human-readable description if it wants to handle the input.
If you specified CONSUME_LINE, this method will be called as $obj->applies(\$inputline);
If you specified CONSUME_TOKENS, this method will be called as $obj->applies(\$inputline,\@tokens,$piped_flag)
Will be called as $obj->execute(\$inputline,\@tokens,$how,$piped_flag)
$how is what the call to applies returned. If @tokens is not applicable an empty array will be supplied.
$how
@tokens
Your execute function should return an array of the form:
($evalcode, \@words, $forcefork, @return_val)
If $evalcode, <@words> and <$forcefork> are undef, execution is finished after this call and @return_val will be used as return value.
$evalcode
@return_val
But $evalcode can also be a Perl sub - in which case it is evaluated later on, or a string - in which case it's a filename of a program to execute. @words will then be used as arguments for the program.
@words
$forcefork may be used to force a fork() call even for the perl subs.
$forcefork
fork()
Returns a list of names of other strategies. It is guaranteed that the evaluation strategy will be tried before those other named strategies are tried.
To install Psh, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Psh
CPAN shell
perl -MCPAN -e shell install Psh
For more information on module installation, please visit the detailed CPAN module installation guide.