NAME

Zoidberg::Shell - a scripting interface to the Zoidberg shell

SYNOPSIS

        use Zoidberg::Shell;
	my $SHELL = Zoidberg::Shell->new();
       
	# Order parent shell to 'cd' to /usr
	# If you let your shell do 'cd' that is _NOT_ the same as doing 'chdir'
        $SHELL->shell(qw{cd /usr});
	
	# Let your parent shell execute a logic list with a pipeline
	$SHELL->shell([qw{ls -al}], [qw{grep ^d}], 'OR', [qw{echo some error happened}]);
	
	# Create an alias
	$SHELL->alias({'ls' => 'ls --color=auto'});
	
	# since we use Exporter::Tidy you can also do this:
	use Zoidberg::Shell _prefix => 'zoid_', qw/shell alias unalias/;
	zoid_alias({'perlfunc' => 'perldoc -Uf'});

DESCRIPTION

This module is intended to let perl scripts interface to the Zoidberg shell in an easy way. The most important usage for this is to write 'source scripts' for the Zoidberg shell which can use and change the parent shell environment like /.*sh/ source scripts do with /.*sh/ environments.

EXPORT

Only the subs AUTOLOAD and shell are exported by default. AUTOLOAD works more or less like the one from Shell.pm by Larry Wall, but it includes zoid's builtin functions and commands (also it just prints output to stdout see TODO).

The other methods (except new) can be exported on demand. Be aware of the fact that methods like alias can mask "plugin defined builtins" with the same name, but with an other interface. If instead of exporting these methods the "AUTOLOAD" method is used, different behaviour can be expected.

METHODS

Be aware: All commands are executed in the parent shell environment, so if a command changes the environment these changes will change the environment of the parent shell, even when the script has long finished.

new()

Simple constructor.

shell($command, @_)

If $command is a built-in shell function (possibly defined by a plugin) or a system binary, it will be run with arguments @_. The command won't be subject to alias expansion, arguments might be subject to glob expansion.

If you just want the output of a system command use the system method.

If you want to make sure you get a built-in command use builtin, you might prevent some strange bugs.

shell([$command, @_], [..], 'AND', [..])

Create a logic list and/or pipeline. Available tokens are 'AND', 'OR' and 'EOS' (End Of Statement, ';').

shell_string($string)

Parse and execute $string like it was entered from the commandline. You should realise that the parsing is dependent on grammars currently in use, and also on things like aliases etc.

Using this form in a source script _will_ attract nasty bugs

shell_tree([$context, @_], [..],'AND',[..])
shell_tree([ {context => $context}, @_ ])

Like shell() but lets lets you pass more meta data to the parse tree. This can be considered an "expert mode", see parser documentation/source elsewhere.

TODO - not yet implemented

set(..)

Update settings in parent shell.

# merge hash with current settings hash
set( { noglob => 0 } );

# set these bits to true
set( qw/hide_private_method hide_hidden_files/);
alias(\%aliases)

Merge %aliases with current alias hash.

alias( { ls => 'ls ---color=auto' } )

FIXME point to docs on aliases

unalias(@aliases)

Delete all keys listed in @aliases from the aliases table.

exec_error()

Returns the error caused by the last executed command, or undef is all is well.

AUTOLOAD

All calls that get autoloaded are passed directly to the shell() method.

TODO

Not all routines that are documented are implemented yet

Currently stdout isn't captured if wantarray

An interface to create background jobs

An interface to get input

Merge this interface with Zoidberg::Fish ?

Can builtins support both perl data and switches ?

Test script

AUTHOR

Jaap Karssenberg || Pardus [Larus] <pardus@cpan.org>

Copyright (c) 2003 Jaap G Karssenberg. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Shell, Zoidberg, http://zoidberg.sourceforge.net