line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Devel::REPL::Client::AnyEvent::Connection; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
617
|
use AnyEvent::Handle; |
|
1
|
|
|
|
|
13925
|
|
|
1
|
|
|
|
|
32
|
|
7
|
1
|
|
|
1
|
|
6
|
use Scalar::Util qw(weaken); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
8
|
1
|
|
|
1
|
|
3
|
use Term::ReadKey; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
62
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use constant { |
11
|
1
|
|
|
|
|
356
|
EOT => "\x04", |
12
|
1
|
|
|
1
|
|
4
|
}; |
|
1
|
|
|
|
|
2
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
0
|
|
|
0
|
0
|
|
my ($class, %args) = @_; |
16
|
0
|
|
|
|
|
|
my $self = bless { |
17
|
|
|
|
|
|
|
handle => undef, |
18
|
|
|
|
|
|
|
input => undef, |
19
|
|
|
|
|
|
|
on_close => undef, |
20
|
|
|
|
|
|
|
}, $class; |
21
|
0
|
|
|
|
|
|
my $weak_self = $self; |
22
|
0
|
|
|
|
|
|
weaken($weak_self); |
23
|
|
|
|
|
|
|
my $handle = AnyEvent::Handle->new( |
24
|
|
|
|
|
|
|
fh => $args{socket}, |
25
|
|
|
|
|
|
|
on_error => sub { |
26
|
0
|
|
|
0
|
|
|
my ($handle, $fatal, $message) = @_; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
$weak_self->{handle} = $weak_self->{watch} = undef; |
29
|
0
|
|
|
|
|
|
$handle->destroy; |
30
|
|
|
|
|
|
|
$weak_self->{on_close}->($weak_self) |
31
|
0
|
0
|
|
|
|
|
if $weak_self->{on_close}; |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
on_read => sub { |
34
|
0
|
|
|
0
|
|
|
my ($handle) = @_; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
syswrite *STDOUT, $handle->{rbuf}; |
37
|
0
|
|
|
|
|
|
substr $handle->{rbuf}, 0, length($handle->{rbuf}), ''; |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
on_eof => sub { |
40
|
0
|
|
|
0
|
|
|
my ($handle) = @_; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$weak_self->{handle} = $weak_self->{watch} = undef; |
43
|
0
|
|
|
|
|
|
$handle->destroy; |
44
|
|
|
|
|
|
|
$weak_self->{on_close}->($weak_self) |
45
|
0
|
0
|
|
|
|
|
if $weak_self->{on_close}; |
46
|
|
|
|
|
|
|
}, |
47
|
0
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
my $watch = AnyEvent->io( |
49
|
|
|
|
|
|
|
fh => \*STDIN, |
50
|
|
|
|
|
|
|
poll => 'r', |
51
|
|
|
|
|
|
|
cb => sub { |
52
|
0
|
|
|
0
|
|
|
while (defined(my $key = ReadKey -1, \*STDIN)) { |
53
|
0
|
|
|
|
|
|
$handle->push_write($key); |
54
|
0
|
0
|
|
|
|
|
if ($key eq EOT) { |
55
|
0
|
|
|
|
|
|
print STDOUT "^D\n"; |
56
|
0
|
|
|
|
|
|
$handle->push_shutdown; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
}, |
60
|
0
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
$self->{handle} = $handle; |
63
|
0
|
|
|
|
|
|
$self->{watch} = $watch; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return $self; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub DESTROY { |
69
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$self->close; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
0
|
0
|
|
sub on_close { $_[0]->{on_close} = $_[1] } |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub close { |
77
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
0
|
|
|
|
$self->{handle}->destroy if $self->{handle} && !$self->{handle}->destroyed; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |