๐Ÿ“˜ 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

Your email address will not be published. Required fields are marked *

Retype the CAPTCHA code from the image
Change the CAPTCHA codeSpeak the CAPTCHA code