summaryrefslogtreecommitdiffstats
path: root/lib/App/REPL/Plugin/LoadClass.pm
blob: 9a48b22701489a6a182e55cf0831365c874ecb8a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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;