6

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?

jjmerelo
  • 22,578
  • 8
  • 40
  • 86
Vadim Belman
  • 1,210
  • 6
  • 15
  • I would say this is related to [this other question](https://stackoverflow.com/questions/53544352/how-to-export-sub-main-opts) and [this other](https://stackoverflow.com/questions/53634257/obtaining-the-pod-of-a-module-without-explicitly-exporting-it). There seems to be a necessity to include in the symbol table some lexically scoped variables so that they can be accessed. There's [this request](https://github.com/rakudo/rakudo/issues/2532) in the Rakudo repo and a possible workaround (which adds boilerplate too, I'm afraid) – jjmerelo Dec 11 '18 at 05:36
  • 1
    Looks like a request for more generic way to access precompilation data is needed. BTW, accessing pod is of special interest as it would allow something similar to p5's Pod::Weaver but without the downside of having to rewrite source code! – Vadim Belman Dec 11 '18 at 15:04

1 Answers1

5

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

ugexe
  • 5,297
  • 1
  • 28
  • 49
  • 1
    Sadly, https://github.com/rakudo/rakudo/pull/1812 has bitrotted a bit. FWIW, that discussion has completely passed me by :-( – Elizabeth Mattijsen Dec 11 '18 at 17:18
  • @ugexe – thanx! Wish the CompUnit family be well documented. I tried reading the sources, found the `content` method but it's not really a self-explanatory one. ;) Anyway, looking forward for the not-yet-installed support. – Vadim Belman Dec 12 '18 at 00:05