Skip to content

Instantly share code, notes, and snippets.

@zoffixznet

zoffixznet/md.md Secret

Last active February 21, 2018 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/8a73776b3cd7e3b3df2c02c242dc8763 to your computer and use it in GitHub Desktop.
Save zoffixznet/8a73776b3cd7e3b3df2c02c242dc8763 to your computer and use it in GitHub Desktop.

Based on the module-source-finding code I have from the designer of the CompUnit system, what you have is basically as simple as it gets. The only difference I see is they used $*REPO.need, which also throws if it can't find a module:

my @installed = installed-modules <Digest::MD5 Test NotThere PrettyDump>;

sub installed-modules {
    gather for @_ -> $mod {
        put $mod, '-' x 15;
        (try $*REPO.need: CompUnit::DependencySpecification.new:  :short-name($mod))
            andthen       "Found $mod".put and $mod.take
            orelse  "Didn't find $mod".put
    }
}

require returns the loaded module on successful load, so you can just assign it to a variable right there and then:

put "Already installed: @installed[]";
(my $digest = (try require ::(@installed.head)).new) === Nil
      and die "Failed to load @installed.head"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment