| 1 | 178 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | package Ekorn::Pipeline::Workers::Worker; | ||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | 178 | ▶ | use IO::Socket::INET (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | 178 | ▶ | use Storable (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | 178 | ▶ | use Ekorn::Pipeline; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | 178 | ▶ | use Ekorn::Pipeline::Gather (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 178 | ▶ | use Ekorn::Pipeline::Source (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 178 | ▶ | use Ekorn::Pipeline::Workers::Wire qw( | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | write_frame read_frame resolve unplaced | ||||||||||||||||||||||||||||||||||||||
| 12 | 178 | token_variable); | |||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||
| 14 | 178 | our $VERSION = 'v0.1.0'; | |||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||
| 17 | # A worker: a new perl, run as | ||||||||||||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||||||||||||
| 19 | # perl -I... -e 'require Ekorn::Pipeline::Workers::Worker; Ekorn::Pipeline::Workers::Worker::run()' PORT | ||||||||||||||||||||||||||||||||||||||
| 20 | # | ||||||||||||||||||||||||||||||||||||||
| 21 | # with its token in its environment, never on its command line, which | ||||||||||||||||||||||||||||||||||||||
| 22 | # every user of the computer can read (D16). It takes the token out of | ||||||||||||||||||||||||||||||||||||||
| 23 | # %ENV, so the block, and what it starts, never sees it. | ||||||||||||||||||||||||||||||||||||||
| 24 | # | ||||||||||||||||||||||||||||||||||||||
| 25 | # It connects to the parent, says who it is, takes its setup, loads the | ||||||||||||||||||||||||||||||||||||||
| 26 | # functions it names, runs init, and says it's ready; then takes a | ||||||||||||||||||||||||||||||||||||||
| 27 | # value, runs the block on it, and replies, until the parent closes its | ||||||||||||||||||||||||||||||||||||||
| 28 | # socket; then done. | ||||||||||||||||||||||||||||||||||||||
| 29 | # | ||||||||||||||||||||||||||||||||||||||
| 30 | # The block runs inside a run of its own, made for each value, so that | ||||||||||||||||||||||||||||||||||||||
| 31 | # Ekorn itself gives it the parent's context, through a source, and | ||||||||||||||||||||||||||||||||||||||
| 32 | # ending, by calling it from a flush when the parent was ending. The | ||||||||||||||||||||||||||||||||||||||
| 33 | # result's number and original are set by hand, in the one variable of | ||||||||||||||||||||||||||||||||||||||
| 34 | # Ekorn's that isn't lexical. A stop or an error is caught around the | ||||||||||||||||||||||||||||||||||||||
| 35 | # block, before the inner run sees it, and sent back as it was, an | ||||||||||||||||||||||||||||||||||||||
| 36 | # error object too, if it can be frozen (D13). A stop crosses as its | ||||||||||||||||||||||||||||||||||||||
| 37 | # values, which the stage throws again as an Ekorn::Pipeline::Stop; one | ||||||||||||||||||||||||||||||||||||||
| 38 | # that isn't an array carries none, as in Ekorn (D18). | ||||||||||||||||||||||||||||||||||||||
| 39 | 178 | ▶ | sub run () { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=17 SCAR=28.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 40 | 178 | my($port) = @ARGV; | |||||||||||||||||||||||||||||||||||||
| 41 | 178 | ▶ | my $token = delete $ENV{token_variable()} // ''; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $ENV{token_variable()} // ""
MC/DC0%0/1
delete $ENV{token_variable()} // ""
delete $ENV{token_variable()}
Truth table50%1/2
A
A= delete $ENV{token_variable()}
| |||||||||||||||||||||||||||||||||||||||
| 42 | 178 | ▶ | my $socket = IO::Socket::INET->new( | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 43 | PeerAddr => '127.0.0.1', PeerPort => $port, | ||||||||||||||||||||||||||||||||||||||
| 44 | Proto => 'tcp', | ||||||||||||||||||||||||||||||||||||||
| 45 | ) or die "A worker of Ekorn::Pipeline::Workers couldn't connect: $!\n"; | ||||||||||||||||||||||||||||||||||||||
| 46 | 178 | binmode $socket; | |||||||||||||||||||||||||||||||||||||
| 47 | 178 | ▶ | write_frame($socket, Storable::nfreeze([$token, $$])) or exit 2; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 48 | 178 | ▶ | my $frame = read_frame($socket) // exit 0; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
read_frame($socket) // exit 0
MC/DC0%0/1
read_frame($socket) // exit 0
read_frame($socket)
Truth table50%1/2
A
A= read_frame($socket)
| |||||||||||||||||||||||||||||||||||||||
| 49 | 178 | my $setup = Storable::thaw($frame); | |||||||||||||||||||||||||||||||||||||
| 50 | 178 | my(@state, $block, $done); | |||||||||||||||||||||||||||||||||||||
| 51 | 178 | my $ready = eval { | |||||||||||||||||||||||||||||||||||||
| 52 | 178 | ▶ | $block = resolve($setup->{block}) // die "there's no $setup->{block}\n"; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
resolve($setup->{"block"}) // die(qq[there's no $setup->{"block"}\n])
MC/DC0%0/1
resolve($setup->{"block"}) // die(qq[there's no $setup->{"block"}\n])
resolve($setup->{"block"})
Truth table50%1/2
A
A= resolve($setup->{"block"})
| |||||||||||||||||||||||||||||||||||||||
| 53 | $done = $setup->{done} | ||||||||||||||||||||||||||||||||||||||
| 54 | 178 | ▶ | && (resolve($setup->{done}) // die "there's no $setup->{done}\n"); | ||||||||||||||||||||||||||||||||||||
|
Condition60%3/5
$setup->{'done'} && (resolve($setup->{'done'}) // die("there's no $setup->{'done'}\n"))
resolve($setup->{"done"}) // die(qq[there's no $setup->{"done"}\n])
MC/DC50%1/2
$setup->{'done'} && (resolve($setup->{'done'}) // die("there's no $setup->{'done'}\n"))
$setup->{'done'}
resolve($setup->{"done"})
Truth table66%2/3
A && B
A= $setup->{'done'}B= resolve($setup->{"done"})
| |||||||||||||||||||||||||||||||||||||||
| 55 | 178 | ▶ | if ($setup->{init}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 56 | 30 | ▶ | my $init = resolve($setup->{init}) // die "there's no $setup->{init}\n"; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
resolve($setup->{"init"}) // die(qq[there's no $setup->{"init"}\n])
MC/DC0%0/1
resolve($setup->{"init"}) // die(qq[there's no $setup->{"init"}\n])
resolve($setup->{"init"})
Truth table50%1/2
A
A= resolve($setup->{"init"})
| |||||||||||||||||||||||||||||||||||||||
| 57 | 30 | @state = $init->(@{ $setup->{init_args} }); | |||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||
| 59 | 176 | 1; | |||||||||||||||||||||||||||||||||||||
| 60 | }; | ||||||||||||||||||||||||||||||||||||||
| 61 | 178 | ▶ | write_frame($socket, Storable::nfreeze($ready ? [1] : [0, "$@"])) or exit 2; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 62 | 178 | ▶ | exit 0 unless $ready; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 63 | 176 | my($value, $where, $kind, $payload); | |||||||||||||||||||||||||||||||||||||
| 64 | 337 | ▶ | my $call = sub () { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||
| 65 | 337 | my @results = eval { | |||||||||||||||||||||||||||||||||||||
| 66 | local $Ekorn::Pipeline::CURRENT_RESULT | ||||||||||||||||||||||||||||||||||||||
| 67 | = defined $where->{number} | ||||||||||||||||||||||||||||||||||||||
| 68 | 337 | ▶ | ? [$where->{number} - 1, $where->{original}] | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 69 | : undef; | ||||||||||||||||||||||||||||||||||||||
| 70 | 337 | local $_ = $value; | |||||||||||||||||||||||||||||||||||||
| 71 | 337 | $block->($value, @state); | |||||||||||||||||||||||||||||||||||||
| 72 | }; | ||||||||||||||||||||||||||||||||||||||
| 73 | 325 | ▶ | if (my $error = $@) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 74 | ($kind, $payload) | ||||||||||||||||||||||||||||||||||||||
| 75 | = ref $error && $error isa 'Ekorn::Pipeline::Stop' | ||||||||||||||||||||||||||||||||||||||
| 76 | 8 | ▶ | ? (stop => eval { [@{ $error }[1 .. $#$error]] } // []) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
ref $error and $error isa "Ekorn::Pipeline::Stop"
eval {
do {
[@{$error;}[1 .. $error->$#*]]
}
} // []
MC/DC100%2/2
ref $error and $error isa "Ekorn::Pipeline::Stop"
ref $error
$error isa "Ekorn::Pipeline::Stop"
MC/DC0%0/1
eval {
do {
[@{$error;}[1 .. $error->$#*]]
}
} // []
eval {
do {
[@{$error;}[1 .. $error->$#*]]
}
}
Truth table100%3/3
A and B
A= ref $errorB= $error isa "Ekorn::Pipeline::Stop"
Truth table50%1/2
A
A= eval {
do {
[@{$error;}[1 .. $error->$#*]]
}
}
| |||||||||||||||||||||||||||||||||||||||
| 77 | : (err => _crossing($error)); | ||||||||||||||||||||||||||||||||||||||
| 78 | 8 | return; | |||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||
| 80 | 317 | ($kind, $payload) = (ok => \@results); | |||||||||||||||||||||||||||||||||||||
| 81 | 317 | return; | |||||||||||||||||||||||||||||||||||||
| 82 | 176 | }; | |||||||||||||||||||||||||||||||||||||
| 83 | 337 | ▶ | my $stage = Ekorn::Pipeline::Gather->new(sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 84 | return ( | ||||||||||||||||||||||||||||||||||||||
| 85 | 337 | ▶ | sub { $where->{ending} ? () : $call->() }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 86 | 325 | ▶ | sub { $where->{ending} ? $call->() : () }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 87 | 337 | ); | |||||||||||||||||||||||||||||||||||||
| 88 | 176 | }); | |||||||||||||||||||||||||||||||||||||
| 89 | 337 | ▶ | my $source = Ekorn::Pipeline::Source->new(sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 90 | 337 | my $given = 0; | |||||||||||||||||||||||||||||||||||||
| 91 | 337 | ▶ | return {step => sub { $given++ ? () : 1 }, context => $where->{context}}; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 92 | 176 | }); | |||||||||||||||||||||||||||||||||||||
| 93 | 176 | my $run = Ekorn::Pipeline->new($stage); | |||||||||||||||||||||||||||||||||||||
| 94 | 176 | ▶ | while (defined(my $job = read_frame($socket))) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 95 | 337 | (my $seq, $value, $where) = @{ Storable::thaw($job) }; | |||||||||||||||||||||||||||||||||||||
| 96 | 337 | ($kind, $payload) | |||||||||||||||||||||||||||||||||||||
| 97 | = (err => "$setup->{stage} ran nothing for $setup->{what} #$seq\n"); | ||||||||||||||||||||||||||||||||||||||
| 98 | 337 | $run->iterator($source)->all; | |||||||||||||||||||||||||||||||||||||
| 99 | my $reply | ||||||||||||||||||||||||||||||||||||||
| 100 | 325 | ▶ | = eval { Storable::nfreeze([$seq, $kind, $payload]) } | ||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
eval {
do {
Storable::nfreeze([$seq, $kind, $payload])
}
} // Storable::nfreeze([$seq, "err", qq[$setup->{"stage"} can't send back the results of $setup->{"what"} #${seq}: ] . unplaced($@) . "\n"])
MC/DC0%0/2
eval {
do {
Storable::nfreeze([$seq, $kind, $payload])
}
} // Storable::nfreeze([$seq, "err", qq[$setup->{"stage"} can't send back the results of $setup->{"what"} #${seq}: ] . unplaced($@) . "\n"])
eval {
do {
Storable::nfreeze([$seq, $kind, $payload])
}
}
Storable::nfreeze([$seq, "err", qq[$setup->{"stage"} can't send back the results of $setup->{"what"} #${seq}: ] . unplaced($@) . "\n"])
Truth table66%2/3
A // B
A= eval {
do {
Storable::nfreeze([$seq, $kind, $payload])
}
}B= Storable::nfreeze([$seq, "err", qq[$setup->{"stage"} can't send back the results of $setup->{"what"} #${seq}: ] . unplaced($@) . "\n"])
| |||||||||||||||||||||||||||||||||||||||
| 101 | // Storable::nfreeze([ | ||||||||||||||||||||||||||||||||||||||
| 102 | $seq, | ||||||||||||||||||||||||||||||||||||||
| 103 | err => | ||||||||||||||||||||||||||||||||||||||
| 104 | "$setup->{stage} can't send back the results of $setup->{what} #$seq: " | ||||||||||||||||||||||||||||||||||||||
| 105 | . unplaced($@) . "\n", | ||||||||||||||||||||||||||||||||||||||
| 106 | ]); | ||||||||||||||||||||||||||||||||||||||
| 107 | 325 | ▶ | write_frame($socket, $reply) or last; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||
| 109 | 164 | ▶ | $done->(@state) if $done; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 110 | 164 | STDOUT->flush; | |||||||||||||||||||||||||||||||||||||
| 111 | 164 | STDERR->flush; | |||||||||||||||||||||||||||||||||||||
| 112 | 164 | exit 0; | |||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||
| 116 | # An error as it was, an object included, so the program can catch it | ||||||||||||||||||||||||||||||||||||||
| 117 | # as it would a plain stage's (Ekorn-Pipeline's 2026-0065, D13); one | ||||||||||||||||||||||||||||||||||||||
| 118 | # that can't be frozen, such as an object holding a handle, crosses as | ||||||||||||||||||||||||||||||||||||||
| 119 | # its message, ending in a newline, so the stage adds no line of its | ||||||||||||||||||||||||||||||||||||||
| 120 | # own. | ||||||||||||||||||||||||||||||||||||||
| 121 | 6 | ▶ | sub _crossing ($error) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_crossing: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||
| 122 | 6 | ▶ | return $error if !ref $error || eval { Storable::nfreeze([$error]); 1 }; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not ref $error or eval {
do {
Storable::nfreeze([$error]);
1
}
}
MC/DC100%2/2
not ref $error or eval {
do {
Storable::nfreeze([$error]);
1
}
}
not ref $error
eval {
do {
Storable::nfreeze([$error]);
1
}
}
Truth table100%3/3
not(A) or B
A= not ref $errorB= eval {
do {
Storable::nfreeze([$error]);
1
}
}
| |||||||||||||||||||||||||||||||||||||||
| 123 | 1 | my $message = "$error"; | |||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | return $message =~ m( \n \z )x ? $message : "$message\n"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||
| 127 | 178 | 1; | |||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||
| 129 | __END__ | ||||||||||||||||||||||||||||||||||||||