I was playing around with a plugin thingy that would load things that were available. The docs on the $*REPO
is not quite there so I guessed a bit. This seems to work but I have the feeling I'm missing something simpler (besides the regular golfing on the other bits):
my @modules = <Digest::MD5 NotThere PrettyDump>;
my @installed = gather installed-modules( @modules );
put "Already installed: @installed[]";
try require ::( @installed[0] );
# is there a better way to do this without eval
my $digest = ::( @installed[0] ).new;
sub installed-modules ( *@candidates ) {
for @candidates -> $module {
put $module, '-' x 15;
my $ds = CompUnit::DependencySpecification.new:
:short-name($module);
if $*REPO.resolve: $ds {
put "Found $module";
take $module;
}
else {
put "Didn't find $module";
}
}
}
You need to use instmodsh (interactive inventory for installed Perl modules) command to find out what modules already installed on my system. instmodsh command provides an interactive shell type interface to query details of locally installed Perl modules.
Perl packages should install module files into /usr/lib/perl5/$version/vendor_perl/ (use perl -V:vendorarch in scripts), or /usr/share/perl5/vendor_perl/ .
$*REPO.resolve(CompUnit::DependencySpecification.new(:short-name<Test>))
Note that this is only useful to a certain degree as this only tells you if a module can be resolved. What I mean by this is it would also detect a non-installed module being provided by a directory such as -I lib
, and you won't know which CompUnit::Repository it came from. You could also grep the results of something like $*REPO.repo-chain.grep(* ~~ CompUnit::Repository::Installable).map(*.installed).flat
Additionally the meaning of an "installed" module is not so simple -- CompUnit::Repository::Installable
repositories are what is likely implied, but consider a third party CompUnit::Repository ( such as https://github.com/ugexe/Perl6-CompUnit--Repository--Tar ) -- with this modules are essentially still installed, but the repo itself is not CompUnit::Repository::Installable
. All ::Installable really means in rakudo is that rakudo knows how to install it -- it has nothing to do with what rakudo knows how to find and load
Some PRs ( closed, but I will revisit eventually ) that help address some of these problems via a method candidates { ... }
:
https://github.com/rakudo/rakudo/pull/1125
https://github.com/rakudo/rakudo/pull/1132
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With