man Psh::Strategy () - a Perl Shell Evaluation Strategy (base class)

NAME

Psh::Strategy - a Perl Shell Evaluation Strategy (base class)

SYNOPSIS

  use Psh::Strategy;

DESCRIPTION

Psh::Strategy offers a procedural strategy list interface and a base class for developing strategies.

PROCEDURAL STRATEGY LIST

  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

DEVELOPING STRATEGIES

You have to inherit from Psh::Strategy and you MUST at least override the functions CWconsumes, CWapplies, CWexecute. You CAN also override the function CWruns_before

* consumes
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)
* applies
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 CW$obj->applies(\$inputline); If you specified CONSUME_TOKENS, this method will be called as CW$obj->applies(\$inputline,\@tokens,$piped_flag)
* execute
Will be called as CW$obj->execute(\$inputline,\@tokens,$how,$piped_flag) CW$how is what the call to applies returned. If CW@tokens is not applicable an empty array will be supplied. Your execute function should return an array of the form:
  ($evalcode, \@words, $forcefork, @return_val)
If CW$evalcode, <@words> and <$forcefork> are undef, execution is finished after this call and CW@return_val will be used as return value. But CW$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. CW@words will then be used as arguments for the program. CW$forcefork may be used to force a CWfork() call even for the perl subs.
* runs_before
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.