Library Science
Let’s review a bit of the terminology we’ve been splattering about. We, and the rest of the community, tend to use it loosely because the concepts overlap or coexist, but sometimes precision matters.
- namespace
A namespace is a place to keep names so they won’t be confused with names in other namespaces. This leaves you with the simpler problem of not confusing the namespaces themselves. There are two ways to avoid confusing namespaces with one another: give them unique names, or give them unique locations. Perl lets you do both: named namespaces are called packages, and unnamed namespaces are called lexical scopes. Since lexical scopes can be no larger than a file, and since the standard modules are file-sized (at minimum), it follows that all module interfaces must make use of named namespaces (packages) if they’re to be used by anyone outside the file.
- package
A package is Perl’s standard mechanism for declaring a named namespace. It’s a simple mechanism for grouping together related functions and variables. Just as two directories can both contain a (different) file named Amelia, two different parts of a Perl program can each have its own
$Ameliavariable or&Ameliafunction. Even though these variables or functions seem to have the same name as one another, those names reside in distinct namespaces managed by thepackagedeclaration. Package names are used to identify both modules and classes, as described in Chapter 11 and Chapter 12.- library
The term library is ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access