1 package Thrasher
::Plugin
::REPL
;
5 use Thrasher
::EventLoop
;
7 use Thrasher
::Plugin
qw(register_plugin);
11 # Subclass that integrates itself into a Thrasher::EventLoop.
13 # Warning 1: Anyone who can connect to the REPL port can inject
14 # arbitrary Perl code into the Thrasher process. The only security
15 # measure currently used is binding only to the IPv4 loopback
18 # Warning 2: A REPL iteration blocks the main loop, so it would be
19 # best to avoid long-lived computations!
20 use base
qw(Net::REPL::Server);
22 # TODO: through Thrasher::start-ish configuration.
31 'Warning: REPL plugin loaded but no no repl_port configured?');
35 $repl_server ||= Thrasher
::Plugin
::REPL
->new(
36 'event_loop' => $component->{'event_loop'},
39 'LocalAddr' => '127.0.0.1',
40 'LocalPort' => $repl_port,
47 'main_loop' => { 'Integrate REPL' => \
&integrate_repl
},
51 ### REPL::Server callbacks
54 my ($self, @words) = @_;
56 if ($self->{'debug'}) {
57 my $line = join(' ', @words);
58 Thrasher
::Log
::debug
($line, $self->{'debug'});
65 $self->SUPER::cb_listen
();
67 $self->{'event_loop'}->add_fd_watch(
68 $self->{'server'}->fileno(),
69 $Thrasher::EventLoop
::IN
,
80 $self->SUPER::cb_connect
();
82 $self->{'fh_watch_id'} =
83 $self->{'event_loop'}->add_fd_watch(
84 $self->{'fh'}->fileno(),
85 $Thrasher::EventLoop
::IN
,
87 return $self->interact();
95 $self->SUPER::cb_disconnect
();
97 if ($self->{'fh_watch_id'}) {
98 $self->{'event_loop'}->remove_fd_watch($self->{'fh_watch_id'});
99 $self->{'fh_watch_id'} = undef;