diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-05-30 04:26:53 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-05-30 04:26:53 -0500 |
commit | 69e4ff7c28debe5cae5bd505d5df12bd12bdd11a (patch) | |
tree | 5c7402b86d2be05155c8cf9637a3ea7881f5ca29 /lib | |
parent | 071e98547d4dda83c29ea87cd4cff9115667bf24 (diff) | |
download | reply-69e4ff7c28debe5cae5bd505d5df12bd12bdd11a.tar.gz reply-69e4ff7c28debe5cae5bd505d5df12bd12bdd11a.zip |
LoadClass plugin
Diffstat (limited to 'lib')
-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; |