Psh::Strategy - a Perl Shell Evaluation Strategy (base class)
Psh::Strategy offers a procedural strategy list interface and a base class for developing strategies.
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
Removes a strategy
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
execute. You CAN also override the function
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)
$howis what the call to applies returned. If
@tokensis not applicable an empty array will be supplied.
Your execute function should return an array of the form:
($evalcode, \@words, $forcefork, @return_val)
$evalcode, <@words> and <$forcefork> are undef, execution is finished after this call and
@return_valwill be used as return value.
$evalcodecan 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.
@wordswill then be used as arguments for the program.
$forceforkmay be used to force a
fork()call even for the perl subs.
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.