The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MooseX::Workers::Engine - Provide the workhorse to MooseX::Workers

SYNOPSIS

    package MooseX::Workers;
    
    has Engine => (
        isa      => 'MooseX::Workers::Engine',
        is       => 'ro',
        lazy     => 1,
        required => 1,
        default  => sub { MooseX::Workers::Engine->new( visitor => $_[0] ) },
        handles  => [
            qw(
              max_workers
              has_workers
              num_workers
              put_worker
              kill_worker
              )
        ],
    );
  

DESCRIPTION

MooseX::Workers::Engine provides the main functionality to MooseX::Workers. It wraps a POE::Session and

ATTRIBUTES

visitor

Hold a reference to our main object so we can use the callbacks on it.

max_workers

An Integer specifying the maxium number of workers we have.

workers

An ArrayRef of POE::Wheel::Run objects that are our workers.

session

Contains the POE::Session that controls the workers.

METHODS

yield

Helper method to post events to our internal manager session.

call

Helper method to call events to our internal manager session. This is synchronous and will block incoming data from the children if it takes too long to return.

set_worker($key)

Set the worker at $key

get_worker($key)

Retrieve the worker at $key

delete_worker($key)

Remove the worker atx $key

has_workers

Check to see if we have *any* workers currently. This is delegated to the MooseX::Workers::Engine object.

num_workers

Return the current number of workers. This is delegated to the MooseX::Workers::Engine object.

has_manager

Check to see if we have a manager session.

remove_manager

Remove the manager session.

meta

The Metaclass for MooseX::Workers::Engine see Moose's documentation.

EVENTS

add_worker ($command)

Create a POE::Wheel::Run object to handle $command. If $command holds a scalar, it will be executed as exec($scalar). Shell metacharacters will be expanded in this form. If $command holds an array reference, it will executed as exec(@$array). This form of exec() doesn't expand shell metacharacters. If $command holds a code reference, it will be called in the forked child process, and then the child will exit.

See POE::Wheel::Run for more details.

INTERFACE

MooseX::Worker::Engine fires the following callbacks:

worker_manager_start

Called when the managing session is started

worker_manager_stop

Called when the managing session stops

max_workers_reached

Called when we reach the maximum number of workers

worker_stdout

Called when a child prints to STDOUT

worker_stderr

Called when a child prints to STDERR

worker_error

Called when there is an error condition detected with the child.

worker_done

Called when a worker completes $command

worker_started

Called when a worker starts $command

sig_child($PID, $ret)

Called when the mangaging session recieves a SIG CHDL event

AUTHOR

Chris Prather <perigrin@cpan.org>

LICENCE AND COPYRIGHT

Copyright (c) 2007, Chris Prather <perigrin@cpan.org>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.