1 package Devel::REPL::Plugin::AutoloadModules;
 
   4 use namespace::clean -except => [ 'meta' ];
 
   7 has 'autoloaded' => ( is => 'rw', isa => 'HashRef', default => sub { {} } );
 
   9 my $re = qr/Runtime error: Can.t locate object method "\w+" via package "\w+" \(perhaps you forgot to load "(\w+)"\?\)/;
 
  10 around 'execute' => sub {
 
  14   my @re = $self->$orig(@_);                           # original call
 
  16   return @re unless defined $re[0] && $re[0] =~ /$re/; # if there is no "perhaps you forgot" error, just return
 
  17   my $module = $1;                                     # save the missing package name
 
  19   return @re if $self->autoloaded->{$module};          # if we tried to load it before, give up and return the error
 
  21   $self->autoloaded->{$module} = 1;                    # make sure we don't try this again
 
  22   $self->eval("use SL::$module");                      # try to load the missing module
 
  24   @re = $self->$orig(@_);                              # try again