line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Devel::REPL::Client::AnyEvent; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
595
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
331
|
use Devel::REPL::Client::AnyEvent::Connection; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
489
|
use AnyEvent::Socket; |
|
1
|
|
|
|
|
9682
|
|
|
1
|
|
|
|
|
97
|
|
9
|
1
|
|
|
1
|
|
5
|
use Scalar::Util qw(weaken); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
10
|
1
|
|
|
1
|
|
4
|
use Term::ReadKey; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
59
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use constant { |
13
|
1
|
|
|
|
|
273
|
EOT => "\x04", |
14
|
1
|
|
|
1
|
|
4
|
}; |
|
1
|
|
|
|
|
2
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $RESTORE_READMODE; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
END { |
19
|
|
|
|
|
|
|
ReadMode 0, \*STDIN if $RESTORE_READMODE; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
0
|
|
|
0
|
0
|
|
my ($class, %args) = @_; |
24
|
|
|
|
|
|
|
my $self = bless { |
25
|
|
|
|
|
|
|
port => $args{port}, |
26
|
|
|
|
|
|
|
path => $args{path}, |
27
|
|
|
|
|
|
|
mode => $args{mode}, |
28
|
|
|
|
|
|
|
on_connection => $args{on_connection}, |
29
|
0
|
|
|
|
|
|
tcp_guard => undef, |
30
|
|
|
|
|
|
|
}, $class; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
return $self; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub listen { |
36
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $weak_self = $self; |
39
|
0
|
|
|
|
|
|
weaken($weak_self); |
40
|
0
|
|
|
0
|
|
|
my $cb = sub { $weak_self->_new_connection($_[0]) }; |
|
0
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $prepare = ($self->{path} && defined $self->{mode}) ? sub { |
42
|
|
|
|
|
|
|
chmod $weak_self->{mode}, $weak_self->{path} |
43
|
0
|
0
|
|
0
|
|
|
or die "Unable to change file mode for socket: $!"; |
44
|
0
|
0
|
0
|
|
|
|
} : undef; |
45
|
0
|
0
|
|
|
|
|
if ($self->{port}) { |
|
|
0
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$self->{tcp_guard} = tcp_server('127.0.0.1', $self->{port}, $cb); |
47
|
|
|
|
|
|
|
} elsif ($self->{path}) { |
48
|
0
|
|
|
|
|
|
$self->{tcp_guard} = tcp_server('unix/', $self->{path}, $cb, $prepare); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _new_connection { |
53
|
0
|
|
|
0
|
|
|
my ($self, $fh) = @_; |
54
|
0
|
|
|
|
|
|
my $connection = Devel::REPL::Client::AnyEvent::Connection->new(socket => $fh); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$RESTORE_READMODE = 1; |
57
|
0
|
|
|
|
|
|
ReadMode 3, \*STDIN; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$self->{on_connection}->($connection); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |