line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Child; |
2
|
20
|
|
|
20
|
|
10700
|
use 5.006; |
|
20
|
|
|
|
|
47
|
|
3
|
20
|
|
|
20
|
|
70
|
use strict; |
|
20
|
|
|
|
|
20
|
|
|
20
|
|
|
|
|
416
|
|
4
|
20
|
|
|
20
|
|
105
|
use warnings; |
|
20
|
|
|
|
|
27
|
|
|
20
|
|
|
|
|
513
|
|
5
|
20
|
|
|
20
|
|
56
|
use Carp; |
|
20
|
|
|
|
|
17
|
|
|
20
|
|
|
|
|
1166
|
|
6
|
20
|
|
|
20
|
|
6292
|
use Child::Util; |
|
20
|
|
|
|
|
32
|
|
|
20
|
|
|
|
|
957
|
|
7
|
20
|
|
|
20
|
|
8043
|
use Child::Link::Proc; |
|
20
|
|
|
|
|
32
|
|
|
20
|
|
|
|
|
441
|
|
8
|
20
|
|
|
20
|
|
7798
|
use Child::Link::Parent; |
|
20
|
|
|
|
|
26
|
|
|
20
|
|
|
|
|
418
|
|
9
|
|
|
|
|
|
|
|
10
|
20
|
|
|
20
|
|
78
|
use Exporter 'import'; |
|
20
|
|
|
|
|
17
|
|
|
20
|
|
|
|
|
8143
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = "0.013"; |
13
|
|
|
|
|
|
|
our @PROCS; |
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw/child/; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
add_accessors qw/code/; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub child(&;@) { |
19
|
5
|
|
|
5
|
1
|
3620
|
my ( $code, @params ) = @_; |
20
|
5
|
|
|
|
|
8
|
my $caller = caller; |
21
|
5
|
|
|
|
|
10
|
return __PACKAGE__->new( $code, @params )->start; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
15
|
|
|
15
|
1
|
1451
|
sub all_procs { @PROCS } |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _clean_proc { |
27
|
19
|
|
|
19
|
|
64
|
my $class = shift; |
28
|
19
|
|
|
|
|
47
|
my ($proc) = @_; |
29
|
19
|
50
|
|
|
|
109
|
return unless $proc; |
30
|
19
|
50
|
|
|
|
70
|
return unless @PROCS; |
31
|
19
|
50
|
|
|
|
71
|
@PROCS = grep { $_ && $proc != $_ } @PROCS; |
|
29
|
|
|
|
|
288
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub all_proc_pids { |
35
|
1
|
|
|
1
|
1
|
4078
|
my $class = shift; |
36
|
1
|
|
|
|
|
9
|
map { $_->pid } $class->all_procs; |
|
4
|
|
|
|
|
22
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub wait_all { |
40
|
2
|
|
|
2
|
1
|
1000414
|
my $class = shift; |
41
|
2
|
|
|
|
|
9
|
$_->wait() for $class->all_procs; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub new { |
45
|
55
|
|
|
55
|
1
|
31124
|
my ( $class, $code, $plugin, @data ) = @_; |
46
|
|
|
|
|
|
|
|
47
|
55
|
100
|
|
|
|
225
|
return bless( { _code => $code }, $class ) |
48
|
|
|
|
|
|
|
unless $plugin; |
49
|
|
|
|
|
|
|
|
50
|
19
|
|
|
|
|
25
|
my $build = __PACKAGE__; |
51
|
19
|
|
|
|
|
58
|
$build .= '::IPC::' . ucfirst $plugin; |
52
|
|
|
|
|
|
|
|
53
|
19
|
50
|
|
|
|
1329
|
eval "require $build; 1" |
54
|
|
|
|
|
|
|
|| croak( "Could not load plugin '$plugin': $@" ); |
55
|
|
|
|
|
|
|
|
56
|
19
|
|
|
|
|
148
|
return $build->new( $code, @data ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
30
|
0
|
|
sub shared_data {} |
60
|
|
|
|
|
|
|
|
61
|
22
|
|
|
22
|
0
|
1420
|
sub child_class { 'Child::Link::Proc' } |
62
|
8
|
|
|
8
|
0
|
583
|
sub parent_class { 'Child::Link::Parent' } |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub start { |
65
|
51
|
|
|
51
|
1
|
2309
|
my $self = shift; |
66
|
51
|
|
|
|
|
303
|
my $ppid = $$; |
67
|
51
|
|
|
|
|
136
|
my @data = $self->shared_data; |
68
|
|
|
|
|
|
|
|
69
|
51
|
100
|
|
|
|
47891
|
if ( my $pid = fork() ) { |
70
|
36
|
|
|
|
|
800
|
my $proc = $self->child_class->new( $pid, @data ); |
71
|
36
|
|
|
|
|
133
|
push @PROCS => $proc; |
72
|
36
|
|
|
|
|
853
|
return $proc; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# In the child |
76
|
15
|
|
|
|
|
732
|
@PROCS = (); |
77
|
15
|
|
|
|
|
521
|
my $parent = $self->parent_class->new( $ppid, @data ); |
78
|
15
|
|
|
|
|
338
|
my $code = $self->code; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Ensure the child code can't die and jump out of our control. |
81
|
15
|
100
|
|
|
|
160
|
eval { $code->( $parent ); 1; } || do { |
|
15
|
|
|
|
|
138
|
|
|
12
|
|
|
|
|
181
|
|
82
|
|
|
|
|
|
|
# Simulate die without dying. |
83
|
2
|
|
|
|
|
215
|
print STDERR $@; |
84
|
2
|
|
|
|
|
5571
|
exit 255; |
85
|
|
|
|
|
|
|
}; |
86
|
12
|
|
|
|
|
2264
|
exit; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |