line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Plugin::IOEvents::Tie; |
2
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.001000'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use Test2::API qw/context/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
98
|
|
8
|
1
|
|
|
1
|
|
7
|
use Carp qw/croak/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
214
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub TIEHANDLE { |
11
|
2
|
|
|
2
|
|
5
|
my $class = shift; |
12
|
2
|
|
|
|
|
4
|
my ($name, $fn, $fh) = @_; |
13
|
|
|
|
|
|
|
|
14
|
2
|
50
|
33
|
|
|
7
|
unless ($fn && $fh) { |
15
|
2
|
50
|
|
|
|
9
|
if ($fn) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
16
|
0
|
|
|
|
|
0
|
open($fh, '>&', $fn); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
elsif ($name eq 'STDOUT') { |
19
|
1
|
|
|
|
|
2
|
$fn = fileno(STDOUT); |
20
|
1
|
|
|
|
|
28
|
open($fh, '>&', STDOUT); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
elsif ($name eq 'STDERR') { |
23
|
1
|
|
|
|
|
9
|
$fn = fileno(STDERR); |
24
|
1
|
|
|
|
|
22
|
open($fh, '>&', STDERR); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
20
|
return bless([$name, $fn, $fh], $class); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub OPEN { |
32
|
1
|
|
|
1
|
|
8
|
no warnings 'uninitialized'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
560
|
|
33
|
|
|
|
|
|
|
|
34
|
1
|
50
|
|
1
|
|
3679
|
if ($_[0]->[0] eq 'STDOUT') { |
|
|
0
|
|
|
|
|
|
35
|
1
|
|
|
|
|
22
|
untie(*STDOUT); |
36
|
1
|
50
|
|
|
|
29
|
return open(STDOUT, $_[1], @_ > 2 ? $_[2] : ()); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif ($_[0]->[0] eq 'STDERR') { |
39
|
0
|
|
|
|
|
0
|
untie(*STDERR); |
40
|
0
|
0
|
|
|
|
0
|
return open(STDERR, $_[1], @_ > 2 ? $_[2] : ()); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
0
|
return; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub PRINT { |
47
|
8
|
|
|
8
|
|
3499
|
my $self = shift; |
48
|
8
|
|
|
|
|
19
|
my ($name) = @$self; |
49
|
|
|
|
|
|
|
|
50
|
8
|
50
|
|
|
|
28
|
my $output = defined($,) ? join( $,, @_) : join('', @_); |
51
|
|
|
|
|
|
|
|
52
|
8
|
50
|
|
|
|
20
|
return unless length($output); |
53
|
|
|
|
|
|
|
|
54
|
8
|
|
|
|
|
22
|
my $ctx = context(); |
55
|
8
|
100
|
|
|
|
796
|
$ctx->send_ev2_and_release( |
56
|
|
|
|
|
|
|
info => [ |
57
|
|
|
|
|
|
|
{tag => $name, details => $output, $name eq 'STDERR' ? (debug => 1) : ()}, |
58
|
|
|
|
|
|
|
] |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub FILENO { |
63
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
64
|
0
|
|
|
|
|
0
|
return $self->[1]; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub PRINTF { |
68
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
69
|
0
|
|
|
|
|
0
|
my ($format, @list) = @_; |
70
|
0
|
|
|
|
|
0
|
my ($name) = @$self; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
0
|
my $output = sprintf($format, @list); |
73
|
0
|
0
|
|
|
|
0
|
return unless length($output); |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
my $ctx = context(); |
76
|
0
|
0
|
|
|
|
0
|
$ctx->send_ev2_and_release( |
77
|
|
|
|
|
|
|
info => [ |
78
|
|
|
|
|
|
|
{tag => $name, details => $output, $name eq 'STDERR' ? (debug => 1) : ()}, |
79
|
|
|
|
|
|
|
] |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
0
|
|
0
|
sub CLOSE { 1 } |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub WRITE { |
86
|
1
|
|
|
1
|
|
10485
|
my $self = shift; |
87
|
1
|
|
|
|
|
3
|
my ($buf, $len, $offset) = @_; |
88
|
1
|
50
|
|
|
|
5
|
return syswrite($self->[2], $buf) if @_ == 1; |
89
|
1
|
50
|
|
|
|
16
|
return syswrite($self->[2], $buf, $len) if @_ == 2; |
90
|
0
|
|
|
|
|
|
return syswrite($self->[2], $buf, $len, $offset); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub BINMODE { |
94
|
0
|
|
|
0
|
|
|
my $self = shift; |
95
|
0
|
0
|
|
|
|
|
return binmode($self->[2]) unless @_; |
96
|
0
|
|
|
|
|
|
return binmode($self->[2], $_[0]); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub autoflush { |
100
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
if (@_) { |
103
|
0
|
|
|
|
|
|
my ($val) = @_; |
104
|
0
|
|
|
|
|
|
$self->[2]->autoflush($val); |
105
|
0
|
|
|
|
|
|
$self->[3] = $val; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
return $self->[3]; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |