1 package Devel::REPL::Plugin::Interrupt;
3 use Devel::REPL::Plugin;
4 use Sys::SigAction qw(set_sig_handler);
8 my ($orig, $self) = (shift, shift);
10 local $SIG{INT} = 'IGNORE';
12 return $self->$orig(@_);
15 around 'run_once' => sub {
16 my ($orig, $self) = (shift, shift);
18 # We have to use Sys::SigAction: Perl 5.8+ has safe signal handling by
19 # default, and Term::ReadLine::Gnu restarts the interrupted system calls.
20 # The result is that the signal handler is not fired until you hit Enter.
21 my $sig_action = set_sig_handler INT => sub {
25 return $self->$orig(@_);
28 around 'read' => sub {
29 my ($orig, $self) = (shift, shift);
31 # here SIGINT is caught and only kills the line being edited
33 my $line = eval { $self->$orig(@_) };
34 return $line unless $@;
36 die unless $@ =~ /^Interrupted\./;
38 # (Term::ReadLine::Gnu kills the line by default, but needs a LF -
39 # maybe I missed something?)
50 Devel::REPL::Plugin::Interrupt - traps SIGINT to kill long-running lines
54 By default L<Devel::REPL> exits on SIGINT (usually Ctrl-C). If you load this
55 module, SIGINT will be trapped and used to kill long-running commands
56 (statements) and also to kill the line being edited (like eg. BASH do). (You
57 can still use Ctrl-D to exit.)
61 Shawn M Moore, C<< <sartak at gmail dot com> >>