MooseX:...::Engine(3)
MooseX::Workers::Engine ๐
okay bestie, welcome to the MooseX:...::Engine(3) manual page (yes that's the name it's filed under, we don't make the rules ๐
) โ and no cap, this is the engine room of the whole MooseX::Workers situation. pull up a chair, we're gonna go through every single thing on this page, fr fr.
โจ NAME โจ
MooseX::Workers::Engine โ it's the workhorse for MooseX::Workers. the backbone. the main character. ๐๐
โจ SYNOPSIS โจ
here's how the parent object pulls the engine in, verbatim, don't touch a character:
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
)
],
);
see how it hands off max_workers, has_workers, num_workers, put_worker and kill_worker? that's the delegation situation. it's giving "I don't do the work, I know a girl who does" ๐โโ๏ธ
โจ DESCRIPTION โจ
so MooseX::Workers::Engine is where all the actual functionality for MooseX::Workers lives. it wraps a POE::Session and however many POE::Wheel::Run objects it needs โ as many as it needs, no fixed number, it just keeps spawning them like it's collecting Squishmallows. ๐งธ
โจ ATTRIBUTES โจ
visitorโ holds a reference to our main object so we can use the callbacks that live on it. basically it's holding the group chat contact so it can DM the main object when stuff happens. ๐ฑmax_workersโ an Integer. it's the maximum number of workers we're allowed to have. the cap. the limit. the "we're not doing more than this" boundary. ๐งworkersโ an ArrayRef ofPOE::Wheel::Runobjects, and those objects are our workers. the whole roster. the squad. ๐ซถsessionโ contains thePOE::Sessionthat controls the workers. the manager. the one with the clipboard and the headset. ๐ง
โจ METHODS โจ
yieldโ helper method that posts events to our internal manager session. fire and forget, bestie. ๐ฎcallโ helper method that calls events to our internal manager session. โ ๏ธ heads up: this one is synchronous and it will block incoming data from the children if it takes too long to return. so like, don't let it drag, okay? it's the friend who takes 45 minutes in the bathroom at a party. ๐ญset_worker($key)โ set the worker at$key.get_worker($key)โ retrieve the worker at$key.delete_worker($key)โ remove the worker atx$key. (yes. "atx". that's literally what the page says. we are not fixing it, we are respecting the lore ๐)has_workersโ check to see if we have any workers currently. this is delegated to theMooseX::Workers::Engineobject.num_workersโ return the current number of workers. also delegated to theMooseX::Workers::Engineobject.has_managerโ check to see if we have a manager session. ๐remove_managerโ remove the manager session. bye girl ๐metaโ the Metaclass forMooseX::Workers::Engine, see Moose's documentation. it's the meta one, iykyk. ๐ช
โจ EVENTS โจ
add_worker ($command)
create a POE::Wheel::Run object to handle $command. but like, how it handles $command depends entirely on what $command is, so listen up:
- if
$commandholds a scalar, it will be executed asexec($scalar). shell metacharacters will be expanded in this form. ๐ - if
$commandholds an array reference, it will be executed asexec(@$array). this form ofexec()doesn't expand shell metacharacters. - if
$commandholds 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 to its visitor object. it's basically the engine texting the visitor object constantly. ๐ซถ๐ฒ
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 toSTDOUT.worker_stderrโ called when a child prints toSTDERR.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 managing session receives a SIG CHLD event.sig_*โ called when the underlying POE Kernel receives a signal. important: this is not limited to OS signals (ie. what you'd usually handle in Perl's%SIG), so it will also accept arbitrary POE signals (sent viaPOE::Kernel->signal), but it does excludeSIGCHLD/SIGCHILD, which is instead handled bysig_childabove.
these interface methods are automatically inserted when MooseX::Worker::Engine detects that the visitor object contains any methods beginning with sig_.
signals are case-sensitive, so if you wish to handle aTERMsignal, you must define asig_TERM()method. don't be out here writingsig_term()and wondering why nothing happens bestie, it's giving lowercase betrayal ๐ญ
also note that this action is performed upon MooseX::Worker::Engine startup, so any run-time modification of the visitor object is not likely to be detected. build it at boot time or it's not happening, periodt. ๐
and that's the whole page, you ate that. ๐ฝ๏ธโจ go forth and manage your workers, you iconic little engine whisperer.
this page came to you from perl v5.42.0, dated 2025-07-25, and it lives in the User Contributed Perl Documentation. mwah, take care of her ๐๐๐ฆ
๐ฆ where this page comes from
- fedora 43: perl-MooseX-Workers 0.24-33.fc43 ยท GPL-1.0-or-later OR Artistic-1.0-Perl
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms