When you use
a module, you can pass a list of arguments to it. In your example (which seems to have a typo, missing a closing quote), a list with one element (a hash reference) is passed.
More generally:
use Module LIST
Becomes this:
BEGIN {
require Module;
Module->import( LIST );
}
The BEGIN
block ensures that all of the stuff happens at compile time. The require
loads the module into memory, if it's not there already. And then the module's import()
method is called with whatever arguments were passed (as LIST
) in the original use
statement.
In order for your own modules to do something with such a LIST
of arguments, your module would need to define an import()
method. Many modules don't do that; rather, they inherit import()
from the Exporter
class. See perldoc -f use for more details.
If your module defines its own import()
method, you will either need to export symbols into the client code yourself or, more commonly, use the export_to_level()
method provided by Exporter
. The first argument to this method is a positive integer specifying the level in the call stack to which to export symbols. The most common value of 1 means to export symbols one level above the current package -- that is, to the client code that is using your module. Here is an outline of what your import()
method would need to do.
sub import {
my ($class, @args) = @_;
# Do whatever you need to do with the LIST of arguments
# supplied by the client code using your module.
# Let Exporter do its normal work of exporting symbols
# into the client code using your module.
$class->export_to_level(1, @_);
}