line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Harness::Proc; |
2
|
26
|
|
|
26
|
|
210277
|
use strict; |
|
26
|
|
|
|
|
27
|
|
|
26
|
|
|
|
|
554
|
|
3
|
26
|
|
|
26
|
|
81
|
use warnings; |
|
26
|
|
|
|
|
7
|
|
|
26
|
|
|
|
|
752
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000012'; |
6
|
|
|
|
|
|
|
|
7
|
26
|
|
|
26
|
|
11997
|
use IO::Handle; |
|
26
|
|
|
|
|
127132
|
|
|
26
|
|
|
|
|
1038
|
|
8
|
26
|
|
|
26
|
|
153
|
use Carp qw/croak/; |
|
26
|
|
|
|
|
27
|
|
|
26
|
|
|
|
|
973
|
|
9
|
26
|
|
|
26
|
|
11312
|
use POSIX qw/:sys_wait_h/; |
|
26
|
|
|
|
|
114657
|
|
|
26
|
|
|
|
|
106
|
|
10
|
|
|
|
|
|
|
|
11
|
26
|
|
|
26
|
|
23833
|
use Test2::Util::HashBase qw/file pid in_fh out_fh err_fh exit lines idx/; |
|
26
|
|
|
|
|
29
|
|
|
26
|
|
|
|
|
232
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub init { |
14
|
631
|
|
|
631
|
0
|
258449
|
my $self = shift; |
15
|
|
|
|
|
|
|
|
16
|
631
|
|
|
|
|
3864
|
for my $thing (PID(), IN_FH(), OUT_FH(), FILE()) { |
17
|
2500
|
100
|
|
|
|
7396
|
next if $self->{$thing}; |
18
|
16
|
|
|
|
|
2030
|
croak "'$thing' is a required attribute"; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
615
|
|
|
|
|
970
|
for my $fh (@{$self}{OUT_FH(), ERR_FH()}) { |
|
615
|
|
|
|
|
3054
|
|
22
|
1230
|
100
|
|
|
|
2224
|
next unless $fh; |
23
|
1226
|
|
|
|
|
5493
|
$fh->blocking(0); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
615
|
|
|
|
|
11451
|
$self->{+LINES} = { |
27
|
|
|
|
|
|
|
stderr => [], |
28
|
|
|
|
|
|
|
stdout => [], |
29
|
|
|
|
|
|
|
muxed => [], |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub encoding { |
34
|
327
|
|
|
327
|
1
|
1506
|
my $self = shift; |
35
|
327
|
|
|
|
|
654
|
my ($enc) = @_; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# https://rt.perl.org/Public/Bug/Display.html?id=31923 |
38
|
|
|
|
|
|
|
# If utf8 is requested we use ':utf8' instead of ':encoding(utf8)' in |
39
|
|
|
|
|
|
|
# order to avoid the thread segfault. |
40
|
327
|
50
|
|
|
|
3272
|
if ($enc =~ m/^utf-?8$/i) { |
41
|
327
|
|
|
|
|
528
|
binmode($_, ":utf8") for grep {$_} @{$self}{qw/out_fh err_fh in_fh/}; |
|
981
|
|
|
|
|
4606
|
|
|
327
|
|
|
|
|
930
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
0
|
|
|
|
|
0
|
binmode($_, ":encoding($enc)") for grep {$_} @{$self}{qw/out_fh err_fh in_fh/}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub is_done { |
49
|
28155
|
|
|
28155
|
1
|
32612
|
my $self = shift; |
50
|
|
|
|
|
|
|
|
51
|
28155
|
|
|
|
|
60809
|
$self->wait(WNOHANG); |
52
|
|
|
|
|
|
|
|
53
|
28155
|
100
|
|
|
|
58629
|
return 1 if defined $self->{+EXIT}; |
54
|
22560
|
|
|
|
|
100232
|
return 0; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub wait { |
58
|
28157
|
|
|
28157
|
0
|
24466
|
my $self = shift; |
59
|
28157
|
|
|
|
|
31211
|
my ($flags) = @_; |
60
|
|
|
|
|
|
|
|
61
|
28157
|
100
|
|
|
|
52590
|
return if defined $self->{+EXIT}; |
62
|
|
|
|
|
|
|
|
63
|
23167
|
50
|
|
|
|
45656
|
my $pid = $self->{+PID} or die "No PID"; |
64
|
23167
|
|
100
|
|
|
3092497
|
my $ret = waitpid($pid, $flags || 0); |
65
|
23166
|
|
|
|
|
40753
|
my $exit = $?; |
66
|
|
|
|
|
|
|
|
67
|
23166
|
100
|
|
|
|
52401
|
return if $ret == 0; |
68
|
606
|
50
|
|
|
|
2135
|
die "Process $pid was already reaped!" if $ret == -1; |
69
|
|
|
|
|
|
|
|
70
|
606
|
|
|
|
|
1097
|
$exit >>= 8; |
71
|
606
|
|
|
|
|
5298
|
$self->{+EXIT} = $exit; |
72
|
|
|
|
|
|
|
|
73
|
606
|
|
|
|
|
1792
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub write { |
77
|
6
|
|
|
6
|
1
|
14
|
my $self = shift; |
78
|
6
|
|
|
|
|
15
|
my $fh = $self->{+IN_FH}; |
79
|
6
|
|
|
|
|
127
|
print $fh @_; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub seen_out_lines { |
83
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
84
|
1
|
|
|
|
|
2
|
return @{$self->{+LINES}->{stdout}}; |
|
1
|
|
|
|
|
8
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub seen_err_lines { |
88
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
89
|
1
|
|
|
|
|
2
|
return @{$self->{+LINES}->{stderr}}; |
|
1
|
|
|
|
|
7
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub get_out_line { |
93
|
40556
|
|
|
40556
|
1
|
221753
|
my $self = shift; |
94
|
40556
|
|
|
|
|
103811
|
return $self->_get_line_for(OUT_FH(), 'stdout', @_); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub get_err_line { |
98
|
24926
|
|
|
24926
|
1
|
487106
|
my $self = shift; |
99
|
24926
|
|
|
|
|
52055
|
return $self->_get_line_for(ERR_FH(), 'stderr', @_); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _get_line_for { |
103
|
65482
|
|
|
65482
|
|
58850
|
my $self = shift; |
104
|
65482
|
|
|
|
|
122953
|
my ($io_name, $stash_name, %params) = @_; |
105
|
|
|
|
|
|
|
|
106
|
65482
|
|
50
|
|
|
143579
|
my $stash = $self->{+LINES}->{$stash_name} ||= []; |
107
|
65482
|
|
|
|
|
88119
|
my $idx = \($self->{+IDX}->{$stash_name}); |
108
|
65482
|
|
100
|
|
|
164000
|
$$idx ||= 0; |
109
|
|
|
|
|
|
|
|
110
|
65482
|
100
|
|
|
|
108106
|
if (@$stash > $$idx) { |
111
|
2812
|
|
|
|
|
3727
|
my $line = $stash->[$$idx]; |
112
|
2812
|
100
|
|
|
|
4833
|
$$idx++ unless $params{peek}; |
113
|
2812
|
|
|
|
|
9681
|
return $line; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
62670
|
50
|
|
|
|
113565
|
my $h = $self->{$io_name} or return; |
117
|
|
|
|
|
|
|
|
118
|
62670
|
|
|
|
|
151745
|
seek($h,0,1); |
119
|
62670
|
|
|
|
|
231087
|
my $line = <$h>; |
120
|
62670
|
100
|
|
|
|
268638
|
return unless defined $line; |
121
|
|
|
|
|
|
|
|
122
|
20226
|
|
|
|
|
44072
|
push @$stash => $line; |
123
|
|
|
|
|
|
|
|
124
|
20226
|
100
|
|
|
|
35997
|
$$idx++ unless $params{peek}; |
125
|
|
|
|
|
|
|
|
126
|
20226
|
|
|
|
|
63046
|
return $line; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
__END__ |