Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
(perl) Object oriented simple interface to fork()
Perl Perl6
tree: 0b9dd555b9

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
t
Build.PL
MANIFEST.SKIP
README

README

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.

Something went wrong with that request. Please try again.