line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Formatter::EventStream; |
2
|
6
|
|
|
6
|
|
215961
|
use strict; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
159
|
|
3
|
6
|
|
|
6
|
|
43
|
use warnings; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
285
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000013'; |
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
22
|
use Test2::Util::HashBase qw/fh/; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
31
|
|
8
|
6
|
|
|
6
|
|
455
|
use base 'Test2::Formatter'; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
980
|
|
9
|
6
|
|
|
6
|
|
1705
|
use IO::Handle; |
|
6
|
|
|
|
|
12864
|
|
|
6
|
|
|
|
|
327
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require Test2::Formatter::TAP; |
12
|
6
|
|
|
6
|
|
670
|
use Test2::Harness::JSON; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
2515
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub init { |
15
|
4
|
|
|
4
|
0
|
3431
|
my $self = shift; |
16
|
|
|
|
|
|
|
|
17
|
4
|
|
66
|
|
|
33
|
my $fh = $self->{+FH} ||= do { |
18
|
2
|
50
|
|
|
|
24
|
open(my $h, '>&', *STDOUT) or die "Could not clone STDOUT"; |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
5
|
my $old = select $h; |
21
|
2
|
|
|
|
|
3
|
$| = 1; |
22
|
2
|
|
|
|
|
2
|
select STDERR; |
23
|
2
|
|
|
|
|
2
|
$| = 1; |
24
|
2
|
|
|
|
|
3
|
select STDOUT; |
25
|
2
|
|
|
|
|
2
|
$| = 1; |
26
|
2
|
|
|
|
|
4
|
select $old; |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
7
|
$h; |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
4
|
|
|
|
|
12
|
print $fh "T2_FORMATTER: EventStream\n"; |
32
|
|
|
|
|
|
|
|
33
|
4
|
100
|
|
|
|
18
|
if(my $enc = delete $self->{encoding}) { |
34
|
2
|
|
|
|
|
7
|
$self->encoding($enc); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub write { |
39
|
4
|
|
|
4
|
0
|
84
|
my ($self, $e) = @_; |
40
|
|
|
|
|
|
|
|
41
|
4
|
|
|
|
|
8
|
my $json = $self->_event_to_json($e); |
42
|
|
|
|
|
|
|
|
43
|
4
|
|
|
|
|
8
|
my $fh = $self->{+FH}; |
44
|
4
|
|
|
|
|
23
|
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
|
|
16
|
my ($self, $e) = @_; |
56
|
|
|
|
|
|
|
|
57
|
6
|
|
|
|
|
7
|
my $json = eval { $J->encode($e) }; |
|
6
|
|
|
|
|
81
|
|
58
|
6
|
|
|
|
|
111
|
my $error = $@; |
59
|
6
|
50
|
|
|
|
22
|
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
|
12
|
sub hide_buffered { 0 } |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub encoding { |
69
|
4
|
|
|
4
|
0
|
1660
|
my $self = shift; |
70
|
|
|
|
|
|
|
|
71
|
4
|
50
|
|
|
|
11
|
if (@_) { |
72
|
4
|
|
|
|
|
5
|
my ($enc) = @_; |
73
|
|
|
|
|
|
|
|
74
|
4
|
|
|
|
|
8
|
my $fh = $self->{+FH}; |
75
|
4
|
|
|
|
|
12
|
print $fh "T2_ENCODING: $enc\n"; |
76
|
4
|
|
|
|
|
40
|
$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
|
|
|
|
32
|
if ($enc =~ m/^utf-?8$/i) { |
82
|
4
|
|
|
|
|
22
|
binmode($fh, ":utf8"); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else { |
85
|
0
|
|
|
|
|
0
|
binmode($fh, ":encoding($enc)"); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub DESTROY { |
91
|
4
|
|
|
4
|
|
3068
|
my $self = shift; |
92
|
4
|
50
|
|
|
|
16
|
my $fh = $self->{+FH} or return; |
93
|
4
|
|
|
|
|
6
|
eval { $fh->flush }; |
|
4
|
|
|
|
|
113
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |