<commit_before>role  CompUnitRepo::Locally             { ... }
class CompUnitRepo::Local::File         { ... }
class CompUnitRepo::Local::Installation { ... }

class CompUnitRepo {
    my Mu $p6ml := nqp::gethllsym('perl6', 'ModuleLoader');
    my $lock     = Lock.new;
    my %modules_loaded;

    my %language_module_loaders =
        'NQP' => nqp::gethllsym('nqp', 'ModuleLoader'),
    ;

    method register_language_module_loader($lang, $loader, :$force) {
        nqp::die("Language loader already registered for $lang")
            if ! $force && nqp::existskey(%language_module_loaders, $lang);
        %language_module_loaders{$lang} := $loader;
    }

    method new(Str $spec) { INCLUDE-SPEC2CUR($spec) }

    method files($file, :$name, :$auth, :$ver) {
        for @*INC -> $spec {
            if INCLUDE-SPEC2CUR($spec) -> $cur {
                if $cur.files($file, :$name,:$auth,:$ver).list -> @candi {
                    return @candi;
                }
            }
        }
        ();
    }

    method candidates($name, :$file, :$auth, :$ver) {
        for @*INC -> $spec {

RAKUDO_MODULE_DEBUG("Looking in $spec for $name")
  if $?RAKUDO_MODULE_DEBUG;

            if INCLUDE-SPEC2CUR($spec) -> $cur {
                if $cur.candidates($name, :$file,:$auth,:$ver).list -> @candi {
                    return @candi;
                }
            }
        }
        ();
    }

    method p6ml { $p6ml }

    method load_module($module_name, %opts, \GLOBALish is rw, :$line, :$file) {
        RAKUDO_MODULE_DEBUG("going to load $module_name: %opts.perl()") if $?RAKUDO_MODULE_DEBUG;
        $lock.protect( {
        if %opts<from> && %opts<from> eq 'NQP' {
            $p6ml.load_module($module_name, %opts, GLOBALish, :$line, :$file);
        }
        else {
            my %chosen;
            # See if we need to load it from elsewhere.
            if %opts<from> {
                if %language_module_loaders{%opts<from>}:exists {
                    RAKUDO_MODULE_DEBUG("going to load $module_name from '%opts<from>'") if $?RAKUDO_MODULE_DEBUG;
                    return %language_module_loaders{%opts<from>}.load_module($module_name,
                        %opts, GLOBALish, :$line, :$file);
                }
                else {
                    nqp::die("Do not know how to load code from " ~ %opts<from>);
                }
            }
            elsif $file {
                %chosen<key> := %chosen<pm> := ~$file.IO.abspath;
            }
            else {
                my $candi = self.candidates($module_name, :auth(%opts<auth>), :ver(%opts<ver>))[0];
                if $candi {
                    %chosen<pm>   :=
                      $candi<provides>{$module_name}<pm><file> //
                      $candi<provides>{$module_name}<pm6><file>;<commit_msg>simplify handling of "use ...:from<...>"<commit_after>role  CompUnitRepo::Locally             { ... }
class CompUnitRepo::Local::File         { ... }
class CompUnitRepo::Local::Installation { ... }

class CompUnitRepo {
    my $lock     = Lock.new;
    my %modules_loaded;

    my %language_module_loaders =
        # We're using Perl6::ModuleLoader instead of NQP's here,
        # so it can special-cases NQP wrt GLOBALish correctly.
        'NQP' => nqp::gethllsym('perl6', 'ModuleLoader'),
    ;

    method register_language_module_loader($lang, $loader, :$force) {
        nqp::die("Language loader already registered for $lang")
            if ! $force && nqp::existskey(%language_module_loaders, $lang);
        %language_module_loaders{$lang} := $loader;
    }

    method new(Str $spec) { INCLUDE-SPEC2CUR($spec) }

    method files($file, :$name, :$auth, :$ver) {
        for @*INC -> $spec {
            if INCLUDE-SPEC2CUR($spec) -> $cur {
                if $cur.files($file, :$name,:$auth,:$ver).list -> @candi {
                    return @candi;
                }
            }
        }
        ();
    }

    method candidates($name, :$file, :$auth, :$ver) {
        for @*INC -> $spec {

RAKUDO_MODULE_DEBUG("Looking in $spec for $name")
  if $?RAKUDO_MODULE_DEBUG;

            if INCLUDE-SPEC2CUR($spec) -> $cur {
                if $cur.candidates($name, :$file,:$auth,:$ver).list -> @candi {
                    return @candi;
                }
            }
        }
        ();
    }

    method load_module($module_name, %opts, \GLOBALish is rw, :$line, :$file) {
        RAKUDO_MODULE_DEBUG("going to load $module_name: %opts.perl()") if $?RAKUDO_MODULE_DEBUG;
        $lock.protect( {
        if %opts<from> {
            # See if we need to load it from elsewhere.
            if %language_module_loaders{%opts<from>}:exists {
                return %language_module_loaders{%opts<from>}.load_module($module_name,
                    %opts, GLOBALish, :$line, :$file);
            }
            else {
                nqp::die("Do not know how to load code from " ~ %opts<from>);
            }
        }
        else {
            my %chosen;
            if $file {
                %chosen<key> := %chosen<pm> := ~$file.IO.abspath;
            }
            else {
                my $candi = self.candidates($module_name, :auth(%opts<auth>), :ver(%opts<ver>))[0];
                if $candi {
                    %chosen<pm>   :=
                      $candi<provides>{$module_name}<pm><file> //
                      $candi<provides>{$module_name}<pm6><file>;
{'fraction_non_alphanumeric': 0.15173945225758698, 'fraction_numerical': 0.003145817912657291, 'mean_word_length': 1.8121748178980228, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4977721', 'n_tokens_mistral': 1814, 'n_tokens_neox': 1707, 'n_words': 330}