line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Plugin::IOMuxer::Layer; |
2
|
3
|
|
|
3
|
|
189438
|
use strict; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
86
|
|
3
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
442
|
|
4
|
|
|
|
|
|
|
|
5
|
0
|
|
|
|
|
0
|
BEGIN { |
6
|
3
|
|
|
3
|
|
14
|
local $@ = undef; |
7
|
3
|
|
|
|
|
7
|
my $ok = eval { |
8
|
3
|
|
|
|
|
1398
|
require JSON::MaybeXS; |
9
|
3
|
|
|
|
|
16641
|
JSON::MaybeXS->import('JSON'); |
10
|
3
|
|
|
|
|
10
|
1; |
11
|
|
|
|
|
|
|
}; |
12
|
|
|
|
|
|
|
|
13
|
3
|
50
|
|
|
|
15
|
unless($ok) { |
14
|
0
|
|
|
|
|
0
|
require JSON::PP; |
15
|
0
|
|
|
|
|
0
|
*JSON = sub() { 'JSON::PP' }; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
3
|
|
|
|
|
12
|
my $json = JSON()->new->utf8(1); |
19
|
|
|
|
|
|
|
|
20
|
14
|
|
|
14
|
0
|
218
|
sub encode_json { $json->encode(@_) } |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
3
|
|
1606
|
use Time::HiRes qw/time/; |
|
3
|
|
|
|
|
3341
|
|
|
3
|
|
|
|
|
18
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $VERSION = '0.000008'; |
26
|
|
|
|
|
|
|
|
27
|
3
|
|
|
3
|
|
1170
|
use Test2::Plugin::OpenFixPerlIO; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
93
|
|
28
|
3
|
|
|
3
|
|
1647
|
use IO::Handle; |
|
3
|
|
|
|
|
17257
|
|
|
3
|
|
|
|
|
1852
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our %MUXED; |
31
|
|
|
|
|
|
|
our %MUX_FILES; |
32
|
|
|
|
|
|
|
|
33
|
7
|
|
|
7
|
0
|
37
|
sub name { 'other' } |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub PUSHED { |
36
|
4
|
|
|
4
|
0
|
4274
|
my ($class, $mode, $handle) = @_; |
37
|
4
|
|
|
|
|
31
|
$handle->autoflush(1); |
38
|
4
|
|
|
|
|
210
|
bless {buffer => [], handle => $handle, count => 0}, $class; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub WRITE { |
42
|
16
|
|
|
16
|
|
131
|
my ($self, $buffer, $handle) = @_; |
43
|
|
|
|
|
|
|
|
44
|
16
|
|
|
|
|
41
|
my $count = ++$self->{count}; |
45
|
|
|
|
|
|
|
|
46
|
16
|
50
|
|
|
|
44
|
if ($self->{DIED}) { |
47
|
0
|
|
|
|
|
0
|
print $handle $buffer; |
48
|
0
|
|
|
|
|
0
|
return length($buffer); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
16
|
|
|
|
|
37
|
my $ok = eval { |
52
|
16
|
|
|
|
|
48
|
my $time = time; |
53
|
16
|
|
|
|
|
35
|
my $fileno = fileno($handle); |
54
|
|
|
|
|
|
|
|
55
|
16
|
|
|
|
|
78
|
my @parts = split /(\n)/, $buffer; |
56
|
16
|
50
|
66
|
|
|
68
|
unshift @parts => '' if @parts == 1 && $parts[0] eq "\n"; |
57
|
16
|
100
|
|
|
|
49
|
push @parts => undef if @parts % 2; |
58
|
16
|
|
|
|
|
64
|
my %parts = @parts; |
59
|
16
|
|
|
|
|
34
|
for my $part (@parts) { |
60
|
36
|
100
|
|
|
|
124
|
next unless defined $part; |
61
|
32
|
100
|
|
|
|
88
|
next if $part eq "\n"; |
62
|
|
|
|
|
|
|
|
63
|
18
|
|
|
|
|
65
|
my $about = {stamp => $time, fileno => $fileno, name => $self->name, buffer => $part, write_no => $count}; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Time to flush |
66
|
18
|
100
|
|
|
|
55
|
if ($parts{$part}) { |
67
|
14
|
|
|
|
|
42
|
$about->{buffer} .= $parts{$part}; # Put the \n back |
68
|
|
|
|
|
|
|
|
69
|
14
|
|
|
|
|
25
|
my $out; |
70
|
14
|
100
|
|
|
|
24
|
if (@{$self->{buffer}}) { |
|
14
|
|
|
|
|
65
|
|
71
|
2
|
|
|
|
|
6
|
push @{$self->{buffer}} => $about; |
|
2
|
|
|
|
|
6
|
|
72
|
|
|
|
|
|
|
$out = { |
73
|
|
|
|
|
|
|
parts => $self->{buffer}, |
74
|
|
|
|
|
|
|
%$about, |
75
|
2
|
|
|
|
|
10
|
buffer => join '' => map { $_->{buffer} } @{$self->{buffer}}, |
|
6
|
|
|
|
|
22
|
|
|
2
|
|
|
|
|
8
|
|
76
|
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Reset the buffer |
79
|
2
|
|
|
|
|
12
|
$self->{buffer} = []; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else { # Easy |
82
|
12
|
|
|
|
|
21
|
$out = $about; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
14
|
|
|
|
|
36
|
my $json = encode_json($out); |
86
|
14
|
|
|
|
|
41
|
my $mh = $MUX_FILES{$MUXED{$fileno}}; |
87
|
14
|
|
|
|
|
151
|
print $mh $json, "\n"; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
else { |
90
|
4
|
|
|
|
|
6
|
push @{$self->{buffer}} => $about; |
|
4
|
|
|
|
|
29
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
16
|
|
|
|
|
49
|
1; |
95
|
|
|
|
|
|
|
}; |
96
|
16
|
|
|
|
|
33
|
my $err = $@; |
97
|
|
|
|
|
|
|
|
98
|
16
|
|
|
|
|
237
|
print $handle $buffer; |
99
|
|
|
|
|
|
|
|
100
|
16
|
50
|
|
|
|
53
|
unless ($ok) { |
101
|
0
|
|
|
|
|
0
|
$self->{DIED}++; |
102
|
0
|
|
|
|
|
0
|
die $err; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
16
|
|
|
|
|
81
|
return length($buffer); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub DESTROY { |
109
|
4
|
|
|
4
|
|
114
|
my $self = shift; |
110
|
4
|
50
|
|
|
|
19
|
my $handle = $self->{handle} or return; |
111
|
4
|
50
|
|
|
|
14
|
my $buffer = $self->{buffer} or return; |
112
|
4
|
50
|
|
|
|
30
|
return unless @$buffer; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my $fileno = fileno($handle); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $out = { |
117
|
|
|
|
|
|
|
parts => $self->{buffer}, |
118
|
|
|
|
|
|
|
stamp => time, |
119
|
|
|
|
|
|
|
fileno => $fileno, |
120
|
|
|
|
|
|
|
name => $self->name, |
121
|
|
|
|
|
|
|
write_no => ++$self->{count}, |
122
|
|
|
|
|
|
|
DESTROY => 1, |
123
|
0
|
|
|
|
|
|
buffer => join '' => map { $_->{buffer} } @$buffer, |
|
0
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
}; |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my $json = encode_json($out); |
127
|
0
|
|
|
|
|
|
my $mh = $MUX_FILES{$MUXED{$fileno}}; |
128
|
0
|
|
|
|
|
|
print $mh $json, "\n"; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |