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 consumes, applies, execute. You CAN also override the function runs_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 $obj->applies(\$inputline);

    If you specified CONSUME_TOKENS, this method will be called as $obj->applies(\$inputline,\@tokens,$piped_flag)

  • execute

    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.

    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.

    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.

    $forcefork may be used to force a fork() 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.