line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Child; |
2
|
20
|
|
|
20
|
|
11383
|
use 5.006; |
|
20
|
|
|
|
|
52
|
|
|
20
|
|
|
|
|
650
|
|
3
|
20
|
|
|
20
|
|
84
|
use strict; |
|
20
|
|
|
|
|
25
|
|
|
20
|
|
|
|
|
545
|
|
4
|
20
|
|
|
20
|
|
129
|
use warnings; |
|
20
|
|
|
|
|
28
|
|
|
20
|
|
|
|
|
522
|
|
5
|
20
|
|
|
20
|
|
75
|
use Carp; |
|
20
|
|
|
|
|
25
|
|
|
20
|
|
|
|
|
1239
|
|
6
|
20
|
|
|
20
|
|
6849
|
use Child::Util; |
|
20
|
|
|
|
|
40
|
|
|
20
|
|
|
|
|
1017
|
|
7
|
20
|
|
|
20
|
|
8260
|
use Child::Link::Proc; |
|
20
|
|
|
|
|
42
|
|
|
20
|
|
|
|
|
467
|
|
8
|
20
|
|
|
20
|
|
7243
|
use Child::Link::Parent; |
|
20
|
|
|
|
|
30
|
|
|
20
|
|
|
|
|
491
|
|
9
|
|
|
|
|
|
|
|
10
|
20
|
|
|
20
|
|
89
|
use Exporter 'import'; |
|
20
|
|
|
|
|
23
|
|
|
20
|
|
|
|
|
8857
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = "0.012"; |
13
|
|
|
|
|
|
|
our @PROCS; |
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw/child/; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
add_accessors qw/code/; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub child(&;@) { |
19
|
5
|
|
|
5
|
1
|
4420
|
my ( $code, @params ) = @_; |
20
|
5
|
|
|
|
|
10
|
my $caller = caller; |
21
|
5
|
|
|
|
|
18
|
return __PACKAGE__->new( $code, @params )->start; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
15
|
|
|
15
|
1
|
2107
|
sub all_procs { @PROCS } |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _clean_proc { |
27
|
19
|
|
|
19
|
|
51
|
my $class = shift; |
28
|
19
|
|
|
|
|
41
|
my ($proc) = @_; |
29
|
19
|
50
|
|
|
|
73
|
return unless $proc; |
30
|
19
|
50
|
|
|
|
69
|
return unless @PROCS; |
31
|
19
|
50
|
|
|
|
79
|
@PROCS = grep { $_ && $proc != $_ } @PROCS; |
|
29
|
|
|
|
|
360
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub all_proc_pids { |
35
|
1
|
|
|
1
|
1
|
4363
|
my $class = shift; |
36
|
1
|
|
|
|
|
13
|
map { $_->pid } $class->all_procs; |
|
4
|
|
|
|
|
44
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub wait_all { |
40
|
2
|
|
|
2
|
1
|
1000744
|
my $class = shift; |
41
|
2
|
|
|
|
|
19
|
$_->wait() for $class->all_procs; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub new { |
45
|
55
|
|
|
55
|
1
|
30679
|
my ( $class, $code, $plugin, @data ) = @_; |
46
|
|
|
|
|
|
|
|
47
|
55
|
100
|
|
|
|
296
|
return bless( { _code => $code }, $class ) |
48
|
|
|
|
|
|
|
unless $plugin; |
49
|
|
|
|
|
|
|
|
50
|
19
|
|
|
|
|
64
|
my $build = __PACKAGE__; |
51
|
19
|
|
|
|
|
123
|
$build .= '::IPC::' . ucfirst $plugin; |
52
|
|
|
|
|
|
|
|
53
|
19
|
50
|
|
|
|
1702
|
eval "require $build; 1" |
54
|
|
|
|
|
|
|
|| croak( "Could not load plugin '$plugin': $@" ); |
55
|
|
|
|
|
|
|
|
56
|
19
|
|
|
|
|
179
|
return $build->new( $code, @data ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
30
|
|
|
30
|
0
|
57
|
sub shared_data {} |
60
|
|
|
|
|
|
|
|
61
|
22
|
|
|
22
|
0
|
1600
|
sub child_class { 'Child::Link::Proc' } |
62
|
8
|
|
|
8
|
0
|
681
|
sub parent_class { 'Child::Link::Parent' } |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub start { |
65
|
51
|
|
|
51
|
1
|
2579
|
my $self = shift; |
66
|
51
|
|
|
|
|
450
|
my $ppid = $$; |
67
|
51
|
|
|
|
|
145
|
my @data = $self->shared_data; |
68
|
|
|
|
|
|
|
|
69
|
51
|
100
|
|
|
|
47310
|
if ( my $pid = fork() ) { |
70
|
36
|
|
|
|
|
1345
|
my $proc = $self->child_class->new( $pid, @data ); |
71
|
36
|
|
|
|
|
176
|
push @PROCS => $proc; |
72
|
36
|
|
|
|
|
1038
|
return $proc; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# In the child |
76
|
15
|
|
|
|
|
1025
|
@PROCS = (); |
77
|
15
|
|
|
|
|
577
|
my $parent = $self->parent_class->new( $ppid, @data ); |
78
|
15
|
|
|
|
|
406
|
my $code = $self->code; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Ensure the child code can't die and jump out of our control. |
81
|
15
|
100
|
|
|
|
198
|
eval { $code->( $parent ); 1; } || do { |
|
15
|
|
|
|
|
172
|
|
|
12
|
|
|
|
|
152
|
|
82
|
|
|
|
|
|
|
# Simulate die without dying. |
83
|
2
|
|
|
|
|
184
|
print STDERR $@; |
84
|
2
|
|
|
|
|
399
|
exit 255; |
85
|
|
|
|
|
|
|
}; |
86
|
12
|
|
|
|
|
5682
|
exit; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |