line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IPC::Simple::Group; |
2
|
|
|
|
|
|
|
# ABSTRACT: work with several processes as a group |
3
|
|
|
|
|
|
|
$IPC::Simple::Group::VERSION = '0.09'; |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
27
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
118
|
|
6
|
4
|
|
|
4
|
|
23
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
93
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
21
|
use Carp; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
195
|
|
9
|
4
|
|
|
4
|
|
23
|
use IPC::Simple::Channel qw(); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
2475
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
1
|
|
|
1
|
0
|
3
|
my $class = shift; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
|
|
7
|
my $self = bless{ |
15
|
|
|
|
|
|
|
members => {}, |
16
|
|
|
|
|
|
|
messages => IPC::Simple::Channel->new, |
17
|
|
|
|
|
|
|
}, $class; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
5
|
$self->add(@_); |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
3
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub add { |
25
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
4
|
for (@_) { |
28
|
2
|
50
|
|
|
|
7
|
croak 'processes must be named to be grouped' |
29
|
|
|
|
|
|
|
unless $_->name; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
croak 'processes with a recv_cb may not be grouped' |
32
|
2
|
50
|
|
|
|
8
|
if $_->{cb}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
croak 'processes with a term_cb may not be grouped' |
35
|
2
|
50
|
|
|
|
6
|
if $_->{term_cb}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
7
|
for (@_) { |
39
|
2
|
|
|
|
|
8
|
$self->{members}{ $_->{name} } = $_; |
40
|
2
|
|
|
4
|
|
7
|
$_->{recv_cb} = sub{ $self->{messages}->put( $_[0] ) }; |
|
4
|
|
|
|
|
20
|
|
41
|
2
|
|
|
2
|
|
6
|
$_->{term_cb} = sub{ $self->drop( $_[0] ) }; |
|
2
|
|
|
|
|
11
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# If the process has already been launched, move existing messages into the |
44
|
|
|
|
|
|
|
# group queue. |
45
|
2
|
50
|
|
|
|
7
|
unless ($_->is_ready) { |
46
|
0
|
|
|
|
|
0
|
$self->{messages}->put( $_->{messages}->clear ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub drop { |
52
|
2
|
|
|
2
|
0
|
5
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
delete $self->{members}{ $_->{name} } |
55
|
2
|
|
|
|
|
22
|
for @_; |
56
|
|
|
|
|
|
|
|
57
|
2
|
100
|
|
|
|
7
|
unless (%{ $self->{members} }) { |
|
2
|
|
|
|
|
12
|
|
58
|
1
|
|
|
|
|
6
|
$self->{messages}->shutdown; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub members { |
63
|
3
|
|
|
3
|
1
|
5
|
my $self = shift; |
64
|
3
|
|
|
|
|
8
|
return values %{ $self->{members} }; |
|
3
|
|
|
|
|
12
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub launch { |
68
|
1
|
|
|
1
|
1
|
7
|
my $self = shift; |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
3
|
for ($self->members) { |
71
|
2
|
50
|
|
|
|
5
|
$_->launch if $_->is_ready; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub terminate { |
76
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
77
|
1
|
|
|
|
|
14
|
$_->terminate(@_) for $self->members; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub signal { |
81
|
0
|
|
|
0
|
1
|
0
|
my ($self, $signal) = @_; |
82
|
0
|
|
|
|
|
0
|
$_->signal($signal) for $self->members; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub join { |
86
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
87
|
1
|
|
|
|
|
3
|
$_->join for $self->members; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub recv { |
91
|
5
|
|
|
5
|
1
|
126
|
my $self = shift; |
92
|
5
|
|
|
|
|
27
|
$self->{messages}->recv; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |