Skip to content
This repository
tree: 9e5350d8b5
Fetching contributors…

Cannot retrieve contributors at this time

file 29 lines (23 sloc) 0.761 kb
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 29
class NieczaPathSearch;

has @.path;

# Given Foo::Bar, find ($?FILE, $?ORIG)
method load_module($name) {
    my $sub = "".IO.combine($name.split('::'));

    my @path = ($*unit ?? $*unit.get_incs !! ()), @!path;

    for @path -> $pe {
        for <pm6 pm setting> -> $ext {
            my $fn = $pe.IO.append($sub).but-extension($ext);
            if $fn.f {
                my $text = $fn.slurp;
                # check borrowed from STD to weed out Perl 5 heuristically
                next if $ext eq 'pm' && $text ~~ /^^\h*package\h+\w+\s*\;/;
                return ~$fn.realpath, $text;
            }
        }
    }

    die "Unable to locate module $name in @path[]";
}

method load_file($name) {
    my $p = $name.IO;
    (~$p.realpath, $p.slurp);
}
Something went wrong with that request. Please try again.