Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

README

  • Loading branch information...
commit 0b9dd555b9fa24a5589770e0744881bb07f854d5 1 parent 4ab417b
@exodist authored
Showing with 141 additions and 1 deletion.
  1. +140 −0 README
  2. +1 −1  t/Import.t
View
140 README
@@ -0,0 +1,140 @@
+NAME
+ Child - Object oriented simple interfare to fork()
+
+DESCRIPTION
+ Fork is too low level, and difficult to manage. Often people forget to
+ exit at the end, reap their children, and check exit status. The problem
+ is the low level functions provided to do these things. Throw in pipes
+ for IPC and you just have a pile of things nobody wants to think about.
+
+ Child is an Object Oriented interface to fork. It provides a clean way
+ to start a child process, and manage it afterwords. It provides methods
+ for running, waiting, killing, checking, and even communicating with a
+ child process.
+
+SYNOPSIS
+ BASIC
+ use Child;
+
+ my $child = Child->new(sub {
+ my $self = shift;
+ ....
+ # exit() is called for you at the end.
+ });
+
+ # Build with IPC
+ my $child2 = Child->new(sub {
+ my $self = shift;
+ $self->say("message1");
+ $self->say("message2");
+ my $reply = $self->read(1);
+ }, pipe => 1 );
+
+ # Read (blocking)
+ my $message1 = $child2->read(1);
+
+ # Read (non-blocking)
+ my $message2 = $child2->read();
+
+ $child2->say("responce");
+
+ # Kill the child if it is not done
+ $child->complete || $child->kill(9);
+
+ $child->wait; #blocking
+
+ SHORTCUT WITHOUT IPC
+ Child can export the child(&) shortcut function when requested. This
+ function creates and starts the child process.
+
+ use Child qw/child/;
+
+ my $child = child {
+ my $self = shift;
+ ...
+ };
+
+ SHORTCUT WITH IPC
+ To add IPC to children created with child(), import with ':pipe'. How
+ child() behaves regarding IPC is lexical to each importing class.
+
+ use Child qw/child :pipe/;
+
+ my $child = child {
+ my $self = shift;
+ $self->say("message1");
+ };
+
+ my $message1 = $child->read(1);
+
+METHODS
+ $class->new( sub { ... } )
+ $class->new( sub { ... }, pipe => 1 )
+ Create a new Child object. Does not start the child.
+
+ $child->start()
+ Start the child process.
+
+ $bool = $child->is_complete()
+ Check if the child is finished (non-blocking)
+
+ $child->wait()
+ Wait on the child (blocking)
+
+ $child->kill($SIG)
+ Send the $SIG signal to the child process.
+
+ $child->read($BLOCK)
+ Read a message from the child. Takes a single boolean argument; when
+ true the method blocks.
+
+ $child->write( @MESSAGES )
+ Send the messages to the child. works like print, you must add "\n".
+
+ $child->say( @MESSAGES )
+ Send the messages to the child. works like say, adds the seperator
+ for you (usually "\n").
+
+ $child->pid()
+ Returns the child PID (only in parent process).
+
+ $child->exit_status()
+ If the child has exited this will contain the status. NOTE: You must
+ call wait or is_complete before this field is populated.
+
+ $child->code()
+ Returns the coderef used to construct the Child.
+
+ $child->parent()
+ Returns the parent processes PID. (Only in child)
+
+HISTORY
+ Most of this was part of Parrallel::Runner intended for use in the
+ Fennec project. Fennec is being brocken into multiple parts, this is one
+ such part.
+
+FENNEC PROJECT
+ This module is part of the Fennec project. See Fennec for more details.
+ Fennec is a project to develop an extendable and powerful testing
+ framework. Together the tools that make up the Fennec framework provide
+ a potent testing environment.
+
+ The tools provided by Fennec are also useful on their own. Sometimes a
+ tool created for Fennec is useful outside the greator framework. Such
+ tools are turned into their own projects. This is one such project.
+
+ Fennec - The core framework
+ The primary Fennec project that ties them all together.
+
+AUTHORS
+ Chad Granum exodist7@gmail.com
+
+COPYRIGHT
+ Copyright (C) 2010 Chad Granum
+
+ Child is free software; Standard perl licence.
+
+ Child is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
+
View
2  t/Import.t
@@ -15,7 +15,7 @@ my $one = child( sub { 1; });
ok( !$one->ipc, "no ipc by default" );
$CLASS->import(':pipe');
-my $one = child( sub { 1; });
+$one = child( sub { 1; });
ok( $one->ipc, "ipc added" );
done_testing;

0 comments on commit 0b9dd55

Please sign in to comment.
Something went wrong with that request. Please try again.