diff options
Diffstat (limited to 'lib/App/REPL')
-rw-r--r-- | lib/App/REPL/Plugin/LoadClass.pm | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/App/REPL/Plugin/LoadClass.pm b/lib/App/REPL/Plugin/LoadClass.pm new file mode 100644 index 0000000..9a48b22 --- /dev/null +++ b/lib/App/REPL/Plugin/LoadClass.pm @@ -0,0 +1,28 @@ +package App::REPL::Plugin::LoadClass; +use strict; +use warnings; + +use base 'App::REPL::Plugin'; + +use Module::Runtime 'use_package_optimistically'; +use Try::Tiny; + +sub execute { + my $self = shift; + my ($next, @args) = @_; + + try { + $next->(@args); + } + catch { + if (/^Can't locate object method "[^"]*" via package "([^"]*)"/) { + use_package_optimistically($1); + $next->(@args); + } + else { + die $_; + } + } +} + +1; |