Hi

I am trying to use MooseX::Worker to build a manager/worker program, and 
so far I think the module has a lot of potential to simplify the building 
of such modules. 

However, I cant for the life of me work out how to 'put' (in the POE 
sense) to a child worker.

This works, but there must (or at least should) be an easier way:

#!/usr/bin/perl -w

package Manager;
use Moose;
with qw(MooseX::Workers);

sub run {
    my ($self) = @_;
    use Data::Dumper;
    my $kid = $self->spawn(sub { workerguy(@_) });
 
    #warn Dumper($self->{Engine}->{workers}),"\n";
 
    $self->{Engine}->get_worker(1)->put("hello bastard\n"); 
}

sub workerguy {
    my $self = shift;
    while (my $line = <STDIN>) {
        chomp $line;
        sleep(1);
        print "im $$, my manager said '$line'\n";
    }
}

sub worker_stdout  { my $self = shift; warn "from worker: ",$_[0],"\n"; 
                     $self->{Engine}->get_worker(1)->put("hello again\n"); 
 
                   }

no Moose;

Manager->new->run();
POE::Kernel->run();

The output of the above looks like this:
from worker: im 29283, my manager said 'hello bastard'
from worker: im 29283, my manager said ''
from worker: im 29283, my manager said 'hello again'
from worker: im 29283, my manager said ''
from worker: im 29283, my manager said 'hello again'
from worker: im 29283, my manager said ''
from worker: im 29283, my manager said 'hello again'
from worker: im 29283, my manager said ''
from worker: im 29283, my manager said 'hello again'

A few questions:
*) What if I dont want the manager to capture the workers STDERR? Maybe I 
just want that to go to terminal/shell.
*) Why is the worker being called with no message? Every second line of 
the output was called with no text.
*) Is there an easier way to iterate over workers? In particular, I want 
to know when a worker is 'ready', so I can send him more work.

Cheers,
Michael Potter
Data Extracts (dataservices.extracts)
Corporate and Data Services
Centrelink
p)   02 6131 (51)0274
f)    02 6131 (51)0444
m) 0423 467 325

**********************************************************************
IMPORTANT:  This e-mail is intended for the use of the addressee and may 
contain information that is confidential, commercially valuable or subject to 
legal or parliamentary privilege.  If you are not the intended recipient you 
are notified that any review, re-transmission, disclosure, use or dissemination 
of this communication is strictly prohibited by several Commonwealth Acts of 
Parliament.  If you have received this communication in error please notify the 
sender immediately and delete all copies of this transmission together with any 
attachments.
**********************************************************************

Reply via email to