File Coverage

lib/MooseX/Workers/Job.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             package MooseX::Workers::Job;
2              
3 17     17   189081 use Moose;
  17         1013138  
  17         116  
4             has 'ID' => ( is => 'rw', isa => 'Int' ); # POE::Wheel::Run->ID
5             has 'PID' => ( is => 'rw', isa => 'Int' ); # POE::Wheel::Run->PID
6             has 'name' => ( is => 'rw', isa => 'Str' );
7             has 'command' => ( is => 'rw', isa => 'CodeRef|Str|ArrayRef' ); # See POE::Wheel::Run POD (Program)
8             has 'args' => ( is => 'rw', isa => 'ArrayRef' ); # See POE::Wheel::Run POD (ProgramArgs)
9             has 'timeout' => ( is => 'rw', isa => 'Int' ); # abort after this many seconds
10 17     17   90993 no Moose;
  17         33  
  17         98  
11              
12              
13             =head1 NAME
14              
15             MooseX::Workers::Job - One of the jobs MooseX::Workers is running
16              
17             =head1 SYNOPSIS
18              
19             package Manager;
20             use Moose;
21             with qw(MooseX::Workers);
22              
23             sub worker_stdout {
24             my ( $self, $output, $job ) = @_;
25             printf(
26             "%s(%s,%s) said '%s'\n",
27             $job->name, $job->ID, $job->PID, $output
28             );
29             }
30             sub run {
31             foreach (qw( foo bar baz )) {
32             my $job = MooseX::Workers::Job->new(
33             name => $_,
34             command => sub { print "Hello World\n" },
35             timeout => 30,
36             );
37             $_[0]->spawn( $job );
38             }
39             POE::Kernel->run();
40             }
41             no Moose;
42              
43             Manager->new()->run();
44             # bar(2,32423) said 'Hello World'
45             # foo(1,32422) said 'Hello World'
46             # baz(3,32424) said 'Hello World'
47              
48             =head1 DESCRIPTION
49              
50             MooseX::Workers::Job objects are convenient if you want to name each
51             L<MooseX::Workers> job, or if you want them to timeout (abort)
52             after a certain number of seconds.
53              
54             =cut
55              
56              
57             1;
58