10

I have this module which needs a specific file to work. You can pass the path of the file you want to use or not. If you don't, then a default file is taken. That default file is located at the resources folder, so I typed the path as: "resources/data/type-graph.txt". The problem is that does not work because it takes my CWD as root directory.

Do you know how to make the path relative to the module dir?

Any suggestion is appreciated :).

1
  • I'd take a look at Zef and how it handles config files. I think you should be able to have your module install a default config somewhere that it can access but off the top of my head I'm not sure where. Jul 2, 2019 at 9:17

1 Answer 1

12

You should take a look at the Modules documentation page. There this example is given to access a file placed in the resources folder:

my $template-text = %?RESOURCES<templates/default-template.mustache>.slurp;

You also need to list the file in META6.json so the file will be accessible once the module is installed.

{
    ...,
    "resources": [ "templates/default-template.mustache"]
}

As guifa noted in a comment %?RESOURCES works with individual files, not directory structures. It makes no guarantees of how the files are actually stored. So %?RESOURCES<templates>.dir will not work.

3
  • 2
    It might be worthwhile to note that that %?RESOURCES requires full foreknowledge of the file names. You can't, for instance, do %?RESOURCES<templates>.dir and get usable results. Jul 3, 2019 at 4:22
  • 3
    @guifa note that anything using %?RESOURCES has the means to know the file names: say %?RESOURCES{$_} for $*DISTRIBUTION.meta<resources>
    – ugexe
    Jul 3, 2019 at 14:53
  • @ugexe eah, I should have been clearer, you need to pass it an exact filename key. I never thought about peaking into $*DISTRIBUTION — I'm going to update my localization module to use that, thanks for the idea! Jul 3, 2019 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.