Relative path inside a module

429 Views Asked by At

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

There are 1 best solutions below

3
On BEST ANSWER

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.