Here we need to distinguish between four things:
A Distribution
A
packageA
moduleA
class/grammar
Distribution§
A Distribution is a set of related source files that are distributed together. This usually includes some modules, some tests, and maybe some other resources.
For a full explanation, see Distributions: An introduction and the following documentation.
package§
Packages are nested namespaces of named program elements. Modules, classes and grammars are all types of package.
For a full explanation see Packages.
module§
Modules are usually one or more source files that expose Raku constructs, such as classes, roles, grammars, subroutines and variables. Modules are usually used for distributing Raku code as libraries which can be used in another Raku program.
For a full explanation see the pages linked from Using Modules: An Introduction.
class§
Classes are a collection of methods and attributes grouped together for convenience. Being a package, they're also a nested namespace.
For further explanation, see:
The
classsection of the Type system fundamentalsThe Classes and objects tutorial
grammar§
Grammars are a specific type of class intended for parsing text. Grammars are composed of rules, tokens and regexes which are actually methods, since grammars are classes.
For a full explanation see Grammars.
Creating and using modules§
A module is usually a source file or set of source files that expose Raku constructs [1] .
Modules are typically packages (classes, roles, grammars), subroutines, and sometimes variables. In Raku module can also refer to a type of package declared with the module keyword (see Module Packages and the examples below) but here we mostly mean "module" as a set of source files in a namespace.