Chapter 10. Using Modules

Modules allow you to compartmentalize, distribute, and reuse code. Someone creates a general solution to something, then packages it so you can reuse it in your programs. Sometimes people make these modules available to everyone. You can find some Perl 6 modules at https://modules.perl6.org or by looking for them on GitHub.

You don’t have to understand the code inside a module to benefit from its features. You can usually follow the examples in its documentation even if it uses syntax that you haven’t already seen.

Installing Modules

zef is one of the Perl 6 module managers. It can install, update, and uninstall modules. It comes with Rakudo Star but you can install it yourself:

% git clone https://github.com/ugexe/zef.git
% cd zef
% perl6 -Ilib bin/zef install .

Once you have zef you can install modules. The Task::Popular module installs those most used by other modules:

% zef install Task::Popular

You can install a module by name if the author has registered it in the module ecosystem:

% zef install HTTP::Tiny

You can also tell it to install the code directly from a Git repository:

% zef install https://github.com/sergot/http-useragent.git

% zef install git://github.com/sergot/http-useragent.git

Ensure that you are using the clone URL and not the project page URL.

You can install from a local directory if the module infrastructure is there and there’s a META6.json file. You have to make the argument to zef not look like a module name. This one looks for a module ...

Get Learning Perl 6 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.