| 1 | ######################################################################## | ||||||||||||||||||||
| 2 | # housekeeping | ||||||||||||||||||||
| 3 | ######################################################################## | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | package Parallel::Queue::Manager v4.0.2; | ||||||||||||||||||||
| 6 | 85 | ▶ | use v5.24; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 85 | ▶ | use mro qw( c3 ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 85 | ▶ | use Parallel::Queue qw( noexport ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 85 | ▶ | use mro::EVERY; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 85 | ▶ | use Carp qw( croak ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 85 | ▶ | use Scalar::Util qw( blessed reftype ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | ######################################################################## | ||||||||||||||||||||
| 17 | # package variables | ||||||||||||||||||||
| 18 | ######################################################################## | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 85 | our @CARP_NOT = ( __PACKAGE__, qw( mro mro::EVERY ) ); | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 85 | my $parent_pid = $$; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | ######################################################################## | ||||||||||||||||||||
| 25 | # methods | ||||||||||||||||||||
| 26 | ######################################################################## | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 2159 | ▶ | sub handler : lvalue | ||||||||||||||||||
|
Subroutine
handler: called CC=3 SCAR=17.3
Pod
undocumented
| |||||||||||||||||||||
| 29 | { | ||||||||||||||||||||
| 30 | 2159 | my $qmgr = shift; | |||||||||||||||||||
| 31 | 2159 | ▶ | @_ or return $qmgr->[0]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 0 | my $handler = shift; | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | ▶ | 'CODE' eq reftype $handler | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | or croak "handler: '$handler' is not CODE."; | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | $qmgr->[0] = $handler | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 4107 | ▶ | sub queue : lvalue | ||||||||||||||||||
|
Subroutine
queue: called CC=3 SCAR=11.7
Pod
undocumented
| |||||||||||||||||||||
| 42 | { | ||||||||||||||||||||
| 43 | 4107 | my $qmgr = shift; | |||||||||||||||||||
| 44 | 4107 | ▶ | @_ or return $qmgr->[1] ||= []; | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$qmgr->[1] ||= []
MC/DC100%1/1
$qmgr->[1] ||= []
$qmgr->[1]
Truth table100%2/2
A
A= $qmgr->[1]
| |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 0 | $qmgr->[1] = shift | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | sub next | ||||||||||||||||||||
| 50 | 2762 | ▶ | { | ||||||||||||||||||
|
Subroutine
next: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 51 | 2762 | my $qmgr = shift; | |||||||||||||||||||
| 52 | 2762 | my $queue = $qmgr->queue; | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | # the caller may want undef as an argument, who knows? | ||||||||||||||||||||
| 55 | # only fix is an exception to indicate no further jobs. | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 2762 | ▶ | @$queue | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | ? shift @$queue | ||||||||||||||||||||
| 59 | : die "Empty queue.\n" | ||||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | sub configure | ||||||||||||||||||||
| 63 | 500 | ▶ | { | ||||||||||||||||||
|
Subroutine
configure: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 64 | 500 | my $handler = Parallel::Queue->can( 'configure' ); | |||||||||||||||||||
| 65 | 500 | my $qmgr = shift; | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 500 | $handler->( @_, qw( noexport ) ); | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 500 | $qmgr | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | sub runqueue | ||||||||||||||||||||
| 73 | 500 | ▶ | { | ||||||||||||||||||
|
Subroutine
runqueue: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 74 | 500 | state $runq = Parallel::Queue->can( 'runqueue' ); | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 500 | $parent_pid = $$; | |||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 500 | my $qmgr = shift; | |||||||||||||||||||
| 79 | 500 | my $jobs = shift; | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | # note that the queue may already be loaded | ||||||||||||||||||||
| 82 | # from construction or previous assignment. | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 500 | ▶ | $qmgr->queue = [ @_ ] | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 85 | if @_; | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 500 | $runq->( $jobs, $qmgr ); | |||||||||||||||||||
| 88 | 422 | $qmgr | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | sub next_job | ||||||||||||||||||||
| 92 | 2762 | ▶ | { | ||||||||||||||||||
|
Subroutine
next_job: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 93 | # pull the item off the stack in the | ||||||||||||||||||||
| 94 | # parent process, not the child. ignore | ||||||||||||||||||||
| 95 | # $@, eval returning undef is sufficient | ||||||||||||||||||||
| 96 | # to end queue execution. | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 2762 | my $qmgr = shift; | |||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | eval | ||||||||||||||||||||
| 101 | 2762 | { | |||||||||||||||||||
| 102 | 2762 | my $next = $qmgr->next; | |||||||||||||||||||
| 103 | 1654 | ▶ | sub { $qmgr->handler->( $next ) } | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 104 | 2345 | } | |||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | ######################################################################## | ||||||||||||||||||||
| 108 | # object manglement | ||||||||||||||||||||
| 109 | ######################################################################## | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | sub new | ||||||||||||||||||||
| 112 | 503 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 113 | 503 | my $qmgr = &construct; | |||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 503 | $qmgr->EVERY::LAST::initialize( @_ ); | |||||||||||||||||||
| 116 | 503 | $qmgr | |||||||||||||||||||
| 117 | } | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | sub construct | ||||||||||||||||||||
| 120 | 503 | ▶ | { | ||||||||||||||||||
|
Subroutine
construct: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||
| 121 | 503 | my $proto = shift; | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 503 | ▶ | bless [], blessed $proto || $proto; | ||||||||||||||||||
|
Condition33%1/3
builtin::blessed($proto) || $proto
MC/DC0%0/2
builtin::blessed($proto) || $proto
builtin::blessed($proto)
$proto
Truth table33%1/3
A || B
A= builtin::blessed($proto)B= $proto
| |||||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | sub initialize | ||||||||||||||||||||
| 127 | 503 | ▶ | { | ||||||||||||||||||
|
Subroutine
initialize: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 128 | 503 | my $qmgr = shift; | |||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | 503 | ▶ | $qmgr->handler = shift if @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 131 | 503 | ▶ | $qmgr->queue = [ @_ ] if @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | return | ||||||||||||||||||||
| 134 | 503 | } | |||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | DESTROY | ||||||||||||||||||||
| 137 | 424 | ▶ | { | ||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 138 | 424 | my $qmgr = shift; | |||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 424 | $qmgr->EVERY::cleanup; | |||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | 424 | undef @$qmgr; | |||||||||||||||||||
| 143 | 424 | undef $qmgr; | |||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | return | ||||||||||||||||||||
| 146 | 424 | } | |||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | sub cleanup | ||||||||||||||||||||
| 149 | 424 | ▶ | { | ||||||||||||||||||
|
Subroutine
cleanup: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 150 | 424 | ▶ | if( $$ == $parent_pid ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 151 | { | ||||||||||||||||||||
| 152 | 420 | my $qmgr = shift; | |||||||||||||||||||
| 153 | 420 | my $queue = $qmgr->queue; | |||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | 420 | ▶ | say STDERR join "\n\t", "($$) Incomplete jobs:", @$queue | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 156 | if @$queue; | ||||||||||||||||||||
| 157 | } | ||||||||||||||||||||
| 158 | else | ||||||||||||||||||||
| 159 | { | ||||||||||||||||||||
| 160 | # child running individual job has nothing to | ||||||||||||||||||||
| 161 | # clean up. | ||||||||||||||||||||
| 162 | } | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | return | ||||||||||||||||||||
| 165 | 424 | } | |||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | # keep require happy | ||||||||||||||||||||
| 168 | 85 | 1 | |||||||||||||||||||
| 169 | __END__ | ||||||||||||||||||||