| 1 | 203 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Ekorn::Pipeline::Workers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Stages running a function for each value in a pool of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # workers, each a new perl, started fresh, not a clone of this one, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # talked to on a socket of its own, so they run alike on Unix and on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # Windows. As a worker is a new perl, the block is named, as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # 'Module::function', which the worker loads, never a closure; so are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # init and done. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # - in_workers($n, $block): results in the order the values came; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # - in_workers_as_ready($n, $block): results as they finish; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # - once_per($key, $n, $block, join => ...): the block run once per key, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # in the workers, each value joined with its key's results. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # All three are made on Ekorn::Pipeline::Workers::Pool, below, which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # knows nothing of order or keys: it takes values tagged by its caller, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # and gives back what each finished with, tagged. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 203 | ▶ | use B (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 203 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 203 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 203 | ▶ | use Sub::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 203 | ▶ | use Ekorn::Pipeline; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 203 | ▶ | use Ekorn::Pipeline::Context qw(kept_origin); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 203 | ▶ | use Ekorn::Pipeline::Errors (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 203 | ▶ | use Ekorn::Pipeline::Gather qw(gather); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 203 | ▶ | use Ekorn::Pipeline::Stop (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 203 | ▶ | use Ekorn::Pipeline::Workers::Pool (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 203 | ▶ | use Ekorn::Pipeline::Workers::Wire qw(resolve); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 203 | our $VERSION = 'v0.1.0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # Its whole purpose is its three stages, so all three are exported by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # default, as Futures' are (Ekorn-Pipeline's 2026-0064, D12). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 203 | our @EXPORT = qw(in_workers in_workers_as_ready once_per); ## no critic (Modules::ProhibitAutomaticExportation) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # Croak at the line that called Ekorn::Pipeline. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | our @CARP_NOT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 203 | = (@Ekorn::Pipeline::Errors::INTERNAL, 'Ekorn::Pipeline::Workers::Pool'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # For tests: the pids of every worker started, and of every worker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # reaped, with waitpid's answer, which the pool keeps: kill 0 can't say | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # on Windows, where a pid is soon another process's. A worker the pool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # killed, of which Windows leaves waitpid nothing (-1), as Perl's kill | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # there has already collected it, is put down by its pid: it's gone. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 203 | our @FORKED; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 203 | our %REAPED; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # Check the stage's arguments, and give back the block and the options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # with the block, init and done as names, which is how the pool sends | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # them to its workers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # The number of workers, checked first, as the window's default is made | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # from it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 5141 | ▶ | sub _check_n ($n) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_n: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 5141 | ▶ | croak 'Expected a number of workers of 1 or more' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $n and $n =~ / \A [1-9] \d* \z /ux
MC/DC100%2/2
defined $n and $n =~ / \A [1-9] \d* \z /ux
defined $n
$n =~ / \A [1-9] \d* \z /ux
Truth table100%3/3
A and B
A= defined $nB= $n =~ / \A [1-9] \d* \z /ux
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | unless defined $n && $n =~ m( \A [1-9] \d* \z )x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 5067 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # The options each stage takes, so that one misspelt croaks, rather | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # than giving the default (2026-0065's D19). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 203 | my %OPTIONS = map { $_ => 1 } qw(init init_args done window); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 203 | my %ONCE_PER_OPTIONS = (%OPTIONS, map { $_ => 1 } qw(join hold ordered)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 5067 | ▶ | sub _check_options ($known, %options) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_options: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 5067 | my($unknown) = sort grep { !$known->{$_} } keys %options; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 5067 | ▶ | croak "Expected no option $unknown" if defined $unknown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 4248 | for my $count (qw(window hold)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | croak "Expected $count to be a whole number" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 8314 | ▶ | if defined $options{$count} && $options{$count} !~ m( \A \d+ \z )x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $options{$count} and not $options{$count} =~ / \A \d+ \z /ux
MC/DC100%2/2
defined $options{$count} and not $options{$count} =~ / \A \d+ \z /ux
defined $options{$count}
not $options{$count} =~ / \A \d+ \z /ux
Truth table100%3/3
A and not(B)
A= defined $options{$count}B= not $options{$count} =~ / \A \d+ \z /ux
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 3975 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3901 | ▶ | sub _check_pool_args ($n, $block, $window, %options) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_pool_args: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 3901 | $block = _check_name('the function' => $block); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 2917 | ▶ | croak 'Expected a window at least the number of workers' if $window < $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 2789 | for my $part (qw(init done)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | $options{$part} = _check_name($part => $options{$part}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 5396 | ▶ | if defined $options{$part}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | croak 'Expected init_args to be an array reference' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2516 | ▶ | if defined $options{init_args} && ref $options{init_args} ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $options{"init_args"} and ref $options{"init_args"} ne "ARRAY"
MC/DC100%2/2
defined $options{"init_args"} and ref $options{"init_args"} ne "ARRAY"
defined $options{"init_args"}
ref $options{"init_args"} ne "ARRAY"
Truth table100%3/3
A and B
A= defined $options{"init_args"}B= ref $options{"init_args"} ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # Without an init, they'd be given to nothing (2026-0065's D23). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | croak 'Expected init with init_args' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 2479 | ▶ | if defined $options{init_args} && !defined $options{init}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $options{"init_args"} and not defined $options{"init"}
MC/DC100%2/2
defined $options{"init_args"} and not defined $options{"init"}
defined $options{"init_args"}
not defined $options{"init"}
Truth table100%3/3
A and not(B)
A= defined $options{"init_args"}B= not defined $options{"init"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 2297 | return ($block, %options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # A block, init or done names a function a new perl can load: as a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # string, 'Module::function', or a code reference to a named sub in a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # module, \&Module::function, which gives its name (D7, as amended). An | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # anonymous sub has no name a worker could load, and may close over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # what's only in this perl; a sub of the program's script, in main, is in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # no module a worker loads. It's loaded here too, so a name that's wrong | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # croaks as the stage is made; and a worker loads a function's module by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # the function's package, so a sub whose package wasn't loaded from a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # file of its name, defined in the program's script, or in a second | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # package of a module's file, croaks here too, rather than in every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # worker (2026-0065's D21). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 4623 | ▶ | sub _check_name ($part, $given) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_name: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 4623 | my $name = $given; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 4623 | ▶ | if (ref $given eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 980 | $name = Sub::Util::subname($given); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 980 | ▶ | croak "Expected $part to be a named sub in a module, not an anonymous one: " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | . 'a worker is a new perl, which it can\'t reach' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | if $name =~ m( :: __ANON__ \z )x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 798 | ▶ | croak "Expected $part to be a sub in a module, not the program's $name: " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | . 'a worker is a new perl, which loads modules, not the program' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | if $name =~ m( \A main :: )x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 4350 | ▶ | croak "Expected $part to be given by name, as 'Module::function', " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
ref $name or not defined $name or not $name =~ / \A \w+ (?: :: \w+ )+ \z /ux
ref $name or not defined $name
MC/DC66%2/3
ref $name or not defined $name or not $name =~ / \A \w+ (?: :: \w+ )+ \z /ux
ref $name
not defined $name
not $name =~ / \A \w+ (?: :: \w+ )+ \z /ux
Truth table75%3/4
A or not(B) or not(C)
A= ref $nameB= not defined $nameC= not $name =~ / \A \w+ (?: :: \w+ )+ \z /ux
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | . 'or as a code reference to one: a worker is a new perl, which a closure in this one can\'t reach' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | if ref $name || !defined $name || $name !~ m( \A \w+ (?: :: \w+ )+ \z )x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 4222 | my($module) = $name =~ m( \A (.+) :: \w+ \z )x; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 4222 | my $code = eval { resolve($name) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 4222 | chomp(my $why = $@); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 4222 | ▶ | croak "Expected ${part}'s module, $module, to load: $why" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $code or $why eq ""
MC/DC100%2/2
defined $code or $why eq ""
defined $code
$why eq ""
Truth table100%3/3
A or B
A= defined $codeB= $why eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | unless defined $code || $why eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 4003 | ▶ | croak "Expected $part to exist, but there's no $name" unless $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 3821 | (my $file = "$module.pm") =~ s( :: )(/)gx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 3821 | ▶ | unless ($INC{$file}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 455 | ▶ | croak "Expected $part to be a sub in a module, not the program's $name: " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$module eq "main" or B::svref_2object($code)->FILE eq $0
MC/DC100%2/2
$module eq "main" or B::svref_2object($code)->FILE eq $0
$module eq "main"
B::svref_2object($code)->FILE eq $0
Truth table100%3/3
A or B
A= $module eq "main"B= B::svref_2object($code)->FILE eq $0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | . 'a worker is a new perl, which loads modules, not the program' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | if $module eq 'main' || B::svref_2object($code)->FILE eq $0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 91 | croak "Expected $part to be in a module of its own name, $module, " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | . 'which a worker can load'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 3366 | return $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # As in_workers, but passing each value's results on as soon as they're | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # back, in the order they finish, so one slow value holds up none of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # rest. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 746 | ▶ | sub in_workers_as_ready ($n, $block, %options) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
in_workers_as_ready: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 746 | return _in_workers($n, $block, 0, %options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 3520 | ▶ | sub in_workers ($n, $block, %options) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
in_workers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 3520 | return _in_workers($n, $block, 1, %options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # Both: ordered, or as ready, which is the stage's to say, not an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # option (2026-0065's D20). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 4266 | ▶ | sub _in_workers ($n, $block, $ordered, %options) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_in_workers: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 4266 | _check_n($n); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 4192 | _check_options(\%OPTIONS, %options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 3282 | ▶ | my $window = $options{window} // 2 * $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options{"window"} // 2 * $n
MC/DC100%1/1
$options{"window"} // 2 * $n
$options{"window"}
Truth table100%2/2
A
A= $options{"window"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 3282 | ($block, %options) = _check_pool_args($n, $block, $window, %options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 1969 | ▶ | return gather { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 1969 | ▶ | my $pool = Ekorn::Pipeline::Workers::Pool->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | $n, $block, %options, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | stage => $ordered ? 'in_workers' : 'in_workers_as_ready', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1969 | my @pending; # in order: {seq, state => sent|done, kind, payload} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | my @finished; # done, in the order they finished | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1969 | my %by_seq; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1969 | my $next_seq = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 22224 | ▶ | my $collect = sub ($timeout) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 22224 | for my $reply ($pool->poll($timeout)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 12644 | my($seq, $kind, $payload) = @$reply; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 12644 | my $job = $by_seq{$seq}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 12644 | @$job{qw(state kind payload)} = ('done', $kind, $payload); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 12644 | push @finished, $job; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1969 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # The next finished job whose results may go on: ordered, the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # oldest, once it's done; unordered, the first to have finished. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | my $next_done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | = $ordered | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 35041 | ▶ | ? sub () { @pending && $pending[0]{state} eq 'done' ? $pending[0] : undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
Condition100%3/3
@pending and $pending[0]{"state"} eq "done"
MC/DC100%2/2
@pending and $pending[0]{"state"} eq "done"
@pending
$pending[0]{"state"} eq "done"
Truth table100%3/3
A and B
A= @pendingB= $pending[0]{"state"} eq "done"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 1969 | ▶ | : sub () { $finished[0] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # Take the finished jobs that may go on, adding their results to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # @$results, which a flush's takes share; a stop carries all of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # them (2026-0065's D17). An error stops the taking; it's thrown | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # once nothing this take took is left to pass on. In a flush, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # what earlier takes took is lost with it, as a flush can't pass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # values on and then die (Ekorn-Pipeline's 2026-0061). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 18328 | ▶ | my $take = sub ($results) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 18328 | my $before = @$results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 18328 | ▶ | while (my $job = $next_done->()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 12519 | ▶ | return if $job->{kind} eq 'err' && @$results > $before; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$job->{"kind"} eq "err" and @$results > $before
MC/DC100%2/2
$job->{"kind"} eq "err" and @$results > $before
$job->{"kind"} eq "err"
@$results > $before
Truth table100%3/3
A and B
A= $job->{"kind"} eq "err"B= @$results > $before
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 12512 | @pending = grep { $_ != $job } @pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 12512 | @finished = grep { $_ != $job } @finished; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 12512 | delete $by_seq{$job->{seq}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 12512 | ▶ | die $job->{payload} if $job->{kind} eq 'err'; ## no critic (ErrorHandling::RequireCarping): the worker's error as it was | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 12204 | ▶ | if ($job->{kind} eq 'stop') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 153 | @pending = @finished = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | Ekorn::Pipeline::Stop->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | @$results, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 153 | $job->{origin}->gives(@{ $job->{payload} }), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 12051 | push @$results, $job->{origin}->gives(@{ $job->{payload} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 17860 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1969 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 13823 | ▶ | my $step = sub ($value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 13823 | my $job = {seq => $next_seq++, state => 'sent', origin => kept_origin}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 13823 | push @pending, $job; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 13823 | $by_seq{$job->{seq}} = $job; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 13823 | $pool->submit($job->{seq}, $value, _where()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 13631 | $collect->(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # Wait while the window's full and nothing may go on yet. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 13631 | ▶ | $collect->(undef) while @pending >= $window && !$next_done->(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@pending >= $window and not &$next_done()
MC/DC100%2/2
@pending >= $window and not &$next_done()
@pending >= $window
not &$next_done()
Truth table100%3/3
A and not(B)
A= @pending >= $windowB= not &$next_done()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 13631 | $take->(\my @results); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 13389 | return @results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1969 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 1451 | ▶ | my $flush = sub () { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 1451 | my @results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 1451 | ▶ | while (@pending) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 4697 | ▶ | $collect->(undef) unless $next_done->(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 4697 | $take->(\@results); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 1232 | return @results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 1969 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 1836 | ▶ | my $end = sub ($how) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 1836 | $pool->shut_down($how); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 1836 | @pending = @finished = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 1836 | %by_seq = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 1969 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 1969 | return {step => $step, flush => $flush, end => $end, holds => 1}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 1769 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # The block, given each distinct key once, in the workers; each value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # passed on as join gives it, from the value and its key's results. A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # key asked for while it's still being looked up waits for that lookup, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # rather than starting another. Keys are kept, with their results, for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # the run. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 875 | ▶ | sub once_per ($key_of, $n, $block, %options) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
once_per: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 875 | _check_n($n); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 875 | _check_options(\%ONCE_PER_OPTIONS, %options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 693 | ▶ | my $window = $options{window} // 2 * $n; # keys in flight at most | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$options{"window"} // 2 * $n
MC/DC0%0/1
$options{"window"} // 2 * $n
$options{"window"}
Truth table50%1/2
A
A= $options{"window"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 693 | ▶ | my $hold = $options{hold} // 1000; # values waiting, before we wait | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options{"hold"} // 1000
MC/DC100%1/1
$options{"hold"} // 1000
$options{"hold"}
Truth table100%2/2
A
A= $options{"hold"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 693 | ▶ | my $ordered = $options{ordered} // 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options{"ordered"} // 1
MC/DC100%1/1
$options{"ordered"} // 1
$options{"ordered"}
Truth table100%2/2
A
A= $options{"ordered"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 693 | ▶ | my $join = $options{join} // sub ($value, @found) { @found }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Condition66%2/3
$options{"join"} // sub ($value, @found) {
@found;
}
MC/DC0%0/2
$options{"join"} // sub ($value, @found) {
@found;
}
$options{"join"}
sub ($value, @found) {
@found;
}
Truth table66%2/3
A // B
A= $options{"join"}B= sub ($value, @found) {
@found;
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 693 | ▶ | croak 'Expected a code reference for the key' unless ref $key_of eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 656 | ▶ | croak 'Expected a code reference to join' unless ref $join eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 619 | delete @options{qw(hold ordered join)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 619 | ($block, %options) = _check_pool_args($n, $block, $window, %options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 513 | ▶ | return gather { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 513 | my $pool = Ekorn::Pipeline::Workers::Pool->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | $n, $block, %options, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | stage => 'once_per', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | what => 'key', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 513 | my %found; # key => [kind, payload], once its lookup's back | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | my %asked; # key => 1, while its lookup's in flight | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 513 | my @waiting; # in order: [value, key] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 10524 | ▶ | my $collect = sub ($timeout) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 10524 | for my $reply ($pool->poll($timeout)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1258 | my($key, $kind, $payload) = @$reply; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1258 | $found{$key} = [$kind, $payload]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 1258 | delete $asked{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 513 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # The waiting values whose keys are back, joined, added to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | # @$results, as in_workers' take adds them: ordered, from the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # oldest, stopping at the first still waiting; unordered, all of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # them. A key's error is thrown once nothing this take joined is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # left to pass on; its stop, with all of @$results, its values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # as they were, not joined. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 10774 | ▶ | my $take = sub ($results) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 10774 | my $before = @$results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 10774 | my @still; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 10774 | ▶ | while (my $wait = shift @waiting) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 80139 | my($value, $key, $origin) = @$wait; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 80139 | my $found = $found{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 80139 | ▶ | unless ($found) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 70690 | ▶ | if ($ordered) { unshift @waiting, $wait; last } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 64961 | push @still, $wait; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 64961 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 9449 | my($kind, $payload) = @$found; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 9449 | ▶ | if ($kind eq 'err') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | if (@$results > $before) { unshift @waiting, $wait; last } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 42 | die $payload; ## no critic (ErrorHandling::RequireCarping): the worker's error as it was | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 9407 | ▶ | if ($kind eq 'stop') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 20 | @waiting = @still = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 20 | Ekorn::Pipeline::Stop->throw(@$results, $origin->gives(@$payload)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 9387 | local $_ = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 9387 | push @$results, $origin->gives($join->($value, @$payload)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 10712 | unshift @waiting, @still; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 10712 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 513 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 9734 | ▶ | my $step = sub ($value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 9734 | my $key = do { local $_ = $value; $key_of->($value) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 9734 | ▶ | croak 'Expected a key for each value, not undef' unless defined $key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 9697 | push @waiting, [$value, $key, kept_origin]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 9697 | ▶ | unless ($found{$key} || $asked{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$found{$key} or $asked{$key}
MC/DC100%2/2
$found{$key} or $asked{$key}
$found{$key}
$asked{$key}
Truth table100%3/3
A or B
A= $found{$key}B= $asked{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 1493 | $asked{$key} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1493 | $pool->submit($key, $key, _where()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 9605 | $collect->(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # Wait while the window's full of keys in flight, or too many | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # values wait behind one whose key isn't back. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | $collect->(undef) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | while %asked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | && (keys %asked >= $window | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 9605 | ▶ | || (@waiting >= $hold && !$found{$waiting[0][1]})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
%asked and keys %asked >= $window || @waiting >= $hold && !$found{$waiting[0][1]}
keys %asked >= $window or @waiting >= $hold and not $found{$waiting[0][1]}
@waiting >= $hold and not $found{$waiting[0][1]}
MC/DC75%3/4
%asked and keys %asked >= $window || @waiting >= $hold && !$found{$waiting[0][1]}
%asked
keys %asked >= $window
@waiting >= $hold
not $found{$waiting[0][1]}
Truth table80%4/5
A and B or C and not(D)
A= %askedB= keys %asked >= $windowC= @waiting >= $holdD= not $found{$waiting[0][1]}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 9605 | $take->(\my @results); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 9580 | return @results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 513 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # Take as the keys come back, so the flush gives its values in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # the order they could go on. An error after values taken here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # is thrown at the next take, and they're lost with the run: a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # flush can't pass values on and then die. A stop carries them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 344 | ▶ | my $flush = sub () { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 344 | my @results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 344 | ▶ | while (@waiting) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 1169 | $take->(\@results); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 1132 | ▶ | $collect->(undef) if @waiting; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 307 | return @results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 513 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 452 | ▶ | my $end = sub ($how) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 452 | $pool->shut_down($how); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 452 | %found = %asked = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 452 | @waiting = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 513 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 513 | return {step => $step, flush => $flush, end => $end, holds => 1}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 528 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # Where the value being given to the stage stands in its run, as the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # block would see it, run in the stage: the run's context, whether a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # flush's values are going through, and the result's number and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # original. Asking for the original calls the source's original part, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | # which a run otherwise calls only when a stage asks. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 15316 | ▶ | sub _where () { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_where: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 15316 | context => Ekorn::Pipeline::run_context(), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | ending => Ekorn::Pipeline::ending(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | number => Ekorn::Pipeline::Context::result_number(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | original => Ekorn::Pipeline::Context::result_original(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 203 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||