line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2011-2015 by [Mark Overmeer]. |
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.02. |
5
|
3
|
|
|
3
|
|
912
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
81
|
|
6
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
86
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package IOMux::Bundle; |
9
|
3
|
|
|
3
|
|
14
|
use vars '$VERSION'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
128
|
|
10
|
|
|
|
|
|
|
$VERSION = '1.00'; |
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
13
|
use base 'IOMux::Handler::Read', 'IOMux::Handler::Write'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
2824
|
|
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
|
18
|
use Log::Report 'iomux'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
19
|
|
15
|
|
|
|
|
|
|
|
16
|
3
|
|
|
3
|
|
692
|
use Scalar::Util qw(blessed); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
3524
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
##### WORK IN PROGRESS! |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub init($) |
22
|
1
|
|
|
1
|
0
|
7
|
{ my ($self, $args) = @_; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# stdin to be a writer is a bit counter-intuitive, therefore some |
25
|
|
|
|
|
|
|
# extra tests. |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
7
|
my @filenos; |
28
|
1
|
|
|
|
|
18
|
my $name = $args->{name}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $in = $self->{IMB_stdin} = $args->{stdin} |
31
|
1
|
50
|
|
|
|
20
|
or error __x"no stdin handler for {name}", name => $name; |
32
|
1
|
50
|
33
|
|
|
124
|
blessed $in && $in->isa('IOMux::Handler::Write') |
33
|
|
|
|
|
|
|
or error __x"stdin {name} is not at writer", name => $name; |
34
|
1
|
|
|
|
|
48
|
push @filenos, $in->fileno; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $out = $self->{IMB_stdout} = $args->{stdout} |
37
|
1
|
50
|
|
|
|
28
|
or error __x"no stdout handler for {name}", name => $name; |
38
|
1
|
50
|
33
|
|
|
55
|
blessed $out && $out->isa('IOMux::Handler::Read') |
39
|
|
|
|
|
|
|
or error __x"stdout {name} is not at reader", name => $name; |
40
|
1
|
|
|
|
|
16
|
push @filenos, $out->fileno; |
41
|
|
|
|
|
|
|
|
42
|
1
|
50
|
|
|
|
6
|
if(my $err = $self->{IMB_stderr} = $args->{stderr}) |
43
|
0
|
0
|
0
|
|
|
0
|
{ blessed $err && $err->isa('IOMux::Handler::Read') |
44
|
|
|
|
|
|
|
or error __x"stderr {name} is not at reader", name => $name; |
45
|
0
|
|
|
|
|
0
|
push @filenos, $err->fileno; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
11
|
$args->{name} .= ', ('.join(',',@filenos).')'; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
38
|
$self->SUPER::init($args); |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
2
|
$self->{IMB_filenos} = \@filenos; |
53
|
1
|
|
|
|
|
18
|
$self; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
#--------------- |
57
|
|
|
|
|
|
|
|
58
|
2
|
|
|
2
|
1
|
1004144
|
sub stdin() {shift->{IMB_stdin}} |
59
|
0
|
|
|
0
|
1
|
0
|
sub stdout() {shift->{IMB_stdout}} |
60
|
0
|
|
|
0
|
1
|
0
|
sub stderr() {shift->{IMB_stderr}} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub connections() |
64
|
1
|
|
|
1
|
1
|
1
|
{ my $s = shift; |
65
|
1
|
|
|
|
|
32
|
grep defined, $s->{IMB_stdin}, $s->{IMB_stdout}, $s->{IMB_stderr}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#--------------- |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# say, print and printf use write() |
71
|
2
|
|
|
2
|
1
|
21
|
sub write(@) { shift->{IMB_stdin}->write(@_) } |
72
|
0
|
|
|
0
|
1
|
0
|
sub muxOutbufferEmpty() { shift->{IMB_stdin}->muxOutbufferEmpty(@_) } |
73
|
0
|
|
|
0
|
1
|
0
|
sub muxOutputWaiting() { shift->{IMB_stdin}->muxOutputWaiting(@_) } |
74
|
0
|
|
|
0
|
1
|
0
|
sub muxWriteFlagged() { shift->{IMB_stdin}->muxWriteFlagged(@_) } |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
0
|
1
|
0
|
sub readline(@) { shift->{IMB_stdout}->readline(@_) } |
77
|
1
|
|
|
1
|
1
|
23
|
sub slurp(@) { shift->{IMB_stdout}->slurp(@_) } |
78
|
0
|
|
|
0
|
1
|
0
|
sub muxInput($) { shift->{IMB_stdout}->muxInput(@_) } |
79
|
0
|
|
|
0
|
1
|
0
|
sub muxEOF($) { shift->{IMB_stdout}->muxEOF(@_) } |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub muxReadFlagged($) |
82
|
0
|
|
|
0
|
1
|
0
|
{ my ($self, $fileno) = @_; |
83
|
0
|
0
|
|
|
|
0
|
if(my $e = $self->{IMB_stderr}) |
84
|
0
|
0
|
|
|
|
0
|
{ return $e->muxReadFlagged(@_) |
85
|
|
|
|
|
|
|
if $fileno==$e->fileno; |
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
0
|
$self->{IMB_stdin}->muxReadFlagged(@_); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
0
|
1
|
0
|
sub timeout() { shift->{IMB_stdin}->timeout(@_) } |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub close(;$) |
93
|
1
|
|
|
1
|
1
|
4
|
{ my ($self, $cb) = @_; |
94
|
|
|
|
|
|
|
my $close_error = sub |
95
|
1
|
50
|
|
1
|
|
16
|
{ if(my $err = $self->{IMB_stderr}) { $err->close($cb) } |
|
0
|
50
|
|
|
|
0
|
|
96
|
0
|
|
|
|
|
0
|
elsif($cb) { $cb->($self) } |
97
|
1
|
|
|
|
|
9
|
}; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my $close_out = sub |
100
|
1
|
50
|
|
1
|
|
7
|
{ if(my $out = $self->{IMB_stdout}) { $out->close($close_error) } |
|
1
|
|
|
|
|
13
|
|
101
|
0
|
|
|
|
|
0
|
else { $close_error->() } |
102
|
1
|
|
|
|
|
8
|
}; |
103
|
|
|
|
|
|
|
|
104
|
1
|
50
|
|
|
|
8
|
if(my $in = $self->{IMB_stdin}) { $in->close($close_out) } |
|
1
|
|
|
|
|
8
|
|
105
|
0
|
|
|
|
|
0
|
else { $close_out->() } |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub muxRemove() |
109
|
0
|
|
|
0
|
1
|
0
|
{ my $self = shift; |
110
|
0
|
|
|
|
|
0
|
$_->muxRemove for $self->connections; |
111
|
0
|
|
|
|
|
0
|
trace "mux remove bundle ".$self->name; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub muxInit($) |
115
|
1
|
|
|
1
|
1
|
15
|
{ my ($self, $mux) = @_; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
$_->muxInit($mux, $self) # I want control |
118
|
1
|
|
|
|
|
12
|
for $self->connections; |
119
|
|
|
|
|
|
|
|
120
|
1
|
|
|
|
|
24
|
trace "mux add bundle ".$self->name; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
#--------------- |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub muxError($) |
126
|
0
|
|
|
0
|
1
|
|
{ my ($self, $errbuf) = @_; |
127
|
0
|
|
|
|
|
|
print STDERR $$errbuf; |
128
|
0
|
|
|
|
|
|
$$errbuf = ''; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
#--------------- |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub show() |
134
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
135
|
0
|
|
|
|
|
|
join "\n", (map $_->show, $self->connections), ''; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
0
|
1
|
|
sub fdset() {panic} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |