Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I load a module relative to script in Raku with Raku equivalent of FindBin

Tags:

module

raku

Suppose I have 2 files in a directory

p.pl  
Mod.pm

In perl5 I can load a module Mod.pm from p.pl via:

use FindBin qw($Bin);
use lib "$Bin";
...
use Mod;

I wonder what the Raku equivalent would be (if files are p.raku and Mod.rakumod)?

What I want to accomplish is to load a module relative to a script.

  • I want to execute without setting an env variable prior to starting a script.
  • I dont want to install the modules with zef.
  • I dont want to be forced to set the cwd to the scripts directory, meaning if p.raku and Mod.rakumod are in directory d1 that is in turn in directory d0 I want to be able to run cd d0; rakudo d1/p.raku as well as cd d1; rakudo p.raku
like image 696
Konrad Eisele Avatar asked Aug 09 '20 09:08

Konrad Eisele


1 Answers

As ValleLukas explained:

use lib $*PROGRAM.dirname
use Mod;

can be used.

like image 173
Konrad Eisele Avatar answered Oct 15 '22 21:10

Konrad Eisele