| 1 |
|
| package Zing::Fork; |
| 2 |
|
| |
| 3 |
56 |
▶ | use 5.014; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 4 |
|
| |
| 5 |
56 |
▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 6 |
56 |
▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 7 |
|
| |
| 8 |
56 |
▶ | use registry 'Zing::Types'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 9 |
56 |
▶ | use routines; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 10 |
|
| |
| 11 |
56 |
▶ | use Data::Object::Class; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 12 |
56 |
▶ | use Data::Object::ClassHas; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 13 |
56 |
▶ | use Data::Object::Space; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 14 |
|
| |
| 15 |
56 |
| extends 'Zing::Class'; |
| 16 |
|
| |
| 17 |
56 |
▶ | use POSIX (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 18 |
|
| |
| 19 |
56 |
▶ | use Config; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 20 |
|
| |
| 21 |
56 |
| our $VERSION = '0.26'; # VERSION |
| 22 |
|
| |
| 23 |
|
| # ATTRIBUTES |
| 24 |
|
| |
| 25 |
56 |
| has 'scheme' => ( |
| 26 |
|
| is => 'ro', |
| 27 |
|
| isa => 'Scheme', |
| 28 |
|
| req => 1, |
| 29 |
|
| ); |
| 30 |
|
| |
| 31 |
56 |
| has 'parent' => ( |
| 32 |
|
| is => 'rw', |
| 33 |
|
| isa => 'Process', |
| 34 |
|
| req => 1, |
| 35 |
|
| ); |
| 36 |
|
| |
| 37 |
|
| has 'processes' => ( |
| 38 |
|
| is => 'rw', |
| 39 |
|
| isa => 'HashRef[Process]', |
| 40 |
0 |
▶ | def => sub{{}}, |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
|
| 41 |
56 |
| ); |
| 42 |
|
| |
| 43 |
56 |
| has 'space' => ( |
| 44 |
|
| is => 'ro', |
| 45 |
|
| isa => 'Space', |
| 46 |
|
| new => 1 |
| 47 |
|
| ); |
| 48 |
|
| |
| 49 |
0 |
▶ | fun new_space($self) { |
|
Subroutine
new_space: not called CC=1 SCAR=6.9
Pod
undocumented
|
| 50 |
0 |
| Data::Object::Space->new($self->scheme->[0]) |
| 51 |
56 |
| } |
| 52 |
|
| |
| 53 |
|
| # SHIMS |
| 54 |
|
| |
| 55 |
|
| sub _waitpid { |
| 56 |
|
| CORE::waitpid(shift, POSIX::WNOHANG) |
| 57 |
|
| } |
| 58 |
|
| |
| 59 |
|
| # METHODS |
| 60 |
|
| |
| 61 |
0 |
▶ | method execute() { |
|
Subroutine
execute: not called CC=4 SCAR=30.0
|
| 62 |
0 |
| my $pid; |
| 63 |
|
| my $process; |
| 64 |
0 |
| my $sid = $$; |
| 65 |
|
| |
| 66 |
0 |
▶ | if ($Config{d_pseudofork}) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($Zing::Fork::Config{"d_pseudofork"}) |
0 |
0 |
0 |
|
| 67 |
0 |
| $self->throw(error_fork('emulation not supported')); |
| 68 |
|
| } |
| 69 |
|
| |
| 70 |
0 |
▶ | if(!defined($pid = fork)) { |
Branch: 1 branch
| Branch | True | False | Total |
| unless (defined($pid = fork)) |
0 |
0 |
0 |
|
| 71 |
0 |
| $self->fork(error_fork("$!")); |
| 72 |
|
| } |
| 73 |
|
| |
| 74 |
|
| # parent |
| 75 |
0 |
▶ | if ($pid) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($pid) { } |
0 |
0 |
0 |
|
| 76 |
|
| $process = $self->space->load->new( |
| 77 |
0 |
| @{$self->scheme->[1]}, |
| 78 |
|
| pid => $pid, |
| 79 |
|
| parent => $self->parent, |
| 80 |
|
| ); |
| 81 |
0 |
| return $self->processes->{$pid} = $process; |
| 82 |
|
| } |
| 83 |
|
| # child |
| 84 |
|
| else { |
| 85 |
0 |
| $pid = $$; |
| 86 |
|
| $process = $self->space->load->new( |
| 87 |
0 |
| @{$self->scheme->[1]}, |
| 88 |
|
| pid => $pid, |
| 89 |
|
| parent => $self->parent, |
| 90 |
|
| |
| 91 |
|
| ); |
| 92 |
0 |
| $process->execute; |
| 93 |
|
| } |
| 94 |
|
| |
| 95 |
0 |
| POSIX::_exit(0); |
| 96 |
56 |
| } |
| 97 |
|
| |
| 98 |
0 |
▶ | method monitor() { |
|
Subroutine
monitor: not called CC=2 SCAR=17.9
Pod
documented
|
| 99 |
0 |
| my $result = {}; |
| 100 |
|
| |
| 101 |
0 |
| for my $pid (sort keys %{$self->processes}) { |
| 102 |
0 |
| $result->{$pid} = _waitpid $pid; |
| 103 |
|
| } |
| 104 |
|
| |
| 105 |
0 |
| return $result; |
| 106 |
56 |
| } |
| 107 |
|
| |
| 108 |
0 |
▶ | method sanitize() { |
|
Subroutine
sanitize: not called CC=4 SCAR=30.0
Pod
documented
|
| 109 |
0 |
| my $result = $self->monitor; |
| 110 |
|
| |
| 111 |
0 |
| for my $pid (sort keys %{$result}) { |
| 112 |
0 |
▶ | if ($result->{$pid} == $pid || $result->{$pid} == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($result->{$pid} == $pid or $result->{$pid} == -1) |
0 |
0 |
0 |
Condition0%0/3
$result->{$pid} == $pid or $result->{$pid} == -1
MC/DC0%0/2
$result->{$pid} == $pid or $result->{$pid} == -1
$result->{$pid} == $pid
$result->{$pid} == -1
Truth table0%0/3
A or B
A= $result->{$pid} == $pidB= $result->{$pid} == -1
|
| 113 |
0 |
| delete $self->processes->{$pid}; |
| 114 |
|
| } |
| 115 |
|
| } |
| 116 |
|
| |
| 117 |
0 |
| return scalar(keys %{$self->processes}); |
| 118 |
56 |
| } |
| 119 |
|
| |
| 120 |
0 |
▶ | method terminate(Str $signal = 'kill') { |
|
Subroutine
terminate: not called CC=4 SCAR=30.0
Pod
documented
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 1 and $signal = "kill" |
0 |
0 |
0 |
| Type::Tiny::XS::Str($signal) or Function::Parameters::_croak('In method terminate: parameter 1 ($signal): ' . ${my $v = bless( {"_is_core" => 1,"_overload_coderef" => sub { package Sub::Defer; use warnings; use strict; $undeferred ||= undefer_sub($deferred_info->[4]); goto \&$undeferred;},"_overload_coderef_no_rebuild" => 1,"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Str","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; ref \$_ eq 'SCALAR' or ref \(my $val = $_) eq 'SCALAR';},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 291,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Str","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; use warnings; use strict; $Type::Tiny::AvoidCallbacks ? goto $orig_inlined : "$xsubname($_[1])";},"library" => "Types::Standard","name" => "Str","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] and not ref $_[0] or _failed_check(8, 'Value', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Value","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; not ref $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 276,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Value","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "defined($_[1]) and not ref($_[1])";},"library" => "Types::Standard","name" => "Value","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] or _failed_check(7, 'Defined', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Defined","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] and _failed_check(6, 'Undef', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Undef","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => {},"constraint" => sub { package Types::Standard; no warnings; use strict; not defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 254,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Undef","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "!defined($_[1])";},"library" => "Types::Standard","name" => "Undef","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; '???'; $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Item","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Type::Tiny; use warnings; use strict; !0;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 226,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Item","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Item","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; '???'; $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => do{my $o},"display_name" => "to_Any","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complement_name" => "None","constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 220,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Any","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Any","type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 1}, 'Type::Tiny' ),"uniq" => 2}, 'Type::Tiny' ),"type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 6}, 'Type::Tiny' ),"constraint" => sub { package Types::Standard; no warnings; use strict; defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 262,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Defined","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "defined($_[1])";},"library" => "Types::Standard","name" => "Defined","parent" => {},"uniq" => 7}, 'Type::Tiny' ),"uniq" => 8}, 'Type::Tiny' ),"sorter" => sub { package Types::Standard; no warnings; use strict; $_[0] cmp $_[1];},"type_default" => sub { package Types::Standard; no warnings; use strict; return '';},"uniq" => 9}, 'Type::Tiny' );$v->{"coercion"}{"type_constraint"} = $v;$v->{"compiled_type_constraint"} = $v->{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"};$v->{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"};$v->{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"};$v->{"parent"}{"parent"}{"complementary_type"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"complementary_type"} = $v->{"parent"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"constraint"};$v->{"parent"}{"parent"}{"parent"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}; \$v}->get_message($signal)) |
0 |
0 |
0 |
|
| 121 |
0 |
| my $result = {}; |
| 122 |
|
| |
| 123 |
0 |
| for my $pid (sort keys %{$self->processes}) { |
| 124 |
0 |
| $result->{$pid} = $self->processes->{$pid}->signal($pid, $signal); |
| 125 |
|
| } |
| 126 |
|
| |
| 127 |
0 |
| return $result; |
| 128 |
56 |
| } |
| 129 |
|
| |
| 130 |
|
| # ERRORS |
| 131 |
|
| |
| 132 |
0 |
▶ | fun error_fork(Str $reason) { |
|
Subroutine
error_fork: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| Branch | True | False | Total |
| Type::Tiny::XS::Str($reason) or Function::Parameters::_croak('In fun error_fork: parameter 1 ($reason): ' . ${my $v = bless( {"_is_core" => 1,"_overload_coderef" => sub { package Sub::Defer; use warnings; use strict; $undeferred ||= undefer_sub($deferred_info->[4]); goto \&$undeferred;},"_overload_coderef_no_rebuild" => 1,"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Str","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; ref \$_ eq 'SCALAR' or ref \(my $val = $_) eq 'SCALAR';},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 291,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Str","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; use warnings; use strict; $Type::Tiny::AvoidCallbacks ? goto $orig_inlined : "$xsubname($_[1])";},"library" => "Types::Standard","name" => "Str","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] and not ref $_[0] or _failed_check(8, 'Value', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Value","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; not ref $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 276,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Value","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "defined($_[1]) and not ref($_[1])";},"library" => "Types::Standard","name" => "Value","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] or _failed_check(7, 'Defined', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Defined","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] and _failed_check(6, 'Undef', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Undef","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => {},"constraint" => sub { package Types::Standard; no warnings; use strict; not defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 254,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Undef","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "!defined($_[1])";},"library" => "Types::Standard","name" => "Undef","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; '???'; $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Item","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Type::Tiny; use warnings; use strict; !0;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 226,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Item","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Item","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; '???'; $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => do{my $o},"display_name" => "to_Any","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complement_name" => "None","constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 220,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Any","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Any","type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 1}, 'Type::Tiny' ),"uniq" => 2}, 'Type::Tiny' ),"type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 6}, 'Type::Tiny' ),"constraint" => sub { package Types::Standard; no warnings; use strict; defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 262,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Defined","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "defined($_[1])";},"library" => "Types::Standard","name" => "Defined","parent" => {},"uniq" => 7}, 'Type::Tiny' ),"uniq" => 8}, 'Type::Tiny' ),"sorter" => sub { package Types::Standard; no warnings; use strict; $_[0] cmp $_[1];},"type_default" => sub { package Types::Standard; no warnings; use strict; return '';},"uniq" => 9}, 'Type::Tiny' );$v->{"coercion"}{"type_constraint"} = $v;$v->{"compiled_type_constraint"} = $v->{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"};$v->{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"};$v->{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"};$v->{"parent"}{"parent"}{"complementary_type"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"complementary_type"} = $v->{"parent"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"constraint"};$v->{"parent"}{"parent"}{"parent"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}; \$v}->get_message($reason)) |
0 |
0 |
0 |
|
| 133 |
0 |
| code => 'error_fork', |
| 134 |
|
| message => "Error on fork: $reason", |
| 135 |
56 |
| } |
| 136 |
|
| |
| 137 |
56 |
| 1; |
| 138 |
|
| |
| 139 |
|
| =encoding utf8 |
| 140 |
|
| |
| 141 |
|
| =head1 NAME |
| 142 |
|
| |
| 143 |
|
| Zing::Fork - Fork Manager |
| 144 |
|
| |
| 145 |
|
| =cut |
| 146 |
|
| |
| 147 |
|
| =head1 ABSTRACT |
| 148 |
|
| |
| 149 |
|
| Scheme Fork Manager |
| 150 |
|
| |
| 151 |
|
| =cut |
| 152 |
|
| |
| 153 |
|
| =head1 SYNOPSIS |
| 154 |
|
| |
| 155 |
|
| use Zing::Fork; |
| 156 |
|
| use Zing::Process; |
| 157 |
|
| |
| 158 |
|
| my $scheme = ['MyApp', [], 1]; |
| 159 |
|
| my $fork = Zing::Fork->new(scheme => $scheme, parent => Zing::Process->new); |
| 160 |
|
| |
| 161 |
|
| # $fork->execute; |
| 162 |
|
| |
| 163 |
|
| =cut |
| 164 |
|
| |
| 165 |
|
| =head1 DESCRIPTION |
| 166 |
|
| |
| 167 |
|
| This package provides provides a mechanism for forking and tracking processes, |
| 168 |
|
| as well as establishing the parent-child relationship. B<Note:> The C<$num> |
| 169 |
|
| part of the application scheme, i.e. C<['MyApp', [], $num]>, is ignored and |
| 170 |
|
| launching the desired forks requires calling L</execute> multiple times. |
| 171 |
|
| |
| 172 |
|
| =cut |
| 173 |
|
| |
| 174 |
|
| =head1 LIBRARIES |
| 175 |
|
| |
| 176 |
|
| This package uses type constraints from: |
| 177 |
|
| |
| 178 |
|
| L<Zing::Types> |
| 179 |
|
| |
| 180 |
|
| =cut |
| 181 |
|
| |
| 182 |
|
| =head1 ATTRIBUTES |
| 183 |
|
| |
| 184 |
|
| This package has the following attributes: |
| 185 |
|
| |
| 186 |
|
| =cut |
| 187 |
|
| |
| 188 |
|
| =head2 parent |
| 189 |
|
| |
| 190 |
|
| parent(Process) |
| 191 |
|
| |
| 192 |
|
| This attribute is read-only, accepts C<(Process)> values, and is required. |
| 193 |
|
| |
| 194 |
|
| =cut |
| 195 |
|
| |
| 196 |
|
| =head2 processes |
| 197 |
|
| |
| 198 |
|
| processes(HashRef[Process]) |
| 199 |
|
| |
| 200 |
|
| This attribute is read-only, accepts C<(HashRef[Process])> values, and is optional. |
| 201 |
|
| |
| 202 |
|
| =cut |
| 203 |
|
| |
| 204 |
|
| =head2 scheme |
| 205 |
|
| |
| 206 |
|
| scheme(Scheme) |
| 207 |
|
| |
| 208 |
|
| This attribute is read-only, accepts C<(Scheme)> values, and is required. |
| 209 |
|
| |
| 210 |
|
| =cut |
| 211 |
|
| |
| 212 |
|
| =head2 space |
| 213 |
|
| |
| 214 |
|
| space(Space) |
| 215 |
|
| |
| 216 |
|
| This attribute is read-only, accepts C<(Space)> values, and is optional. |
| 217 |
|
| |
| 218 |
|
| =cut |
| 219 |
|
| |
| 220 |
|
| =head1 METHODS |
| 221 |
|
| |
| 222 |
|
| This package implements the following methods: |
| 223 |
|
| |
| 224 |
|
| =cut |
| 225 |
|
| |
| 226 |
|
| =head2 execute |
| 227 |
|
| |
| 228 |
|
| execute() : Process |
| 229 |
|
| |
| 230 |
|
| The execute method forks a process based on the scheme, adds it to the process |
| 231 |
|
| list and returns a representation of the child process. |
| 232 |
|
| |
| 233 |
|
| =over 4 |
| 234 |
|
| |
| 235 |
|
| =item execute example #1 |
| 236 |
|
| |
| 237 |
|
| # given: synopsis |
| 238 |
|
| |
| 239 |
|
| my $process = $fork->execute; |
| 240 |
|
| |
| 241 |
|
| =back |
| 242 |
|
| |
| 243 |
|
| =cut |
| 244 |
|
| |
| 245 |
|
| =head2 monitor |
| 246 |
|
| |
| 247 |
|
| monitor() : HashRef[Int] |
| 248 |
|
| |
| 249 |
|
| The monitor method calls L<perlfunc/waitpid> on tracked processes and returns |
| 250 |
|
| the results as a pid/result map. |
| 251 |
|
| |
| 252 |
|
| =over 4 |
| 253 |
|
| |
| 254 |
|
| =item monitor example #1 |
| 255 |
|
| |
| 256 |
|
| # given: synopsis |
| 257 |
|
| |
| 258 |
|
| $fork->execute; |
| 259 |
|
| $fork->execute; |
| 260 |
|
| |
| 261 |
|
| # forks still alive |
| 262 |
|
| |
| 263 |
|
| my $results = $fork->monitor; |
| 264 |
|
| |
| 265 |
|
| # { 1000 => 1000, ... } |
| 266 |
|
| |
| 267 |
|
| =back |
| 268 |
|
| |
| 269 |
|
| =over 4 |
| 270 |
|
| |
| 271 |
|
| =item monitor example #2 |
| 272 |
|
| |
| 273 |
|
| # given: synopsis |
| 274 |
|
| |
| 275 |
|
| $fork->execute; |
| 276 |
|
| $fork->execute; |
| 277 |
|
| |
| 278 |
|
| # forks are dead |
| 279 |
|
| |
| 280 |
|
| my $results = $fork->monitor; |
| 281 |
|
| |
| 282 |
|
| # { 1000 => -1, ... } |
| 283 |
|
| |
| 284 |
|
| =back |
| 285 |
|
| |
| 286 |
|
| =cut |
| 287 |
|
| |
| 288 |
|
| =head2 sanitize |
| 289 |
|
| |
| 290 |
|
| sanitize() : Int |
| 291 |
|
| |
| 292 |
|
| The sanitize method removes inactive child processes from the process list and |
| 293 |
|
| returns the number of processes remaining. |
| 294 |
|
| |
| 295 |
|
| =over 4 |
| 296 |
|
| |
| 297 |
|
| =item sanitize example #1 |
| 298 |
|
| |
| 299 |
|
| # given: synopsis |
| 300 |
|
| |
| 301 |
|
| $fork->execute; # dead |
| 302 |
|
| $fork->execute; # dead |
| 303 |
|
| |
| 304 |
|
| my $results = $fork->sanitize; # 0 |
| 305 |
|
| |
| 306 |
|
| =back |
| 307 |
|
| |
| 308 |
|
| =over 4 |
| 309 |
|
| |
| 310 |
|
| =item sanitize example #2 |
| 311 |
|
| |
| 312 |
|
| # given: synopsis |
| 313 |
|
| |
| 314 |
|
| $fork->execute; # live |
| 315 |
|
| $fork->execute; # dead |
| 316 |
|
| |
| 317 |
|
| my $results = $fork->sanitize; # 1 |
| 318 |
|
| |
| 319 |
|
| =back |
| 320 |
|
| |
| 321 |
|
| =over 4 |
| 322 |
|
| |
| 323 |
|
| =item sanitize example #3 |
| 324 |
|
| |
| 325 |
|
| # given: synopsis |
| 326 |
|
| |
| 327 |
|
| $fork->execute; # live |
| 328 |
|
| $fork->execute; # live |
| 329 |
|
| |
| 330 |
|
| my $results = $fork->sanitize; # 2 |
| 331 |
|
| |
| 332 |
|
| =back |
| 333 |
|
| |
| 334 |
|
| =cut |
| 335 |
|
| |
| 336 |
|
| =head2 terminate |
| 337 |
|
| |
| 338 |
|
| terminate(Str $signal = 'kill') : HashRef[Int] |
| 339 |
|
| |
| 340 |
|
| The terminate method call L<perlfunc/kill> and sends a signal to all tracked |
| 341 |
|
| processes and returns the results as a pid/result map. |
| 342 |
|
| |
| 343 |
|
| =over 4 |
| 344 |
|
| |
| 345 |
|
| =item terminate example #1 |
| 346 |
|
| |
| 347 |
|
| # given: synopsis |
| 348 |
|
| |
| 349 |
|
| $fork->execute; |
| 350 |
|
| $fork->execute; |
| 351 |
|
| |
| 352 |
|
| my $results = $fork->terminate; # kill |
| 353 |
|
| |
| 354 |
|
| =back |
| 355 |
|
| |
| 356 |
|
| =over 4 |
| 357 |
|
| |
| 358 |
|
| =item terminate example #2 |
| 359 |
|
| |
| 360 |
|
| # given: synopsis |
| 361 |
|
| |
| 362 |
|
| $fork->execute; |
| 363 |
|
| $fork->execute; |
| 364 |
|
| |
| 365 |
|
| my $results = $fork->terminate('term'); |
| 366 |
|
| |
| 367 |
|
| =back |
| 368 |
|
| |
| 369 |
|
| =over 4 |
| 370 |
|
| |
| 371 |
|
| =item terminate example #3 |
| 372 |
|
| |
| 373 |
|
| # given: synopsis |
| 374 |
|
| |
| 375 |
|
| $fork->execute; |
| 376 |
|
| $fork->execute; |
| 377 |
|
| |
| 378 |
|
| my $results = $fork->terminate('usr2'); |
| 379 |
|
| |
| 380 |
|
| =back |
| 381 |
|
| |
| 382 |
|
| =cut |
| 383 |
|
| |
| 384 |
|
| =head1 AUTHOR |
| 385 |
|
| |
| 386 |
|
| Al Newkirk, C<awncorp@cpan.org> |
| 387 |
|
| |
| 388 |
|
| =head1 LICENSE |
| 389 |
|
| |
| 390 |
|
| Copyright (C) 2011-2019, Al Newkirk, et al. |
| 391 |
|
| |
| 392 |
|
| This is free software; you can redistribute it and/or modify it under the terms |
| 393 |
|
| of the The Apache License, Version 2.0, as elucidated in the L<"license |
| 394 |
|
| file"|https://github.com/iamalnewkirk/zing/blob/master/LICENSE>. |
| 395 |
|
| |
| 396 |
|
| =head1 PROJECT |
| 397 |
|
| |
| 398 |
|
| L<Wiki|https://github.com/iamalnewkirk/zing/wiki> |
| 399 |
|
| |
| 400 |
|
| L<Project|https://github.com/iamalnewkirk/zing> |
| 401 |
|
| |
| 402 |
|
| L<Initiatives|https://github.com/iamalnewkirk/zing/projects> |
| 403 |
|
| |
| 404 |
|
| L<Milestones|https://github.com/iamalnewkirk/zing/milestones> |
| 405 |
|
| |
| 406 |
|
| L<Contributing|https://github.com/iamalnewkirk/zing/blob/master/CONTRIBUTE.md> |
| 407 |
|
| |
| 408 |
|
| L<Issues|https://github.com/iamalnewkirk/zing/issues> |
| 409 |
|
| |
| 410 |
|
| =cut |