lib/Proc/Spawner/Graph.pm

filter: Statementstmt 80.0% 252 / 315 Branchbran 43.2% 58 / 134 Conditioncond 42.3% 55 / 130 MC/DCmcdc 21.9% 16 / 73 Subroutinesub 97.7% 43 / 44 Podpod 0.0% 0 / 29 totaltotal 58.4% 424 / 725 CC 143 SCAR 53.2
CC
143
Cov
63%
to_dot
907.4
run
26.5
then
24.6
CRAP 204.1
« lib/Proc/Spawner.pm ↑ Summary lib/Proc/ShellSubset/Large.pm »
1 package Proc::Spawner::Graph;
2 551 our $VERSION = '0.13';
3 # EXPERIMENTAL. The companion of Proc::Spawner: the spawn graph, which is what gets executed. It says,
4 # for the current moment, which of our children and which of our own reads and writes use which open
5 # file, and carries on each process what to do when it ends. That reaction may start new processes,
6 # each with its own reaction, close ends, read and write; so the graph grows and shrinks as it runs.
7 #
8 # end an open file the parent keeps for its children or for its own reads and writes:
9 # { kind => 'r' | 'w' | 'file' | 'parent', fd => N, fh => HANDLE while open, n => HOLDS, what => TEXT,
10 # pipe => NAME, peer => the other half (weak) r and w
11 # mode => '<' '>' '>>' '<>' '>|', path => PATH file; parent: its access
12 # forgotten => 1 once the parent has closed it, g => the graph (weak) }
13 # 'parent': the parent's own fd N, which it never closes. The others are close-on-exec, so a
14 # child gets only what its fd table gives it. Whoever needs an end holds it (hold); the last
15 # release closes it.
16 # proc a child: { name, pid, argv => TEXT, edges => [[CHILD_FD, OP, END, KEEP], ...], on_exit => HANDLER,
17 # st => 'pending' | 'running' | 'exited N' | 'signal N' | 'lost' | 'never', after => [PROC (weak), WORD] }
18 # 'after': the process whose end led to this start (for the pictures).
19 # io Perl's own reads and writes, $g->{io} = { ID => [END, '<' or '>'] }; drawn as the process 'Perl'.
20 #
21 # HANDLER: a code ref, or [NAME, DATA...] with NAME a fully qualified sub name (its module is loaded at
22 # first use). Called from Proc::Spawner's queue, one at a time, never waiting:
23 # on_exit HANDLER->(GRAPH, PROC, WAIT STATUS or undef, DATA...)
24 # perl_read, perl_write HANDLER->(GRAPH, BYTES or undef at end of file, DATA...), HANDLER->(GRAPH, DATA...) with $! the
25 # write's error (EPIPE, ...: the rest is dropped), or 0
26 # No strong reference cycles: the graph holds its processes, a process its ends and its HANDLER (with
27 # its DATA); ends refer back only weakly. So DATA must not hold the graph: a handler gets it as an argument.
28 567 ▶use strict; use warnings; use feature 'current_sub';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
29 552 ▶use Scalar::Util qw(refaddr weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 559 ▶use Fcntl qw(F_SETFD FD_CLOEXEC F_GETFL F_SETFL O_RDONLY O_WRONLY O_RDWR O_CREAT O_TRUNC O_APPEND O_NONBLOCK S_ISFIFO);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 559 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
32 551 ▶use Proc::Spawner;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 668 ▶sub tr_ { &Proc::Spawner::tr_ }
Subroutine tr_: called CC=1 SCAR=0.0
Pod undocumented
35 551 our %OPEN = ('<' => O_RDONLY, '>' => O_WRONLY|O_CREAT|O_TRUNC, '>|' => O_WRONLY|O_CREAT|O_TRUNC,
36 '>>' => O_WRONLY|O_CREAT|O_APPEND, '<>' => O_RDWR|O_CREAT);
37 551 my %RD = ('<' => 1, '<>' => 1);
38 551 my %WR = ('>' => 1, '>>' => 1, '>|' => 1, '<>' => 1);
39  
40 550 ▶sub new { my ($class, %o) = @_; bless { procs => [], io => {}, own => {}, pipes => 0, dot => $o{dot}, pics => 0 }, $class }
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
41  
42 551 my %HANDLER;
43 837 ▶sub handler {
Subroutine handler: called CC=3 SCAR=11.0
Pod undocumented
44 834 my $n = shift;
45 551 ▶ $HANDLER{$n} //= do { no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
Condition66%2/3
$HANDLER{$n} //= do { no strict 'refs'; unless (defined &$n) { (my $m = $n) =~ s/::[^:]+\z//; $m =~ s[::][/]g; require "$m.pm"; } ; \&$n }
l!l&&r!l&&!r
2665750
MC/DC0%0/2
$HANDLER{$n} //= do { no strict 'refs'; unless (defined &$n) { (my $m = $n) =~ s/::[^:]+\z//; $m =~ s[::][/]g; require "$m.pm"; } ; \&$n }
$HANDLER{$n} do { no strict 'refs'; unless (defined &$n) { (my $m = $n) =~ s/::[^:]+\z//; $m =~ s[::][/]g; require "$m.pm"; } ; \&$n }
Truth table66%2/3
A //= B
A= $HANDLER{$n}B= do { no strict 'refs'; unless (defined &$n) { (my $m = $n) =~ s/::[^:]+\z//; $m =~ s[::][/]g; require "$m.pm"; } ; \&$n }
ABresult
1X1
011
000
46 574 ▶ unless (defined &$n) { (my $m = $n) =~ s/::[^:]+\z//; $m =~ s{::}{/}g; require "$m.pm" }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &$n) 209 366 575
47 574 \&$n } }
48 2977 ▶sub call { my ($h, @a) = @_; ref $h eq 'CODE' ? $h->(@a) : handler($h->[0])->(@a, @$h[1 .. $#$h]) }
Subroutine call: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
ref $h eq 'CODE' ? : 2694 291 2985
49  
50 # ------------------------------------------------------------------ ends
51 448 ▶sub adopt { # end $e gets the handle $fh, with one hold
Subroutine adopt: called CC=1 SCAR=0.0
Pod undocumented
52 415 my ($g, $e, $fh, $what) = @_;
53 415 Proc::Spawner::__set_cloexec(fileno $fh, 1); # also when Perl gave it an fd <= $^F (Windows: not inherited)
54 415 @$e{qw(fd fh n what)} = (fileno $fh, $fh, 1, $what); delete $e->{forgotten}; weaken($e->{g} = $g); $e }
55 159 ▶sub peers { my @e = @_; $e[0]{peer} = $e[1]; $e[1]{peer} = $e[0]; weaken($_->{peer}) for @e; @e }
Subroutine peers: called CC=2 SCAR=6.9
Pod undocumented
56 # Where /proc/self/fd cannot open a pipe end anew (no /proc: FreeBSD; RT #182479), a pipe of ours is a named FIFO,
57 # opened once more for Perl's own non-blocking writes and then unlinked: so Perl's flag never reaches the children.
58 551 our $REOPEN = -d '/proc/self/fd';
59 551 my ($FIFODIR, $FIFON);
60 7 ▶sub fifo_pipe { # (read handle, write handle, Perl's own non-blocking write handle), or () with $!
Subroutine fifo_pipe: called CC=6 SCAR=25.0
Pod undocumented
61 0 ▶ $FIFODIR //= do { require File::Temp; File::Temp::tempdir('proc-spawner-XXXXXX', TMPDIR => 1, CLEANUP => 1) };
Condition0%0/3
$FIFODIR //= do { require File::Temp; File::Temp::tempdir("proc-spawner-XXXXXX", "TMPDIR", 1, "CLEANUP", 1) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$FIFODIR //= do { require File::Temp; File::Temp::tempdir("proc-spawner-XXXXXX", "TMPDIR", 1, "CLEANUP", 1) }
$FIFODIR do { require File::Temp; File::Temp::tempdir("proc-spawner-XXXXXX", "TMPDIR", 1, "CLEANUP", 1) }
Truth table0%0/3
A //= B
A= $FIFODIRB= do { require File::Temp; File::Temp::tempdir("proc-spawner-XXXXXX", "TMPDIR", 1, "CLEANUP", 1) }
ABresult
1X1
011
000
62 8 ▶ my $p = "$FIFODIR/" . ++$FIFON; POSIX::mkfifo($p, 0600) or return;
Branch: 1 branch
BranchTrueFalseTotal
POSIX::mkfifo($p, 384) or return 0 0 0
63 8 my ($r, $w, $nb);
64 21 ▶ my $ok = sysopen($r, $p, O_RDONLY|O_NONBLOCK) && sysopen($w, $p, O_WRONLY) && sysopen($nb, $p, O_WRONLY|O_NONBLOCK);
Condition0%0/6
sysopen($r, $p, 2048) && sysopen($w, $p, 1) && sysopen($nb, $p, 2049)
!ll&&!rl&&r
000
sysopen $r, $p, 2048 and sysopen $w, $p, 1
!ll&&!rl&&r
000
MC/DC0%0/3
sysopen($r, $p, 2048) && sysopen($w, $p, 1) && sysopen($nb, $p, 2049)
sysopen $r, $p, 2048 sysopen $w, $p, 1 sysopen($nb, $p, 2049)
Truth table0%0/4
A and B && C
A= sysopen $r, $p, 2048B= sysopen $w, $p, 1C= sysopen($nb, $p, 2049)
ABCresult
0XX0
10X0
1100
1111
65 21 ▶ my $err = $!; unlink $p; $! = $err; $ok or return;
Branch: 1 branch
BranchTrueFalseTotal
$ok or return 0 0 0
66 3 fcntl($r, F_SETFL, fcntl($r, F_GETFL, 0) & ~O_NONBLOCK); # the read end as pipe(2) gives it: blocking
67 25 fcntl($nb, F_SETFD, FD_CLOEXEC); ($r, $w, $nb) }
68 165 ▶sub new_pipe { # (read end, write end)
Subroutine new_pipe: called CC=6 SCAR=19.5
Pod undocumented
69 191 my $g = shift; my ($r, $w, $nb); my $n = ++$g->{pipes};
70 166 ▶ if ($REOPEN || $Proc::Spawner::WIN) { pipe $r, $w or return } else { ($r, $w, $nb) = fifo_pipe() or return } # (Windows:
Branch: 3 branches
BranchTrueFalseTotal
if ($Proc::Spawner::Graph::REOPEN or $Proc::Spawner::WIN) { } 158 0 158
pipe $r, $w or return 158 0 158
() = fifo_pipe() or return 0 0 0
Condition33%1/3
$Proc::Spawner::Graph::REOPEN or $Proc::Spawner::WIN
l!l&&r!l&&!r
15800
MC/DC0%0/2
$Proc::Spawner::Graph::REOPEN or $Proc::Spawner::WIN
$Proc::Spawner::Graph::REOPEN $Proc::Spawner::WIN
Truth table33%1/3
A or B
A= $Proc::Spawner::Graph::REOPENB= $Proc::Spawner::WIN
ABresult
1X1
011
000
71 # the loop writes without a non-blocking flag, W5;
72 # Wine's /proc is Linux's, not Windows')
73 179 my @e = peers(map +{ kind => $_, pipe => $n }, qw(r w));
74 179 ▶ adopt($g, $e[0], $r, "pipe $n read end"); adopt($g, $e[1], $w, "pipe $n write end"); $e[1]{nbw} = $nb if $nb;
Branch: 1 branch
BranchTrueFalseTotal
if $nb 0 158 158
75 165 tr_("pipe $n: read end fd $e[0]{fd}, write end fd $e[1]{fd}"); @e }
76 103 ▶sub file_end { # the end for a file the caller opened as $fh
Subroutine file_end: called CC=1 SCAR=0.0
Pod undocumented
77 117 my ($g, $fh, $mode, $path) = @_;
78 103 my $e = adopt($g, { kind => 'file', mode => $mode, path => $path }, $fh, "file '$path' ($mode)");
79 117 tr_("open fd $e->{fd} = '$path' ($mode)"); $e }
80 1632 ▶sub parent_end { # the parent's own fd N
Subroutine parent_end: called CC=2 SCAR=6.9
Pod undocumented
81 1639 my ($g, $n) = @_;
82 1639 ▶ $g->{own}{$n} //= { kind => 'parent', fd => $n, n => 0, what => "our fd $n", mode => access($n) } }
Condition100%2/2
$g->{"own"}{$n} //= {"kind", "parent", "fd", $n, "n", 0, "what", "our fd $n", "mode", access($n)}
l!l
391614
MC/DC100%1/1
$g->{"own"}{$n} //= {"kind", "parent", "fd", $n, "n", 0, "what", "our fd $n", "mode", access($n)}
$g->{"own"}{$n}
Truth table100%2/2
A
A= $g->{"own"}{$n}
Aresult
11
00
83 1611 ▶sub access { # '<', '>' or '<>': how fd N was opened (read through a copy, so N stays untouched); Windows: '<>',
Subroutine access: called CC=5 SCAR=17.8
Pod undocumented
84 1618 ▶ return '<>' if $Proc::Spawner::WIN; # unknown (no F_GETFL; the mode is used only in traces and pictures)
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::Spawner::WIN 0 1614 1614
85 1611 ▶ my $d = POSIX::dup(shift) // return '<>';
Condition50%1/2
POSIX::dup(shift()) // (return "<>")
l!l
16140
MC/DC0%0/1
POSIX::dup(shift()) // (return "<>")
POSIX::dup(shift())
Truth table50%1/2
A
A= POSIX::dup(shift())
Aresult
11
00
86 1611 ▶ open my $h, '<&=', $d or return POSIX::close($d), '<>';
Branch: 1 branch
BranchTrueFalseTotal
open my $h, "<&=", $d or return POSIX::close($d), "<>" 1614 0 1614
87 1618 ▶ (qw(< > <>))[fcntl($h, F_GETFL, 0) & 3] // '<>' }
Condition50%1/2
("<", ">", "<>")[fcntl($h, 3, 0) & 3] // "<>"
l!l
16140
MC/DC0%0/1
("<", ">", "<>")[fcntl($h, 3, 0) & 3] // "<>"
("<", ">", "<>")[fcntl($h, 3, 0) & 3]
Truth table50%1/2
A
A= ("<", ">", "<>")[fcntl($h, 3, 0) & 3]
Aresult
11
00
88 5519 ▶sub hold { $_[0]{n}++ if $_[0] }
Subroutine hold: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 5535 2 5537
89 5927 ▶sub release {
Subroutine release: called CC=6 SCAR=18.0
Pod undocumented
90 5933 ▶ my $e = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $e = shift() or return 5957 2 5959
91 5938 ▶ return if !$e->{fh} or --$e->{n} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if not $e->{"fh"} or --$e->{"n"} > 0 5535 422 5957
Condition100%3/3
not $e->{"fh"} or --$e->{"n"} > 0
l!l&&r!l&&!r
4721814422
MC/DC100%2/2
not $e->{"fh"} or --$e->{"n"} > 0
not $e->{"fh"} --$e->{"n"} > 0
Truth table100%3/3
not(A) or B
A= not $e->{"fh"}B= --$e->{"n"} > 0
ABresult
1X1
011
000
92 421 tr_("close fd $e->{fd} ($e->{what})"); close delete $e->{fh}; $e->{forgotten} = 1;
93 421 ▶ close delete $e->{nbw} if $e->{nbw}; # Perl's own write handle of a FIFO pipe (fifo_pipe): else no end of file
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"nbw"} 0 422 422
94 421 ▶ $e->{g}->event("close $e->{what}") if $e->{g} }
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"g"} 422 0 422
95 900 ▶sub op_of { my $e = shift; { r => '<', w => '>' }->{$e->{kind}} // ($e->{mode} =~ /^(<>|<)\z/ ? "$1" : '>') }
Subroutine op_of: called CC=3 SCAR=11.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$e->{'mode'} =~ /^(<>|<)\z/ ? : 216 533 749
Condition100%2/2
{"r", "<", "w", ">"}->{$e->{"kind"}} // ($e->{"mode"} =~ /^(<>|<)\z/ ? "$1" : ">")
l!l
165749
MC/DC100%1/1
{"r", "<", "w", ">"}->{$e->{"kind"}} // ($e->{"mode"} =~ /^(<>|<)\z/ ? "$1" : ">")
{"r", "<", "w", ">"}->{$e->{"kind"}}
Truth table100%2/2
A
A= {"r", "<", "w", ">"}->{$e->{"kind"}}
Aresult
11
00
96  
97 # ------------------------------------------------------------------ processes
98 # start(PATH, ARGV, ENVP, MAP, %opt): the started process node, or undef with $!. MAP: { CHILD_FD => end,
99 # or undef for closed }; other fds are inherited as they are. %opt: on_exit => HANDLER, node => a
100 # pending node to start (a hand-written graph's), and Proc::Spawner::start's chdir, umask, sigdefault.
101 307 ▶sub start {
Subroutine start: called CC=9 SCAR=22.0
Pod undocumented
102 300 my ($g, $path, $argv, $envp, $map, %o) = @_;
103 300 my $node = delete $o{node};
104 my %fds = map +($_ => $map->{$_} && $map->{$_}{fd}), # an fd of ours under its own number: inherited
105 300 ▶ grep { my $e = $map->{$_}; !($e && $e->{kind} eq 'parent' && $e->{fd} == $_) } keys %$map;
Condition88%8/9
$map->{$_} && $map->{$_}{'fd'}
!ll&&!rl&&r
20239
$e && $e->{'kind'} eq 'parent' && $e->{'fd'} == $_
!ll&&!rl&&r
2383682
$e and $e->{"kind"} eq "parent"
!ll&&!rl&&r
2236685
MC/DC50%1/2
$map->{$_} && $map->{$_}{'fd'}
$map->{$_} $map->{$_}{'fd'}
MC/DC100%3/3
$e && $e->{'kind'} eq 'parent' && $e->{'fd'} == $_
$e $e->{"kind"} eq "parent" $e->{'fd'} == $_
Truth table66%2/3
A && B
A= $map->{$_}B= $map->{$_}{'fd'}
ABresult
0X0
100
111
Truth table100%4/4
A and B && C
A= $eB= $e->{"kind"} eq "parent"C= $e->{'fd'} == $_
ABCresult
0XX0
10X0
1100
1111
106 my $n = $node // { argv => "@$argv",
107 300 ▶ edges => [map [$_, op_of($map->{$_}), $map->{$_}], grep defined $map->{$_}, sort { $a <=> $b } keys %$map] };
Condition100%2/2
$node // {"argv", join($", @$argv), "edges", [map([$_, op_of($map->{$_}), $map->{$_}], grep(defined($map->{$_}), (sort {$a <=> $b;} keys %$map)))]}
l!l
3304
MC/DC100%1/1
$node // {"argv", join($", @$argv), "edges", [map([$_, op_of($map->{$_}), $map->{$_}], grep(defined($map->{$_}), (sort {$a <=> $b;} keys %$map)))]}
$node
Truth table100%2/2
A
A= $node
Aresult
11
00
108 301 ▶ my $pid = Proc::Spawner::start($path, $argv, $envp, \%fds, %o, on_exit => sub { exited($g, $n, shift) }) or return;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
my $pid = Proc::Spawner::start($path, $argv, $envp, \%fds, %o, "on_exit", sub { exited($g, $n, shift()); } ) or return 303 4 307
109 297 @$n{qw(pid st on_exit)} = ($pid, 'running', $o{on_exit});
110 297 ▶ $n->{name} //= "p$pid";
Condition100%2/2
$n->{"name"} //= "p$pid"
l!l
3300
MC/DC100%1/1
$n->{"name"} //= "p$pid"
$n->{"name"}
Truth table100%2/2
A
A= $n->{"name"}
Aresult
11
00
111 297 ▶ if (ref(my $c = $Proc::Spawner::CAUSE) eq 'ARRAY') { $n->{after} = [@$c]; weaken($n->{after}[0]) }
Branch: 1 branch
BranchTrueFalseTotal
if (ref(my $c = $Proc::Spawner::CAUSE) eq "ARRAY") 13 290 303
112 297 ▶ push @{$g->{procs}}, $n unless $node;
Branch: 1 branch
BranchTrueFalseTotal
unless $node 300 3 303
113 297 $g->event("start $n->{argv}"); $n }
114 285 ▶sub exited {
Subroutine exited: called CC=5 SCAR=16.6
Pod undocumented
115 292 my ($g, $n, $w) = @_;
116 292 $n->{wait} = $w;
117 292 ▶ $n->{st} = !defined $w ? 'lost' : $w & 127 ? 'signal ' . ($w & 127) : 'exited ' . ($w >> 8); # (Windows: no WIFSIGNALED)
Branch: 2 branches
BranchTrueFalseTotal
!defined($w) ? : 0 292 292
$w & 127 ? : 8 284 292
118 292 $g->event("exit $n->{argv} ($n->{st})"); $g->prune;
119 292 local $Proc::Spawner::CAUSE = [$n, $n->{st}]; # processes started by the reaction are drawn after this one
120 292 ▶ call($_, $g, $n, $w) for delete $n->{on_exit} // () }
Condition33%1/3
delete $n->{"on_exit"} // ()
l!l&&r!l&&!r
29200
MC/DC0%0/2
delete $n->{"on_exit"} // ()
delete $n->{"on_exit"} ()
Truth table33%1/3
A // B
A= delete $n->{"on_exit"}B= ()
ABresult
1X1
011
000
121  
122 # Perl's own reads and writes of an end
123 1831 ▶sub perl_read { # one read of at most $len bytes
Subroutine perl_read: called CC=1 SCAR=0.0
Pod undocumented
124 1838 my ($g, $e, $len, $h) = @_; my $id;
125 1838 ▶ $id = Proc::Spawner::on_read($e->{fd}, $len, sub { delete $g->{io}{$id}; call($h, $g, @_) });
Subroutine __ANON__: called CC=1 SCAR=0.0
126 1853 $g->{io}{$id} = [$e, '<']; $id }
127 862 ▶sub perl_write { # to a pipe or FIFO through an open file of our own, made non-blocking: the flag on the
Subroutine perl_write: called CC=6 SCAR=18.2
Pod undocumented
128 # shared one would reach the children writing to it too (L10). Linux: /proc/self/fd/N opens anew; a pipe of
129 # ours without /proc: the FIFO's handle opened for this (fifo_pipe). Otherwise (a pipe we were given, without
130 # /proc) the shared one stays blocking and takes PIPE_BUF bytes per write, which a writable pipe takes at once.
131 862 my ($g, $e, $bytes, $h) = @_; my ($id, $nb);
132 # Windows: the fd as it is (the loop writes a synchronous handle from a helper thread, W5).
133 my ($to, $chunk) = $Proc::Spawner::WIN || !S_ISFIFO((POSIX::fstat($e->{fd}))[2] // 0) ? $e->{fd} : $e->{nbw} ? $e->{nbw}
134 862 ▶ : sysopen($nb, "/proc/self/fd/$e->{fd}", O_WRONLY|O_NONBLOCK) ? $nb : ($e->{fd}, POSIX::PIPE_BUF());
Branch: 3 branches
BranchTrueFalseTotal
$Proc::Spawner::WIN || !S_ISFIFO((POSIX::fstat($e->{'fd'}))[2] // 0) ? : 31 832 863
$e->{'nbw'} ? : 0 832 832
sysopen($nb, "/proc/self/fd/$e->{'fd'}", 2049) ? : 832 0 832
Condition60%3/5
$Proc::Spawner::WIN or not S_ISFIFO((POSIX::fstat($e->{"fd"}))[2] // 0)
l!l&&r!l&&!r
031832
(POSIX::fstat($e->{"fd"}))[2] // 0
l!l
8630
MC/DC50%1/2
$Proc::Spawner::WIN or not S_ISFIFO((POSIX::fstat($e->{"fd"}))[2] // 0)
$Proc::Spawner::WIN not S_ISFIFO((POSIX::fstat($e->{"fd"}))[2] // 0)
MC/DC0%0/1
(POSIX::fstat($e->{"fd"}))[2] // 0
(POSIX::fstat($e->{"fd"}))[2]
Truth table66%2/3
A or not(B)
A= $Proc::Spawner::WINB= not S_ISFIFO((POSIX::fstat($e->{"fd"}))[2] // 0)
ABresult
1X1
011
000
Truth table50%1/2
A
A= (POSIX::fstat($e->{"fd"}))[2]
Aresult
11
00
135 861 ▶ $id = Proc::Spawner::on_write($to, $bytes, sub { my $err = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
136 862 ▶ undef $nb; delete $g->{io}{$id}; local $! = $err // 0; call($h, $g) }, $chunk);
Condition100%2/2
$err // 0
l!l
3859
MC/DC100%1/1
$err // 0
$err
Truth table100%2/2
A
A= $err
Aresult
11
00
137 862 $g->{io}{$id} = [$e, '>']; $id }
138  
139 # An ended process stays while it shares an end, or a pipe, with a process still to run or with one of
140 # our own reads and writes; then it is dropped, so a long loop does not grow the graph.
141 473 ▶sub ends_of { map +($_->[2], $_->[2]{peer} // ()), @{$_[0]{edges}} }
Subroutine ends_of: called CC=2 SCAR=7.1
Pod undocumented
Condition66%2/3
$_->[2]{"peer"} // ()
l!l&&r!l&&!r
30311330
MC/DC0%0/2
$_->[2]{"peer"} // ()
$_->[2]{"peer"} ()
Truth table66%2/3
A // B
A= $_->[2]{"peer"}B= ()
ABresult
1X1
011
000
142 285 ▶sub prune {
Subroutine prune: called CC=3 SCAR=11.0
Pod undocumented
143 285 my $g = shift; my $live = qr/^(?:pending|running)/;
144 285 ▶ my %live = map +(refaddr $_ => 1), (map ends_of($_), grep $_->{st} =~ $live, @{$g->{procs}}),
Condition66%2/3
$_->[0]{"peer"} // ()
l!l&&r!l&&!r
2420
MC/DC0%0/2
$_->[0]{"peer"} // ()
$_->[0]{"peer"} ()
Truth table66%2/3
A // B
A= $_->[0]{"peer"}B= ()
ABresult
1X1
011
000
145 285 map +($_->[0], $_->[0]{peer} // ()), values %{$g->{io}};
146 285 ▶ @{$g->{procs}} = grep $_->{st} =~ $live || grep($live{refaddr $_}, ends_of($_)), @{$g->{procs}} }
Condition100%3/3
$_->{'st'} =~ /$live/ || grep($live{builtin::refaddr($_)}, ends_of($_))
l!l&&r!l&&!r
70133277
MC/DC100%2/2
$_->{'st'} =~ /$live/ || grep($live{builtin::refaddr($_)}, ends_of($_))
$_->{'st'} =~ /$live/ grep($live{builtin::refaddr($_)}, ends_of($_))
Truth table100%3/3
A || B
A= $_->{'st'} =~ /$live/B= grep($live{builtin::refaddr($_)}, ends_of($_))
ABresult
1X1
011
000
147  
148 995 ▶sub event { # with dot => DIR: the graph now, as DIR/trace-001.dot, ...
Subroutine event: called CC=4 SCAR=25.6
Pod undocumented
149 995 ▶ my $g = shift; defined(my $dir = $g->{dot}) or return;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $dir = $g->{"dot"}) or return 0 1017 1017
150 0 my %seen; my @io = grep !$seen{refaddr $_->[0]}++, values %{$g->{io}};
151 0 my $what = join ' and ', ('reading') x !!grep($_->[1] eq '<', @io), ('writing') x !!grep($_->[1] eq '>', @io);
152 0 ▶ my @p = (@{$g->{procs}}, @io ? { name => 'Perl', argv => $what, edges => [map ['', $_->[1], $_->[0]], @io] } : ());
Branch: 1 branch
BranchTrueFalseTotal
@io ? : 0 0 0
153 0 my $f = sprintf '%s/trace-%03d.dot', $dir, ++$g->{pics};
154 0 ▶ open my $o, '>', $f or return warn "$f: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $o, ">", $f or return warn("${f}: $!\n") 0 0 0
155 0 print $o to_dot({ procs => \@p }, sprintf '%03d: %s', $g->{pics}, "@_") }
156  
157 # ------------------------------------------------------------------ the notation
158 # pipe NAME [r:forgotten] [w:forgotten] the ends NAME.r and NAME.w
159 # file NAME MODE PATH [forgotten] MODE: < > >> <> >|
160 # PROC: ARGV ... | EDGES | after PROC WORD | STATE
161 # EDGES: FD<END FD>END FD<>END, a '+' after END: drawn as 'keep'; END: NAME.r NAME.w NAME, or @N (the parent's fd N)
162 # STATE: running, exited N (drawing only); none: not started
163 # after PROC WORD: started when PROC has ended; WORD fail: if non-zero, ok: if zero, else always
164 # Perl: WHAT | <END the parent itself reading (or >END writing) an end
165 # Arguments are split at blanks; quoting is not done yet.
166 1 ▶sub parse {
Subroutine parse: called CC=19 SCAR=30.8
Pod undocumented
167 1 my (%end, @procs, @after); my $ln = 0;
168 0 ▶ my $bad = sub { die "$_[0] at line $ln\n" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
169 1 for (split /\n/, shift) {
170 6 ▶ $ln++; s/#.*//; s/^\s+|\s+$//g; next unless length;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 1 5 6
171 5 ▶ if (/^pipe (\w+)(.*)/) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^pipe (\w+)(.*)/) { } 1 4 5
elsif (/^file (\w+) (<>|>>|>\||<|>) (\S+)(?: (forgotten))?\z/) { } 1 3 4
elsif (/^(\w+): (.*)/) { } 3 0 3
172 1 ▶ my ($n, %st) = ("$1", map /^([rw]):forgotten\z/ ? ("$1", 1) : $bad->("bad pipe state '$_'"), split ' ', "$2");
Branch: 1 branch
BranchTrueFalseTotal
/^([rw]):forgotten\z/ ? : 1 0 1
173 1 @end{"$n.r", "$n.w"} = peers(map +{ kind => $_, pipe => $n }, qw(r w));
174 1 $end{"$n.$_"}{forgotten} = 1 for keys %st }
175 elsif (/^file (\w+) (<>|>>|>\||<|>) (\S+)(?: (forgotten))?\z/) {
176 1 ▶ $end{$1} = { kind => 'file', mode => "$2", path => "$3", $4 ? (forgotten => 1) : () } }
Branch: 1 branch
BranchTrueFalseTotal
$4 ? : 0 1 1
177 elsif (/^(\w+): (.*)/) {
178 3 my ($n, $argv, $edges, @rest) = ("$1", split /\s*\|\s*/, "$2");
179 3 my $p = { name => $n, argv => $argv, edges => [], st => 'pending' };
180 3 ▶ for (split ' ', $edges // '') {
Condition50%1/2
$edges // ""
l!l
30
MC/DC0%0/1
$edges // ""
$edges
Truth table50%1/2
A
A= $edges
Aresult
11
00
181 7 ▶ my ($fd, $op, $e, $keep) = /^(\d*)(<>|>>|>\||<|>)([\w.@]+)(\+?)\z/ or $bad->("bad edge '$_'");
Branch: 1 branch
BranchTrueFalseTotal
() = /^(\d*)(<>|>>|>\||<|>)([\w.\@]+)(\+?)\z/ or &$bad("bad edge '${_}'") 7 0 7
182 7 ▶ push @{$p->{edges}}, [$fd, $op, $end{$e} //= $e =~ /^@(\d+)\z/ ? { kind => 'parent', fd => "$1" }
Branch: 1 branch
BranchTrueFalseTotal
$e =~ /^@(\d+)\z/ ? : 1 0 1
Condition66%2/3
$end{$e} //= $e =~ /^@(\d+)\z/ ? {"kind", "parent", "fd", "$1"} : &$bad("unknown end '${e}'")
l!l&&r!l&&!r
610
MC/DC0%0/2
$end{$e} //= $e =~ /^@(\d+)\z/ ? {"kind", "parent", "fd", "$1"} : &$bad("unknown end '${e}'")
$end{$e} $e =~ /^@(\d+)\z/ ? {"kind", "parent", "fd", "$1"} : &$bad("unknown end '${e}'")
Truth table66%2/3
A //= B
A= $end{$e}B= $e =~ /^@(\d+)\z/ ? {"kind", "parent", "fd", "$1"} : &$bad("unknown end '${e}'")
ABresult
1X1
011
000
183 : $bad->("unknown end '$e'"), $keep] }
184 3 ▶ for (@rest) { /^after (\w+)\s*(.*)/ ? push @after, [$p, "$1", "$2"] : ($p->{st} = $_) }
Branch: 1 branch
BranchTrueFalseTotal
/^after (\w+)\s*(.*)/ ? : 1 2 3
185 3 push @procs, $p }
186 0 else { $bad->("cannot read '$_'") } }
187 1 my %byname = map +($_->{name} => $_), @procs;
188 1 ▶ for (@after) { $_->[0]{after} = [$byname{$_->[1]} // die("after: no process $_->[1]\n"), $_->[2] || 'then'];
Condition50%2/4
$byname{$_->[1]} // die("after: no process $_->[1]\n")
l!l
10
$_->[2] || 'then'
l!l
10
MC/DC0%0/1
$byname{$_->[1]} // die("after: no process $_->[1]\n")
$byname{$_->[1]}
MC/DC0%0/1
$_->[2] || 'then'
$_->[2]
Truth table50%1/2
A
A= $byname{$_->[1]}
Aresult
11
00
Truth table50%1/2
A
A= $_->[2]
Aresult
11
00
189 1 weaken($_->[0]{after}[0]) }
190 1 bless { procs => \@procs, ends => \%end, io => {}, own => {}, pipes => 0, pics => 0 } }
191  
192 # ------------------------------------------------------------------ running a hand-written graph
193 # run($g, bin => DIR): runs the parsed graph $g on the engine. Each process is started as DIR/ARGV0
194 # with its arguments and exactly its edges; one with 'after' is started by the reaction of that one,
195 # or never ('never') if WORD does not match. The parent closes its copy of an end when no process
196 # still to start uses it. Returns { PROC_NAME => status, ... } and, for 'Perl', what it read from each end.
197 1 ▶sub run {
Subroutine run: called CC=19 SCAR=32.8
Pod undocumented
198 1 my ($g, %o) = @_;
199 1 my ($perl) = grep $_->{name} eq 'Perl', @{$g->{procs}};
200 1 @{$g->{procs}} = grep $_->{name} ne 'Perl', @{$g->{procs}};
201 1 my @procs = @{$g->{procs}}; $_->{st} = 'pending' for @procs; # a state written in the notation is for drawing
202 1 ▶ my %ends = map +(refaddr $_->[2] => $_->[2]), map @{$_->{edges}}, @procs, $perl // ();
Condition33%1/3
$perl // ()
l!l&&r!l&&!r
010
MC/DC0%0/2
$perl // ()
$perl ()
Truth table33%1/3
A // B
A= $perlB= ()
ABresult
1X1
011
000
203 1 for my $e (grep $_->{kind} ne 'parent', values %ends) {
204 3 ▶ next if $e->{fh};
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"fh"} 1 2 3
205 2 ▶ if ($e->{kind} eq 'file') { sysopen my $fh, $e->{path}, $OPEN{$e->{mode}}, 0666 or die "$e->{path}: $!\n";
Branch: 2 branches
BranchTrueFalseTotal
if ($e->{'kind'} eq 'file') { } 1 1 2
sysopen my $fh, $e->{"path"}, $Proc::Spawner::Graph::OPEN{$e->{"mode"}}, 438 or die qq[$e->{"path"}: $!\n] 1 0 1
206 1 adopt($g, $e, $fh, "file $e->{path}") }
207 1 ▶ else { my ($r, $w) = $e->{kind} eq 'r' ? ($e, $e->{peer}) : ($e->{peer}, $e);
Branch: 1 branch
BranchTrueFalseTotal
$e->{'kind'} eq 'r' ? : 0 1 1
208 1 ▶ pipe my $rh, my $wh or die "pipe: $!\n"; adopt($g, $r, $rh, "pipe $r->{pipe} read end");
Branch: 1 branch
BranchTrueFalseTotal
pipe my $rh, my $wh or die "pipe: $!\n" 1 0 1
209 1 adopt($g, $w, $wh, "pipe $w->{pipe} write end") } }
210 1 ▶ hold($_->[2]) for map @{$_->{edges}}, @procs, $perl // (); # each user holds its ends; the creator lets go
Condition33%1/3
$perl // ()
l!l&&r!l&&!r
010
MC/DC0%0/2
$perl // ()
$perl ()
Truth table33%1/3
A // B
A= $perlB= ()
ABresult
1X1
011
000
211 1 ▶ my %all = map +(refaddr $_ => $_), map +($_, $_->{peer} // ()), values %ends;
Condition66%2/3
$_->{"peer"} // ()
l!l&&r!l&&!r
220
MC/DC0%0/2
$_->{"peer"} // ()
$_->{"peer"} ()
Truth table66%2/3
A // B
A= $_->{"peer"}B= ()
ABresult
1X1
011
000
212 1 release($_) for grep $_->{kind} ne 'parent', values %all;
213 1 my %got;
214 0 ▶ for my $e (map $_->[2], @{$perl ? $perl->{edges} : []}) { $got{refaddr $e} = '';
Branch: 1 branch
BranchTrueFalseTotal
$perl ? : 0 1 1
215 0 $g->perl_read($e, 65536, [__PACKAGE__ . '::collect', $e, \%got]) }
216 1 launch($g, $_, $o{bin}) for grep !$_->{after}, @procs;
217 1 ▶ Proc::Spawner::wait_until(sub { !grep($_->{st} eq 'running', @procs) && !%{$g->{io}} });
Subroutine __ANON__: called CC=2 SCAR=7.0
Condition66%2/3
grep(($_->{'st'} eq 'running'), @procs) || %{$g->{'io'};}
l!l&&r!l&&!r
701
MC/DC50%1/2
grep(($_->{'st'} eq 'running'), @procs) || %{$g->{'io'};}
grep(($_->{'st'} eq 'running'), @procs) %{$g->{'io'};}
Truth table66%2/3
A || B
A= grep(($_->{'st'} eq 'running'), @procs)B= %{$g->{'io'};}
ABresult
1X1
011
000
218 1 ▶ my %res = map +($_->{name} => ($_->{wait} >> 8 || $_->{wait} & 127)), grep defined $_->{wait}, @procs;
Condition33%1/3
$_->{'wait'} >> 8 || $_->{'wait'} & 127
l!l&&r!l&&!r
300
MC/DC0%0/2
$_->{'wait'} >> 8 || $_->{'wait'} & 127
$_->{'wait'} >> 8 $_->{'wait'} & 127
Truth table33%1/3
A || B
A= $_->{'wait'} >> 8B= $_->{'wait'} & 127
ABresult
1X1
011
000
219 0 ▶ $res{Perl} = { map +($_->[2]{pipe} // $_->[2]{path} => $got{refaddr $_->[2]}), @{$perl->{edges}} } if $perl;
Branch: 1 branch
BranchTrueFalseTotal
if $perl 0 1 1
Condition0%0/3
$_->[2]{"pipe"} // $_->[2]{"path"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_->[2]{"pipe"} // $_->[2]{"path"}
$_->[2]{"pipe"} $_->[2]{"path"}
Truth table0%0/3
A // B
A= $_->[2]{"pipe"}B= $_->[2]{"path"}
ABresult
1X1
011
000
220 1 \%res }
221 4 ▶sub launch {
Subroutine launch: called CC=3 SCAR=11.0
Pod undocumented
222 3 my ($g, $p, $bin) = @_; my ($name, @args) = split ' ', $p->{argv};
223 3 ▶ $g->start("$bin/$name", [$name, @args], undef, { map +($_->[0] => $_->[2]), @{$p->{edges}} },
Branch: 1 branch
BranchTrueFalseTotal
$g->start("$bin/$name", [$name, @args], undef, {map(($_->[0], $_->[2]), @{$$p{"edges"};})}, "node", $p, "on_exit", ["Proc::Spawner::Graph::then", $bin]) or die "spawn ${name}: $!\n" 3 0 3
224 node => $p, on_exit => [__PACKAGE__ . '::then', $bin]) or die "spawn $name: $!\n";
225 3 release($_->[2]) for @{$p->{edges}} }
226 4 ▶sub then { # on_exit of a hand-written graph's process: the processes after it
Subroutine then: called CC=11 SCAR=32.0
Pod undocumented
227 3 ▶ my ($g, $p, $w, $bin) = @_; my $st = ($w // 0) >> 8 || ($w // 0) & 127;
Condition28%2/7
($w // 0) >> 8 || ($w // 0) & 127
l!l&&r!l&&!r
300
$w // 0
l!l
30
$w // 0
l!l
00
MC/DC0%0/2
($w // 0) >> 8 || ($w // 0) & 127
$w $w
Truth table33%1/3
A || B
A= $wB= $w
ABresult
1X1
011
000
228 3 ▶ for my $q (grep $_->{st} eq 'pending' && $_->{after} && $_->{after}[0] == $p, @{$g->{procs}}) {
Condition66%4/6
$_->{'st'} eq 'pending' && $_->{'after'} && $_->{'after'}[0] == $p
!ll&&!rl&&r
501
$_->{"st"} eq "pending" and $_->{"after"}
!ll&&!rl&&r
501
MC/DC33%1/3
$_->{'st'} eq 'pending' && $_->{'after'} && $_->{'after'}[0] == $p
$_->{"st"} eq "pending" $_->{"after"} $_->{'after'}[0] == $p
Truth table50%2/4
A and B && C
A= $_->{"st"} eq "pending"B= $_->{"after"}C= $_->{'after'}[0] == $p
ABCresult
0XX0
10X0
1100
1111
229 1 my $word = $q->{after}[1];
230 1 ▶ if ($word eq 'fail' ? $st : $word eq 'ok' ? !$st : 1) { launch($g, $q, $bin) }
Branch: 3 branches
BranchTrueFalseTotal
if ($word eq 'fail' ? $st : ($word eq 'ok' ? !$st : 1)) { } 1 0 1
$word eq 'fail' ? : 1 0 1
$word eq 'ok' ? : 0 0 0
231 0 else { $q->{st} = 'never'; release($_->[2]) for @{$q->{edges}} } } }
232 1 ▶sub collect { # Perl's read of a hand-written graph's end: all of it
Subroutine collect: called CC=2 SCAR=17.9
Pod undocumented
233 0 my ($g, $b, $e, $got) = @_;
234 0 ▶ return release($e) unless defined $b;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $b 0 0 0
235 0 $got->{refaddr $e} .= $b; $g->perl_read($e, 65536, [__PACKAGE__ . '::collect', $e, $got]) }
236  
237 # ------------------------------------------------------------------ drawing
238 0 ▶sub q_ { (my $s = "@_") =~ s/([&<>"])/'&#'.ord($1).';'/ge; $s }
Subroutine q_: called CC=1 SCAR=6.9
Pod undocumented
239 0 ▶sub id { 'e' . refaddr shift }
Subroutine id: called CC=1 SCAR=6.9
Pod undocumented
240  
241 1 ▶sub to_dot { # Graphviz source for $g; $caption under the picture
Subroutine to_dot: called CC=40 SCAR=68.1
Pod undocumented
242 0 my ($g, $caption) = @_;
243 0 my @procs = @{$g->{procs}};
244 0 my %shown = map +(refaddr $_ => 1), @procs;
245 0 my @edges = map { my $p = $_; # an fd a child inherits unchanged from the parent is not drawn
246 0 ▶ [$p, grep !($_->[2]{kind} eq 'parent' && $_->[0] eq $_->[2]{fd}), @{$p->{edges}}] } @procs;
Condition0%0/3
$_->[2]{'kind'} eq 'parent' && $_->[0] eq $_->[2]{'fd'}
!ll&&!rl&&r
000
MC/DC0%0/2
$_->[2]{'kind'} eq 'parent' && $_->[0] eq $_->[2]{'fd'}
$_->[2]{'kind'} eq 'parent' $_->[0] eq $_->[2]{'fd'}
Truth table0%0/3
A && B
A= $_->[2]{'kind'} eq 'parent'B= $_->[0] eq $_->[2]{'fd'}
ABresult
0X0
100
111
247 0 my (%end, %pipe, %first);
248 0 for my $i (reverse 0 .. $#edges) { my ($p, @e) = @{$edges[$i]};
249 0 ▶ for (@e) { $end{refaddr $_->[2]} = $_->[2]; $first{refaddr $_->[2]} = $i if $RD{$_->[1]} } }
Branch: 1 branch
BranchTrueFalseTotal
if $RD{$_->[1]} 0 0 0
250 0 ▶ for my $e (values %end) { push @{$pipe{$e->{pipe}}}, $e if defined $e->{pipe} }
Branch: 1 branch
BranchTrueFalseTotal
if defined $e->{"pipe"} 0 0 0
251 0 ▶ my $dotted = sub { $_[0]{forgotten} ? 'dotted' : 'solid' };
Subroutine __ANON__: called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'forgotten'} ? : 0 0 0
252 my @L = ('digraph G {',
253 0 ▶ ' rankdir=' . ($ENV{RANKDIR} || 'LR') . '; nodesep=0.25; ranksep=0.45; bgcolor="transparent"; fontname="Helvetica";',
Branch: 1 branch
BranchTrueFalseTotal
defined $caption ? : 0 0 0
Condition0%0/2
$ENV{'RANKDIR'} || 'LR'
l!l
00
MC/DC0%0/1
$ENV{'RANKDIR'} || 'LR'
$ENV{'RANKDIR'}
Truth table0%0/2
A
A= $ENV{'RANKDIR'}
Aresult
11
00
254 ' node [fontname="Helvetica", fontsize=11, color="black", fontcolor="black"];',
255 ' edge [fontname="Helvetica", fontsize=10, color="black", fontcolor="black", arrowsize=0.7];',
256 defined $caption ? (sprintf ' label="%s"; labelloc=b; fontsize=10;', q_($caption)) : ());
257 0 for my $e (sort { refaddr $a <=> refaddr $b } grep !defined $_->{pipe}, values %end) {
258 push @L, sprintf ' %s [shape=%s, label="%s", style=%s];', id($e),
259 0 ▶ $e->{kind} eq 'parent' ? ('cds', "Perl's fd $e->{fd}") : ('note', q_("$e->{mode} $e->{path}")), $dotted->($e) }
Branch: 1 branch
BranchTrueFalseTotal
$e->{'kind'} eq 'parent' ? : 0 0 0
260 0 for my $n (sort keys %pipe) {
261 0 ▶ my %h = map +($_->{kind} => $_), map +($_, $_->{peer} // ()), @{$pipe{$n}};
Condition0%0/3
$_->{"peer"} // ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$_->{"peer"} // ()
$_->{"peer"} ()
Truth table0%0/3
A // B
A= $_->{"peer"}B= ()
ABresult
1X1
011
000
262 0 ▶ my ($r, $w) = map $h{$_} // { kind => $_, forgotten => 1 }, qw(r w); # a half nobody holds any more
Condition0%0/2
$h{$_} // {"kind", $_, "forgotten", 1}
l!l
00
MC/DC0%0/1
$h{$_} // {"kind", $_, "forgotten", 1}
$h{$_}
Truth table0%0/2
A
A= $h{$_}
Aresult
11
00
263 0 my $cid = $n =~ s/\W/_/gr;
264 0 push @L, " subgraph cluster_$cid {",
265 qq( label="pipe $n"; style="rounded,dashed"; color="#888888"; fontcolor="#888888"; fontsize=10;);
266 push @L, sprintf ' %s [shape=circle, width=0.32, fixedsize=true, label="%s", style=%s];', id($_), $_->{kind}, $dotted->($_)
267 0 for $w, $r;
268 0 push @L, sprintf(' %s -> %s [penwidth=2.2, arrowhead=none];', id($w), id($r)), ' }' }
269 0 for my $i (0 .. $#edges) {
270 0 ▶ my ($p, @e) = @{$edges[$i]}; my $pn = 'P_' . ($p->{name} =~ s/\W/_/gr); my $st = $p->{st} // 'pending';
Condition0%0/2
$p->{"st"} // "pending"
l!l
00
MC/DC0%0/1
$p->{"st"} // "pending"
$p->{"st"}
Truth table0%0/2
A
A= $p->{"st"}
Aresult
11
00
271 2 ▶ if ($p->{name} eq 'Perl') {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{'name'} eq 'Perl') { } 0 0 0
272 2 push @L, sprintf ' %s [shape=box, style="rounded,filled", fillcolor="#88888822", label="Perl: %s"];', $pn, q_($p->{argv}) }
273 else {
274 2 ▶ my @in = grep $RD{$_->[1]} && !$WR{$_->[1]}, @e; my @o = grep $WR{$_->[1]}, @e;
Condition0%0/3
$RD{$_->[1]} && !$WR{$_->[1]}
!ll&&!rl&&r
000
MC/DC0%0/2
$RD{$_->[1]} && !$WR{$_->[1]}
$RD{$_->[1]} !$WR{$_->[1]}
Truth table0%0/3
A && not(B)
A= $RD{$_->[1]}B= !$WR{$_->[1]}
ABresult
0X0
100
111
275 2 ▶ my $rows = (@in > @o ? @in : @o) || 1;
Branch: 1 branch
BranchTrueFalseTotal
@in > @o ? : 0 0 0
Condition0%0/2
(@in > @o ? @in : @o) || 1
l!l
00
MC/DC0%0/1
(@in > @o ? @in : @o) || 1
(@in > @o ? @in : @o)
Truth table0%0/2
A
A= (@in > @o ? @in : @o)
Aresult
11
00
276 1 ▶ my $cell = sub { my ($side, $x) = @_;
Subroutine __ANON__: called CC=2 SCAR=10.5
277 0 ▶ $x ? qq{<TD PORT="$side$x->[0]" BORDER="1" CELLPADDING="2">$x->[0]</TD>} : '<TD></TD>' };
Branch: 1 branch
BranchTrueFalseTotal
$x ? : 0 0 0
278 2 my $ended = $st !~ /^(pending|running|never)/;
279 1 ▶ my $mid = q_($p->{argv}) . ($st ne 'pending' ? '<BR/><FONT POINT-SIZE="9">' . q_($st) . '</FONT>' : '');
Branch: 1 branch
BranchTrueFalseTotal
$st ne 'pending' ? : 0 0 0
280 1 ▶ my $html = '<TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0"' . ($ended ? ' BGCOLOR="#88888833"' : '') . '>';
Branch: 1 branch
BranchTrueFalseTotal
$ended ? : 0 0 0
281 $html .= '<TR>' . $cell->(i => $in[$_]) . ($_ ? '' : qq{<TD ROWSPAN="$rows" CELLPADDING="5">$mid</TD>})
282 1 ▶ . $cell->(o => $o[$_]) . '</TR>' for 0 .. $rows - 1;
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
283 push @L, sprintf ' %s [shape=box, style=%s, margin=0, label=<%s</TABLE>>];', $pn,
284 1 ▶ { pending => 'dashed', never => 'dashed', running => 'bold' }->{$st} // 'solid', $html }
Condition0%0/2
{"pending", "dashed", "never", "dashed", "running", "bold"}->{$st} // "solid"
l!l
00
MC/DC0%0/1
{"pending", "dashed", "never", "dashed", "running", "bold"}->{$st} // "solid"
{"pending", "dashed", "never", "dashed", "running", "bold"}->{$st}
Truth table0%0/2
A
A= {"pending", "dashed", "never", "dashed", "running", "bold"}->{$st}
Aresult
11
00
285 1 for (@e) {
286 1 my ($fd, $op, $e, $keep) = @$_;
287 1 ▶ my $k = $keep ? ', color="#2b7bb9", penwidth=2.2, label="keep", fontcolor="#2b7bb9"' : '';
Branch: 1 branch
BranchTrueFalseTotal
$keep ? : 0 0 0
288 # a write into a pipe read by an earlier process closes a loop: drawn without pulling the layout
289 1 ▶ $k .= ', constraint=false' if $e->{kind} eq 'w' && $e->{peer} && ($first{refaddr $e->{peer}} // 1e9) < $i;
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"kind"} eq "w" and $e->{"peer"} and ($first{builtin::refaddr($e->{"peer"})} // "1000000000") < $i 0 0 0
Condition0%0/8
$e->{"kind"} eq "w" and $e->{"peer"} and ($first{builtin::refaddr($e->{"peer"})} // "1000000000") < $i
!ll&&!rl&&r
000
$e->{"kind"} eq "w" and $e->{"peer"}
!ll&&!rl&&r
000
$first{builtin::refaddr($e->{"peer"})} // "1000000000"
l!l
00
MC/DC0%0/3
$e->{"kind"} eq "w" and $e->{"peer"} and ($first{builtin::refaddr($e->{"peer"})} // "1000000000") < $i
$e->{"kind"} eq "w" $e->{"peer"} $first{builtin::refaddr($e->{"peer"})}
Truth table0%0/4
A and B and C
A= $e->{"kind"} eq "w"B= $e->{"peer"}C= $first{builtin::refaddr($e->{"peer"})}
ABCresult
0XX0
10X0
1100
1111
290 1 my $id = id($e);
291 push @L, $fd eq '' ? ($RD{$op} ? " $id -> $pn [style=bold$k];" : " $pn -> $id [style=bold$k];")
292 : !$WR{$op} ? " $id -> $pn:i$fd:w [arrowhead=normal$k];"
293 1 ▶ : " $pn:o$fd:e -> $id [" . ($RD{$op} ? 'dir=both' : 'arrowhead=normal') . "$k];" }
Branch: 4 branches
BranchTrueFalseTotal
$fd eq '' ? : 0 0 0
$RD{$op} ? : 0 0 0
!$WR{$op} ? : 0 0 0
$RD{$op} ? : 0 0 0
294 1 ▶ if (my ($q, $word) = @{$p->{after} // []}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = @{$p->{"after"} // [];}) 0 0 0
Condition0%0/2
$p->{"after"} // []
l!l
00
MC/DC0%0/1
$p->{"after"} // []
$p->{"after"}
Truth table0%0/2
A
A= $p->{"after"}
Aresult
11
00
295 push @L, sprintf ' P_%s -> %s [style=dashed, color="#c07000", fontcolor="#c07000", label="%s", constraint=false];',
296 1 ▶ $q->{name} =~ s/\W/_/gr, $pn, q_($word) if $q && $shown{refaddr $q} } }
Branch: 1 branch
BranchTrueFalseTotal
if $q and $shown{builtin::refaddr($q)} 0 0 0
Condition0%0/3
$q and $shown{builtin::refaddr($q)}
!ll&&!rl&&r
000
MC/DC0%0/2
$q and $shown{builtin::refaddr($q)}
$q $shown{builtin::refaddr($q)}
Truth table0%0/3
A and B
A= $qB= $shown{builtin::refaddr($q)}
ABresult
0X0
100
111
297 1 join '', map "$_\n", @L, '}' }
298  
299 551 1;
« lib/Proc/Spawner.pm ↑ Summary lib/Proc/ShellSubset/Large.pm »