I have Raku installed in ~/.rakudo-star/rakudo-star-2018.04
, using LoneStar. When zef
installs a module, it gets installed into a subdirectory of the Rakudo directory. In here is a directory named perl6/site/resources
, which seem to hold all the installed files. How can I figure out which module is contained in which file, using Raku?
How to calculate a module's dist hash
230 Views Asked by Tyil At
2
There are 2 best solutions below
3

If you want to get the source of a namespace that would get loaded you can do:
my $module-name = 'Test';
# Get a Distribution object which provides an IO interface to its contents
my $compunit = $*REPO.resolve(CompUnit::DependencySpecification.new(:short-name{$module-name}));
my $distribution = $compunit.distribution;
my $handle-from-name = $distribution.content($distribution.meta<provides>{$module-name}.keys[0]).open;
say $handle-from-name.slurp(:close);
# Or if we already know the name-path:
my $handle-from-path = $distribution.content("lib/Test.rakumod").open;
say $handle-from-path.slurp(:close);
Note that $compunit.distribution
will only work if resolve returned a CompUnit from a CompUnit::Repository::Installation
repository.
rakudo@1812 is the framework to improve this further, allowing individual repositories to be queried ( $*REPO.resolve
iterates the linked list of repos to give a result ) and unifying behavior for resolve/candidates/etc between CompUnit::Repository::Installation
and CompUnit::Repository::FileSystem
.
If I remember correctly, you shouldn't. It's zef the one that must take care of it. But if you positively have to, use the SHA1 signatures in the directory with
zef locate
will output (in my system)
From your question, it's not too clear if what you want to do is the opposite, that is, find out which SHA1 corresponds to which file; in that case, try and to this:
which will return