Zoidberg::Shell.3pm

Langue: en

Version: 2006-02-19 (debian - 07/07/09)

Section: 3 (Bibliothèques de fonctions)

NAME

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

SYNOPSIS

         use Zoidberg::Shell;
         my $shell = Zoidberg::Shell->current();
 
 
         # 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 things like 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).

All other methods except "new" and "system" 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. This can be confusing but the idea is that methods in this package have a scripting interface, while the like named builtins have a commandline interface.

The reason the "system" can't be exported is because it would mask the perl function "system", also this method is only included so zoid's DispatchTable's can use it.

Also you can import an @JOBS from this module. The ':jobs' tag gives you both @JOBS and the "job()" method.

METHODS

Be aware: All commands are executed in the parent shell environment.

FIXME document the new export tags, document all routines better

"new()"
Simple wrapper for the constructor of the Zoidberg class.
"current()"
Returns the current Zoidberg object, which in turn inherits from this package, or undef when there is no such object.

TODO should also do ipc

"any()"
Uses the current shell if any, else starts a new one.
"system($command, @_)"
Opens a pipe to a system command and returns it's output. Intended for when you want to call a command without using zoid's parser and job management. This method has absolutely no intelligence (no expansions, builtins, etc.), you can only call external commands with it.
"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. FIXME double check this
"shell($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.
"shell([$command, @_], [..], 'AND', [..])"
Create a logic list and/or pipeline. Available tokens are 'AND', 'OR' and 'EOS' (End Of Statement, ';').

"shell()" allows for other kinds of pseudo parse trees, these can be considered as a kind of ``expert mode''. See zoiddevel(1) for more details. You might not want to use these without good reason.

"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/ );
 
 

See zoiduser(1) for a description of the several settings.

"setting($setting)"
Returns the current value for a setting.
"alias(\%aliases)"
Merge %aliases with current alias hash.
         alias( { ls => 'ls ---color=auto' } )
 
 
"unalias(@aliases)"
Delete all keys listed in @aliases from the aliases table.
"source($file)"
Run another perl script, possibly also interfacing with zoid.

FIXME more documentation on zoid's source scripts

"job($spec)"
Used to fetch a job object by its spec, for example:
         $shell->job('%-')->kill(); # kill the previous job
 
 
"AUTOLOAD"
All calls that get autoloaded are passed directly to the "shell()" method. This allows you to use nice syntax like :
         $shell->cd('..');
 
 

JOBS

FIXME splain @JOBS

TODO

An interface to create background jobs

An interface to get input

Can builtins support both perl data and switches ?

Test script

More syntactic sugar :)

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

Zoidberg, Zoidberg::Utils, <http://zoidberg.sourceforge.net>

Shell