line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Child; |
2
|
20
|
|
|
20
|
|
11619
|
use 5.006; |
|
20
|
|
|
|
|
50
|
|
|
20
|
|
|
|
|
546
|
|
3
|
20
|
|
|
20
|
|
67
|
use strict; |
|
20
|
|
|
|
|
20
|
|
|
20
|
|
|
|
|
628
|
|
4
|
20
|
|
|
20
|
|
125
|
use warnings; |
|
20
|
|
|
|
|
27
|
|
|
20
|
|
|
|
|
542
|
|
5
|
20
|
|
|
20
|
|
64
|
use Carp; |
|
20
|
|
|
|
|
20
|
|
|
20
|
|
|
|
|
1184
|
|
6
|
20
|
|
|
20
|
|
6081
|
use Child::Util; |
|
20
|
|
|
|
|
23
|
|
|
20
|
|
|
|
|
767
|
|
7
|
20
|
|
|
20
|
|
6552
|
use Child::Link::Proc; |
|
20
|
|
|
|
|
34
|
|
|
20
|
|
|
|
|
428
|
|
8
|
20
|
|
|
20
|
|
6701
|
use Child::Link::Parent; |
|
20
|
|
|
|
|
31
|
|
|
20
|
|
|
|
|
423
|
|
9
|
|
|
|
|
|
|
|
10
|
20
|
|
|
20
|
|
78
|
use Exporter 'import'; |
|
20
|
|
|
|
|
10
|
|
|
20
|
|
|
|
|
7598
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = "0.011"; |
13
|
|
|
|
|
|
|
our @PROCS; |
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw/child/; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
add_accessors qw/code/; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub child(&;@) { |
19
|
5
|
|
|
5
|
1
|
3967
|
my ( $code, @params ) = @_; |
20
|
5
|
|
|
|
|
7
|
my $caller = caller; |
21
|
5
|
|
|
|
|
13
|
return __PACKAGE__->new( $code, @params )->start; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
15
|
|
|
15
|
1
|
2074
|
sub all_procs { @PROCS } |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _clean_proc { |
27
|
19
|
|
|
19
|
|
50
|
my $class = shift; |
28
|
19
|
|
|
|
|
41
|
my ($proc) = @_; |
29
|
19
|
50
|
|
|
|
62
|
return unless $proc; |
30
|
19
|
|
|
|
|
60
|
@PROCS = grep { $proc != $_ } @PROCS; |
|
29
|
|
|
|
|
152
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub all_proc_pids { |
34
|
1
|
|
|
1
|
1
|
3980
|
my $class = shift; |
35
|
1
|
|
|
|
|
3
|
map { $_->pid } $class->all_procs; |
|
4
|
|
|
|
|
20
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub wait_all { |
39
|
2
|
|
|
2
|
1
|
1000457
|
my $class = shift; |
40
|
2
|
|
|
|
|
12
|
$_->wait() for $class->all_procs; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub new { |
44
|
55
|
|
|
55
|
1
|
32646
|
my ( $class, $code, $plugin, @data ) = @_; |
45
|
|
|
|
|
|
|
|
46
|
55
|
100
|
|
|
|
254
|
return bless( { _code => $code }, $class ) |
47
|
|
|
|
|
|
|
unless $plugin; |
48
|
|
|
|
|
|
|
|
49
|
19
|
|
|
|
|
26
|
my $build = __PACKAGE__; |
50
|
19
|
|
|
|
|
104
|
$build .= '::IPC::' . ucfirst $plugin; |
51
|
|
|
|
|
|
|
|
52
|
19
|
50
|
|
|
|
1295
|
eval "require $build; 1" |
53
|
|
|
|
|
|
|
|| croak( "Could not load plugin '$plugin': $@" ); |
54
|
|
|
|
|
|
|
|
55
|
19
|
|
|
|
|
134
|
return $build->new( $code, @data ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
30
|
|
|
30
|
0
|
57
|
sub shared_data {} |
59
|
|
|
|
|
|
|
|
60
|
22
|
|
|
22
|
0
|
1399
|
sub child_class { 'Child::Link::Proc' } |
61
|
8
|
|
|
8
|
0
|
602
|
sub parent_class { 'Child::Link::Parent' } |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub start { |
64
|
51
|
|
|
51
|
1
|
2420
|
my $self = shift; |
65
|
51
|
|
|
|
|
391
|
my $ppid = $$; |
66
|
51
|
|
|
|
|
150
|
my @data = $self->shared_data; |
67
|
|
|
|
|
|
|
|
68
|
51
|
100
|
|
|
|
39634
|
if ( my $pid = fork() ) { |
69
|
36
|
|
|
|
|
1064
|
my $proc = $self->child_class->new( $pid, @data ); |
70
|
36
|
|
|
|
|
116
|
push @PROCS => $proc; |
71
|
36
|
|
|
|
|
896
|
return $proc; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# In the child |
75
|
15
|
|
|
|
|
902
|
@PROCS = (); |
76
|
15
|
|
|
|
|
631
|
my $parent = $self->parent_class->new( $ppid, @data ); |
77
|
15
|
|
|
|
|
323
|
my $code = $self->code; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Ensure the child code can't die and jump out of our control. |
80
|
15
|
100
|
|
|
|
163
|
eval { $code->( $parent ); 1; } || do { |
|
15
|
|
|
|
|
150
|
|
|
12
|
|
|
|
|
95
|
|
81
|
|
|
|
|
|
|
# Simulate die without dying. |
82
|
2
|
|
|
|
|
190
|
print STDERR $@; |
83
|
2
|
|
|
|
|
377
|
exit 255; |
84
|
|
|
|
|
|
|
}; |
85
|
12
|
|
|
|
|
6470
|
exit; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |