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);
26 $repl_server ||= Thrasher
::Plugin
::REPL
->new(
27 'event_loop' => $component->{'event_loop'},
30 # path in abstract namespace instead of FS
32 . '/Thrasher/REPL/' . $component->{'component_name'},
39 'main_loop' => { 'Integrate REPL' => \
&integrate_repl
},
43 ### REPL::Server callbacks
46 my ($self, @words) = @_;
48 if ($self->{'debug'}) {
49 my $line = join(' ', @words);
50 Thrasher
::Log
::debug
($line, $self->{'debug'});
57 $self->SUPER::cb_listen
();
59 $self->{'event_loop'}->add_fd_watch(
60 $self->{'server'}->fileno(),
61 $Thrasher::EventLoop
::IN
,
72 $self->SUPER::cb_connect
();
74 $self->{'fh_watch_id'} =
75 $self->{'event_loop'}->add_fd_watch(
76 $self->{'fh'}->fileno(),
77 $Thrasher::EventLoop
::IN
,
79 return $self->interact();
87 $self->SUPER::cb_disconnect
();
89 if ($self->{'fh_watch_id'}) {
90 $self->{'event_loop'}->remove_fd_watch($self->{'fh_watch_id'});
91 $self->{'fh_watch_id'} = undef;