line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Formatter::EventStream; |
2
|
6
|
|
|
6
|
|
199300
|
use strict; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
154
|
|
3
|
6
|
|
|
6
|
|
45
|
use warnings; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
257
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000012'; |
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
24
|
use Test2::Util::HashBase qw/fh/; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
33
|
|
8
|
6
|
|
|
6
|
|
509
|
use base 'Test2::Formatter'; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
1081
|
|
9
|
6
|
|
|
6
|
|
1783
|
use IO::Handle; |
|
6
|
|
|
|
|
13947
|
|
|
6
|
|
|
|
|
305
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require Test2::Formatter::TAP; |
12
|
6
|
|
|
6
|
|
697
|
use Test2::Harness::JSON; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
2476
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub init { |
15
|
4
|
|
|
4
|
0
|
2661
|
my $self = shift; |
16
|
|
|
|
|
|
|
|
17
|
4
|
|
66
|
|
|
29
|
my $fh = $self->{+FH} ||= do { |
18
|
2
|
50
|
|
|
|
24
|
open(my $h, '>&', *STDOUT) or die "Could not clone STDOUT"; |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
6
|
my $old = select $h; |
21
|
2
|
|
|
|
|
2
|
$| = 1; |
22
|
2
|
|
|
|
|
3
|
select STDERR; |
23
|
2
|
|
|
|
|
3
|
$| = 1; |
24
|
2
|
|
|
|
|
3
|
select STDOUT; |
25
|
2
|
|
|
|
|
2
|
$| = 1; |
26
|
2
|
|
|
|
|
4
|
select $old; |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
8
|
$h; |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
4
|
|
|
|
|
11
|
print $fh "T2_FORMATTER: EventStream\n"; |
32
|
|
|
|
|
|
|
|
33
|
4
|
100
|
|
|
|
18
|
if(my $enc = delete $self->{encoding}) { |
34
|
2
|
|
|
|
|
5
|
$self->encoding($enc); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub write { |
39
|
4
|
|
|
4
|
0
|
74
|
my ($self, $e) = @_; |
40
|
|
|
|
|
|
|
|
41
|
4
|
|
|
|
|
9
|
my $json = $self->_event_to_json($e); |
42
|
|
|
|
|
|
|
|
43
|
4
|
|
|
|
|
5
|
my $fh = $self->{+FH}; |
44
|
4
|
|
|
|
|
19
|
print $fh "T2_EVENT: $json\n"; |
45
|
4
|
|
|
|
|
12
|
$fh->flush; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
{ |
49
|
|
|
|
|
|
|
my $J = JSON->new; |
50
|
|
|
|
|
|
|
$J->indent(0); |
51
|
|
|
|
|
|
|
$J->convert_blessed(1); |
52
|
|
|
|
|
|
|
$J->allow_blessed(1); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _event_to_json { |
55
|
6
|
|
|
6
|
|
17
|
my ($self, $e) = @_; |
56
|
|
|
|
|
|
|
|
57
|
6
|
|
|
|
|
7
|
my $json = eval { $J->encode($e) }; |
|
6
|
|
|
|
|
98
|
|
58
|
6
|
|
|
|
|
102
|
my $error = $@; |
59
|
6
|
50
|
|
|
|
24
|
return $json if $json; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
require Data::Dumper; |
62
|
0
|
|
|
|
|
0
|
die "JSON encoding error: $error\n" . Data::Dumper::Dumper($e); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
2
|
|
|
2
|
0
|
15
|
sub hide_buffered { 0 } |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub encoding { |
69
|
4
|
|
|
4
|
0
|
1737
|
my $self = shift; |
70
|
|
|
|
|
|
|
|
71
|
4
|
50
|
|
|
|
8
|
if (@_) { |
72
|
4
|
|
|
|
|
6
|
my ($enc) = @_; |
73
|
|
|
|
|
|
|
|
74
|
4
|
|
|
|
|
5
|
my $fh = $self->{+FH}; |
75
|
4
|
|
|
|
|
13
|
print $fh "T2_ENCODING: $enc\n"; |
76
|
4
|
|
|
|
|
34
|
$fh->flush; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# https://rt.perl.org/Public/Bug/Display.html?id=31923 |
79
|
|
|
|
|
|
|
# If utf8 is requested we use ':utf8' instead of ':encoding(utf8)' in |
80
|
|
|
|
|
|
|
# order to avoid the thread segfault. |
81
|
4
|
50
|
|
|
|
23
|
if ($enc =~ m/^utf-?8$/i) { |
82
|
4
|
|
|
|
|
18
|
binmode($fh, ":utf8"); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else { |
85
|
0
|
|
|
|
|
0
|
binmode($fh, ":encoding($enc)"); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub DESTROY { |
91
|
4
|
|
|
4
|
|
3161
|
my $self = shift; |
92
|
4
|
50
|
|
|
|
15
|
my $fh = $self->{+FH} or return; |
93
|
4
|
|
|
|
|
5
|
eval { $fh->flush }; |
|
4
|
|
|
|
|
113
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |