=head1 NAME Module Management in Perl 6 =head1 PREAMBLE use v6; =head1 LANGUAGE en =head1 ABSTRACT =head1 DESCRIPTION =head1 TUTORIAL =head2 module A module is a piece of code which is usually located in a separate file with the name which may be guessed from the module name. Modules start with the keyword C. There are two ways of using it. The first line declares the module, and the rest of the file is its content: module X; sub x() { say "X::x()"; } It is also possible to use a block to hold the body of the module: module X { sub x() { say "X::x()"; } } =head2 export A module can contain subs an variables like any other Perl code or a class. To make subs and variables visible to external (in respect to the module) files, the corresponding item should be marked with the trait C: module X; sub x() is export { say "X::x()"; } =head2 use To use a module, use a C. This keyword searches for the module, loads it and imports what can be imported. Thus, the subs or variables with the C trait will be accessible in the code after module is imported. First, create a module saved in the file Greet.pm: module Greet; sub hey($name) is export { say "Hey, $name!"; } Second, use it in the Perl 6 code: use Greet; hey("you"); # Hey, you! The Perl 6 compiler will search for the module in the directories it knows to be Perl 6 libraries. It the module is located in another place, use the C<-I> command line option, for example: C Another example of the module, this time with nested name and with the code of the module in a block: module Greet::Polite { sub hello($name) is export { say "Hello, $name!"; } } The module file should be saved as C. Its usage is as straightforward as before: use Greet; use Greet::Polite; hey("you"); # Of Greet hello("Mr. X"); # Of Greet::Polite The actions behind the `use` happen at compile time. =head2 import =head2 need =head2 require =head1 AUTHOR Andrew Shitov, C