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