| 1 | package IPC::Manager::Service::State; | ||||||||||||||||||||||||||||||||||
| 2 | 454 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | 454 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | 454 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 454 | ▶ | use IPC::Manager::Util qw/require_mod clone_io/; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 454 | ▶ | use IPC::Manager::Serializer::JSON(); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 454 | ▶ | use Long::Jump qw/setjump longjump havejump/; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | 454 | ▶ | use POSIX(); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 454 | my $base_0 = $0; | |||||||||||||||||||||||||||||||||
| 13 | 454 | my $service_inst; | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | my $_post_exec_run = sub { 255 }; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | sub import { | ||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||
|
Subroutine
import: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | 0 | my $json = shift @ARGV; | |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | 0 | my $params = IPC::Manager::Serializer::JSON->deserialize($json); | |||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my $exec = delete $params->{exec} // {}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $params->{"exec"} // {}
MC/DC0%0/1
delete $params->{"exec"} // {}
delete $params->{"exec"}
Truth table0%0/2
A
A= delete $params->{"exec"}
| |||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | $params->{orig_io} = { | ||||||||||||||||||||||||||||||||||
| 26 | 0 | stderr => clone_io('>&', \*STDERR), | |||||||||||||||||||||||||||||||||
| 27 | stdout => clone_io('>&', \*STDOUT), | ||||||||||||||||||||||||||||||||||
| 28 | stdin => clone_io('<&', \*STDIN), | ||||||||||||||||||||||||||||||||||
| 29 | }; | ||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my $svc_class = require_mod($params->{class} // 'IPC::Manager::Service'); | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$params->{"class"} // "IPC::Manager::Service"
MC/DC0%0/1
$params->{"class"} // "IPC::Manager::Service"
$params->{"class"}
Truth table0%0/2
A
A= $params->{"class"}
| |||||||||||||||||||||||||||||||||||
| 32 | 0 | my $new_inst = $svc_class->new(%$params); | |||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | 0 | my $exit; | |||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my $code = sub { _ipcm_service(%$params, new_inst => $new_inst); $exit = 0 }; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ($exec->{stay_in_begin}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 38 | 0 | $exit = 255; | |||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $_post_exec_run = sub { $exit }; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 40 | 0 | $code->(); | |||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||
| 42 | else { | ||||||||||||||||||||||||||||||||||
| 43 | 0 | $_post_exec_run = $code; | |||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | sub ipcm_worker { | ||||||||||||||||||||||||||||||||||
| 48 | 16 | ▶ | my ($name, $cb) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
ipcm_worker: called CC=6 SCAR=19.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | 16 | ▶ | croak "ipcm_service_worker() can only be called from inside a service" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$service_inst and ref $service_inst ne "CODE"
MC/DC0%0/2
$service_inst and ref $service_inst ne "CODE"
$service_inst
ref $service_inst ne "CODE"
Truth table33%1/3
A and B
A= $service_instB= ref $service_inst ne "CODE"
| |||||||||||||||||||||||||||||||||||
| 51 | unless $service_inst && ref($service_inst) ne 'CODE'; | ||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | 16 | ▶ | my $pid = fork // die "Could not fork: $!"; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
fork // die("Could not fork: $!")
MC/DC0%0/1
fork // die("Could not fork: $!")
fork
Truth table50%1/2
A
A= fork
| |||||||||||||||||||||||||||||||||||
| 54 | 16 | ▶ | if ($pid) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 55 | 12 | $service_inst->register_worker($name => $pid); | |||||||||||||||||||||||||||||||||
| 56 | 12 | return $pid; | |||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | 4 | $0 = "$0 $name"; | |||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||
| 61 | 4 | $service_inst = $cb; | |||||||||||||||||||||||||||||||||
| 62 | 4 | ▶ | croak "ipcm_worker: no IPCM_SERVICE jump point on the stack (worker invoked outside a running service?)" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 63 | unless havejump 'IPCM_SERVICE'; | ||||||||||||||||||||||||||||||||||
| 64 | 4 | longjump IPCM_SERVICE => (); | |||||||||||||||||||||||||||||||||
| 65 | 0 | die "This should not be reachable"; | |||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | sub ipcm_service { | ||||||||||||||||||||||||||||||||||
| 69 | 268 | ▶ | my ($name, @args) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
ipcm_service: called CC=34 SCAR=41.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | 268 | ▶ | my $return_handle = defined(wantarray) ? 1 : 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | 268 | my %params; | |||||||||||||||||||||||||||||||||
| 74 | 268 | ▶ | if (@args == 1 && ref($args[0]) eq 'CODE') { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
@args == 1 and ref $args[0] eq "CODE"
MC/DC50%1/2
@args == 1 and ref $args[0] eq "CODE"
@args == 1
ref $args[0] eq "CODE"
Truth table66%2/3
A and B
A= @args == 1B= ref $args[0] eq "CODE"
| |||||||||||||||||||||||||||||||||||
| 75 | 16 | $params{class} = 'IPC::Manager::Service'; | |||||||||||||||||||||||||||||||||
| 76 | 16 | $params{on_all} = $args[0]; | |||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||
| 78 | ▶ | elsif (@args == 2 && ref($args[0]) eq 'HASH' && ref($args[1]) eq 'CODE') { | |||||||||||||||||||||||||||||||||
|
Condition33%2/6
@args == 2 and ref $args[0] eq "HASH" and ref $args[1] eq "CODE"
@args == 2 and ref $args[0] eq "HASH"
MC/DC0%0/3
@args == 2 and ref $args[0] eq "HASH" and ref $args[1] eq "CODE"
@args == 2
ref $args[0] eq "HASH"
ref $args[1] eq "CODE"
Truth table25%1/4
A and B and C
A= @args == 2B= ref $args[0] eq "HASH"C= ref $args[1] eq "CODE"
| |||||||||||||||||||||||||||||||||||
| 79 | 0 | %params = %{$args[0]}; | |||||||||||||||||||||||||||||||||
| 80 | 0 | $params{class} = 'IPC::Manager::Service'; | |||||||||||||||||||||||||||||||||
| 81 | 0 | $params{on_all} = $args[1]; | |||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||
| 83 | else { | ||||||||||||||||||||||||||||||||||
| 84 | 252 | %params = @args; | |||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | 268 | my $skip_role_checks = delete $params{skip_role_checks}; | |||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | 268 | my $exec = delete $params{exec}; | |||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||
| 91 | 268 | $params{name} = $name; | |||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||
| 93 | 268 | ▶ | $params{orig_io} //= $service_inst ? $service_inst->orig_io : { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$params{"orig_io"} //= $service_inst ? $service_inst->orig_io : {"stderr", clone_io(">&", \*STDERR), "stdout", clone_io(">&", \*STDOUT), "stdin", clone_io("<&", \*STDIN)}
MC/DC0%0/2
$params{"orig_io"} //= $service_inst ? $service_inst->orig_io : {"stderr", clone_io(">&", \*STDERR), "stdout", clone_io(">&", \*STDOUT), "stdin", clone_io("<&", \*STDIN)}
$params{"orig_io"}
$service_inst ? $service_inst->orig_io : {"stderr", clone_io(">&", \*STDERR), "stdout", clone_io(">&", \*STDOUT), "stdin", clone_io("<&", \*STDIN)}
Truth table33%1/3
A //= B
A= $params{"orig_io"}B= $service_inst ? $service_inst->orig_io : {"stderr", clone_io(">&", \*STDERR), "stdout", clone_io(">&", \*STDOUT), "stdin", clone_io("<&", \*STDIN)}
| |||||||||||||||||||||||||||||||||||
| 94 | stderr => clone_io('>&', \*STDERR), | ||||||||||||||||||||||||||||||||||
| 95 | stdout => clone_io('>&', \*STDOUT), | ||||||||||||||||||||||||||||||||||
| 96 | stdin => clone_io('<&', \*STDIN), | ||||||||||||||||||||||||||||||||||
| 97 | } unless $exec; | ||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | 268 | ▶ | if ($service_inst && !$params{redirect}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$service_inst and not $params{"redirect"}
MC/DC50%1/2
$service_inst and not $params{"redirect"}
$service_inst
not $params{"redirect"}
Truth table66%2/3
A and not(B)
A= $service_instB= not $params{"redirect"}
| |||||||||||||||||||||||||||||||||||
| 100 | 16 | ▶ | if (my $redir = $service_inst->redirect) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $params{redirect} = $redir unless defined($redir->{inherit}) && !$redir->{inherit}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $redir->{"inherit"} and not $redir->{"inherit"}
MC/DC0%0/2
defined $redir->{"inherit"} and not $redir->{"inherit"}
defined $redir->{"inherit"}
not $redir->{"inherit"}
Truth table0%0/3
A and not(B)
A= defined $redir->{"inherit"}B= not $redir->{"inherit"}
| |||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||
| 105 | 268 | my $new_ipcm = delete $params{new_ipcm}; | |||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||
| 107 | 268 | ▶ | my $handle_params = delete $params{handle_params} // {}; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $params{"handle_params"} // {}
MC/DC0%0/1
delete $params{"handle_params"} // {}
delete $params{"handle_params"}
Truth table50%1/2
A
A= delete $params{"handle_params"}
| |||||||||||||||||||||||||||||||||||
| 108 | 268 | ▶ | if ($params{ipcm_info}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | croak "'new_ipcm' and 'ipcm_info' may not be combined" if $new_ipcm; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||||||||
| 112 | 268 | ▶ | if ($service_inst && !$new_ipcm) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$service_inst and not $new_ipcm
MC/DC50%1/2
$service_inst and not $new_ipcm
$service_inst
not $new_ipcm
Truth table66%2/3
A and not(B)
A= $service_instB= not $new_ipcm
| |||||||||||||||||||||||||||||||||||
| 113 | 16 | $handle_params->{_peer} = 1; | |||||||||||||||||||||||||||||||||
| 114 | 16 | $params{ipcm_info} = $service_inst->ipcm_info; | |||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||
| 116 | elsif ($return_handle) { | ||||||||||||||||||||||||||||||||||
| 117 | 252 | require IPC::Manager; | |||||||||||||||||||||||||||||||||
| 118 | 252 | $handle_params->{spawn} = IPC::Manager::ipcm_spawn(); | |||||||||||||||||||||||||||||||||
| 119 | 252 | $params{ipcm_info} = $handle_params->{spawn}->info; | |||||||||||||||||||||||||||||||||
| 120 | 252 | $params{watch_pids} = [$$]; | |||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||
| 122 | else { | ||||||||||||||||||||||||||||||||||
| 123 | 0 | croak "Cannot be called in void context without providing 'ipcm_info'"; | |||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||
| 127 | 268 | ▶ | my $class = require_mod($params{class} // 'IPC::Manager::Service'); | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$params{"class"} // "IPC::Manager::Service"
MC/DC0%0/1
$params{"class"} // "IPC::Manager::Service"
$params{"class"}
Truth table50%1/2
A
A= $params{"class"}
| |||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||
| 129 | 268 | ▶ | croak "'$class' does not implement the 'IPC::Manager::Role::Service' role" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$skip_role_checks or Role::Tiny::does_role($class, "IPC::Manager::Role::Service")
MC/DC0%0/2
$skip_role_checks or Role::Tiny::does_role($class, "IPC::Manager::Role::Service")
$skip_role_checks
Role::Tiny::does_role($class, "IPC::Manager::Role::Service")
Truth table33%1/3
A or B
A= $skip_role_checksB= Role::Tiny::does_role($class, "IPC::Manager::Role::Service")
| |||||||||||||||||||||||||||||||||||
| 130 | unless $skip_role_checks || Role::Tiny::does_role($class, 'IPC::Manager::Role::Service'); | ||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | 268 | my $new_inst = $class->new(%params); | |||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||
| 134 | 268 | $new_inst->pre_fork_hook(); | |||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | 268 | ▶ | $exec->{json} = IPC::Manager::Serializer::JSON->serialize(\%params) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 137 | if $exec; | ||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||
| 139 | 268 | ▶ | my $pid = fork // die "Could not fork: $!"; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
fork // die("Could not fork: $!")
MC/DC0%0/1
fork // die("Could not fork: $!")
fork
Truth table50%1/2
A
A= fork
| |||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||
| 141 | # In parent | ||||||||||||||||||||||||||||||||||
| 142 | 268 | ▶ | if ($pid) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 143 | 148 | ▶ | return unless $return_handle || $exec; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$return_handle or $exec
MC/DC50%1/2
$return_handle or $exec
$return_handle
$exec
Truth table66%2/3
A or B
A= $return_handleB= $exec
| |||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||
| 145 | 144 | my $out; | |||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||
| 147 | 144 | ▶ | if (delete $handle_params->{_peer}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 148 | 4 | $out = $service_inst->peer($params{name}, %$handle_params); | |||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||
| 150 | else { | ||||||||||||||||||||||||||||||||||
| 151 | 140 | $out = $new_inst->handle(%$handle_params, name => "service_parent_$$"); | |||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||
| 154 | 144 | ▶ | my $timeout = $params{timeout} || 10; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$params{'timeout'} || 10
MC/DC0%0/1
$params{'timeout'} || 10
$params{'timeout'}
Truth table50%1/2
A
A= $params{'timeout'}
| |||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | 144 | ▶ | croak "Timeout waiting for service to come up after ${timeout}s" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 157 | unless $out->ready($timeout); | ||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||
| 159 | 144 | $out->_set_child_pid($pid); | |||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||
| 161 | 144 | return $out; | |||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||
| 164 | 120 | $new_inst->post_fork_hook(); | |||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||
| 166 | 120 | ▶ | if ($exec) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 167 | 4 | ▶ | my $cmd = $exec->{cmd} // []; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$exec->{"cmd"} // []
MC/DC0%0/1
$exec->{"cmd"} // []
$exec->{"cmd"}
Truth table50%1/2
A
A= $exec->{"cmd"}
| |||||||||||||||||||||||||||||||||||
| 168 | 4 | my $json = $exec->{json}; | |||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||
| 170 | exec( | ||||||||||||||||||||||||||||||||||
| 171 | $^X, | ||||||||||||||||||||||||||||||||||
| 172 | 4 | @{$cmd}, | |||||||||||||||||||||||||||||||||
| 173 | 4 | "-M${ \__PACKAGE__ }", | |||||||||||||||||||||||||||||||||
| 174 | 4 | "-e" => "exit(${ \__PACKAGE__ }\::_post_exec_run())", | |||||||||||||||||||||||||||||||||
| 175 | $json, | ||||||||||||||||||||||||||||||||||
| 176 | ); | ||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||
| 179 | 116 | @_ = (%params, new_inst => $new_inst); | |||||||||||||||||||||||||||||||||
| 180 | 116 | goto \&_ipcm_service; | |||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | sub _post_exec_run { $_post_exec_run->() } | ||||||||||||||||||||||||||||||||
|
Subroutine
_post_exec_run: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||
| 185 | sub _ipcm_service { | ||||||||||||||||||||||||||||||||||
| 186 | 116 | ▶ | my %params = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_ipcm_service: called CC=6 SCAR=20.0
| |||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||
| 188 | 116 | my $name = $params{name}; | |||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||
| 190 | 116 | my $new_inst = delete $params{new_inst}; | |||||||||||||||||||||||||||||||||
| 191 | 116 | $new_inst->set_pid($$); | |||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||
| 193 | 116 | ▶ | $0 = delete($params{rebase_0}) ? "$base_0 $name" : "$0 $name"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||
| 195 | # Figure out if we already had a service | ||||||||||||||||||||||||||||||||||
| 196 | 116 | ▶ | my $prev_service = $service_inst ? 1 : 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||
| 198 | # Set the new instance as the current one | ||||||||||||||||||||||||||||||||||
| 199 | 116 | $service_inst = $new_inst; | |||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||
| 201 | # If a service is already running on the stack, unwind back to its | ||||||||||||||||||||||||||||||||||
| 202 | # setjump so the new $service_inst replaces it rather than nesting | ||||||||||||||||||||||||||||||||||
| 203 | # another run loop on top. | ||||||||||||||||||||||||||||||||||
| 204 | 116 | ▶ | if ($prev_service) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 205 | 8 | ▶ | croak "ipcm_service: previous service detected but no IPCM_SERVICE jump point on the stack" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 206 | unless havejump 'IPCM_SERVICE'; | ||||||||||||||||||||||||||||||||||
| 207 | 8 | longjump IPCM_SERVICE => (); | |||||||||||||||||||||||||||||||||
| 208 | 0 | die "This should not be reachable"; | |||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||
| 211 | # Top-level service: enter the setjump loop. ipcm_worker and nested | ||||||||||||||||||||||||||||||||||
| 212 | # ipcm_service() calls from inside the running service both unwind | ||||||||||||||||||||||||||||||||||
| 213 | # back here via `longjump IPCM_SERVICE`, after which the loop re-runs | ||||||||||||||||||||||||||||||||||
| 214 | # setjump() with $service_inst pointing at the replacement. | ||||||||||||||||||||||||||||||||||
| 215 | 108 | while (1) { | |||||||||||||||||||||||||||||||||
| 216 | my $jumped = setjump IPCM_SERVICE => sub { | ||||||||||||||||||||||||||||||||||
| 217 | # Snapshot: $service_inst can be replaced before this block exits. | ||||||||||||||||||||||||||||||||||
| 218 | 120 | ▶ | my $using_service = $service_inst; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=24.0
| |||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||
| 220 | 120 | ▶ | my $do_posix_exit = ref($using_service) ne 'CODE' && $using_service->use_posix_exit; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $using_service ne 'CODE' && $using_service->use_posix_exit
MC/DC0%0/2
ref $using_service ne 'CODE' && $using_service->use_posix_exit
ref $using_service ne 'CODE'
$using_service->use_posix_exit
Truth table66%2/3
A && B
A= ref $using_service ne 'CODE'B= $using_service->use_posix_exit
| |||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||
| 222 | 120 | ▶ | eval { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 223 | 120 | ▶ | if (ref($using_service) eq 'CODE') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 224 | 4 | my $exit = $using_service->(); | |||||||||||||||||||||||||||||||||
| 225 | 0 | exit($exit); | |||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||
| 227 | else { | ||||||||||||||||||||||||||||||||||
| 228 | 116 | ▶ | my $exit = $using_service->run() // 0; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$using_service->run // 0
MC/DC0%0/1
$using_service->run // 0
$using_service->run
Truth table50%1/2
A
A= $using_service->run
| |||||||||||||||||||||||||||||||||||
| 229 | 104 | ▶ | $do_posix_exit ? POSIX::_exit($exit) : exit($exit); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||
| 231 | 0 | 1; | |||||||||||||||||||||||||||||||||
| 232 | } or warn $@; | ||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | $do_posix_exit ? POSIX::_exit(255) : exit(255); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 235 | 120 | }; | |||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||
| 237 | # setjump returns undef if the sub returned normally (never, in | ||||||||||||||||||||||||||||||||||
| 238 | # practice -- we always exit()). Any other value means longjump | ||||||||||||||||||||||||||||||||||
| 239 | # was called and we loop with the updated $service_inst. | ||||||||||||||||||||||||||||||||||
| 240 | 12 | ▶ | last unless $jumped; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||
| 243 | # This should not be reachable.... | ||||||||||||||||||||||||||||||||||
| 244 | 0 | eval { warn "Scope leak in service '$name' process $$" }; | |||||||||||||||||||||||||||||||||
| 245 | 0 | POSIX::_exit(255); | |||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||
| 248 | 454 | 1; | |||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||
| 250 | __END__ | ||||||||||||||||||||||||||||||||||