The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.
#!/usr/bin/env perl

use strictures 1;
use Eval::WithLexicals;
use Term::ReadLine;
use Data::Dumper;
use Getopt::Long;

GetOptions(
  "plugin=s" => \my @plugins
);

$SIG{INT} = sub { warn "SIGINT\n" };

{ package Data::Dumper; no strict 'vars';
  $Terse = $Indent = $Useqq = $Deparse = $Sortkeys = 1;
  $Quotekeys = 0;
}

my $eval = @plugins
 ? Eval::WithLexicals->with_plugins(@plugins)->new
 : Eval::WithLexicals->new;

my $read = Term::ReadLine->new('Perl REPL');
while (1) {
  my $line = $read->readline('re.pl$ ');
  exit unless defined $line;
  my @ret; eval {
    local $SIG{INT} = sub { die "Caught SIGINT" };
    @ret = $eval->eval($line); 1;
  } or @ret = ("Error!", $@);
  print Dumper @ret;
}