📘 Creating a module in Perl 6

📘 Creating a module in Raku

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


The keyword module declares a module. The name of the module is given after the keyword. There are two methods of scoping the module. Either it can be a bare directive in the beginning of a file, or the whole module can be scoped in the code block within the pair of braces.

In the first option, the rest of the file is the module definition (note the presence of the unit keyword).

unit module X; 

sub x() {
    say "X::x()";
}

In the second option, the code looks similar to the way you declare classes (more on classes in Chapter 4).

module X {
    sub x() {
        say "X::x()";
    }
}

Leave a Reply