Shell::Jobs - request for comments

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Lectori Salutem

In an effort to make the code developed for the Zoidberg shell[1] more
generally available for CPAN I am considering creating a new module by
forking off most of the shell-command-parsing and job-control code from
zoidberg. On the one hand this will force me to have a strict api
between the parser and the rest of the framework, allowing for a better
test suite, on the other hand it will make general job control and
shell-like-parsing available for perl scripts and as a base for other
perl shells.

I ask for suggestions and comments for
   A) a name for this module and
   B) how the api should work
The current working name is Shell::Jobs.
Below follows a synopsis of the api I'm thinking of:

   use Shell::Jobs qw/job @JOBS shell $JOBS/;

   # Run a shell command in the background
   #   job() creates a new background job
   my $job = job('cp ./big.tar.gz /data/backup &');
   print "Copying ...";
   while ($job->running) { print '.', sleep 3 }
   print $@ ? "\nFailed: $@" : "\n";

   # Fork a bunch of processes
   #   running code in a background job effectively forks the
   #   current process
   for (1..5) { job(\&run_child) }
   while (@JOBS) {
     print "$$_ has ended\n" unless $_->running for @JOBS;
     sleep 3;

   # The quick n dirty command shell
   #   examples on how to hook builtin commands etc. will follow once the
   #   module really exists :)
   #   shell() creates a new job, can be foreground or background
   #   $JOBS is an object that calls one method for all objects in @JOBS
   while (<STDIN>) {
     print STDERR $@ if $@;
     $JOBS->report;    # check for background jobs that have ended
   $JOBS->kill('HUP'); # cleanup remaining background jobs

Because we reuse code from zoidberg the parser will do (most) shell
parsing without depending on bash or sh, this includes things like
pipelines, redirections and command substitution.

I am aware of the existence of IPC::Run on CPAN, and although some
features will overlap the functionality won't be the same.

    Jaap Karssenberg

[1] Zoidberg (a.k.a. zoid) :
A modular Perl shell written, configured, and operated entirely in Perl.
It aspires to be a fully operational login shell with all the features
one normally expects. But it also gives direct access to Perl objects
and data structures from the command line, and allows you to run Perl
code within the scope of your command line.

Site Timeline