📘 Creating a module in Perl 6

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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s