Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing resources of a dynamically loaded module

Tags:

module

raku

I can't find a way to correctly get access to resources of an installed distribution. For example, when a module is loaded dynamically:

require ::($module);

One way to get hold of its %?RESOURCES is to ask module to have a sub which would return this hash:

sub resources { %?RESOURCES }

But that adds extra to the boilerplate code.

Another way is to deep scan $*REPO and fetch module's distribution meta.

Are there any better options to achieve this task?

like image 482
Vadim Belman Avatar asked Dec 11 '18 03:12

Vadim Belman


1 Answers

One way is to use $*REPO ( as you already mention ) along with the Distribution object that CompUnit::Repository provides as an interface to the META6 data and its mapping to a given data store / file system.

my $spec = CompUnit::DependencySpecification.new(:short-name<Zef>);
my $dist = $*REPO.resolve($spec).distribution;
say $dist.content("resources/$_").open.slurp for $dist.meta<resources>.list;

Note this only works for installed distributions at the moment, but would work for not-yet-installed distributions ( like -Ilib ) with https://github.com/rakudo/rakudo/pull/1812

like image 125
ugexe Avatar answered Oct 23 '22 03:10

ugexe