📘 The need keyword to use a module in Perl 6

📘 The need keyword to use a module in Raku

N. B. Perl 6 has been renamed to Raku. Click to read more.


To just load a module and do no exports, use the need keyword.

Let us create a module named N, which contains the sub n(). This time, the sub is declared as our but with no is export.

unit module N; 

our sub n() {
    say "N::n()";
}

Then you need a module and may use its methods using the fully qualified names.

need N;
N::n();

The sequence of the two instructions: need M; import M; (now import should always come after the need) is equivalent to a single use M; statement.

Leave a Reply