The standard Exporter module handles the module's external interface. Although you could define your own
method for your package, almost no one does this.
When a module is loaded, a minimal required version number can be supplied. If the version isn't at least this high, the
will raise an exception.
use YourModule 1.86; # If $VERSION < 1.86, fail
This array contains a list of functions and variables that will be exported into the caller's own namespace so they can be accessed without being fully qualified. Typically, a
list is used.
@EXPORT = qw(&F1 &F2 @List);
@EXPORT = qw( F1 F2 @List); # same thing
When a simple
call is made, the function
can be called as
and the array can be accessed as
. The ampersand is optional in front of an exported function specification.
To load the module at compile time but request that no symbols be exported, use the special form
, with empty parentheses.
This array contains symbols that can be imported if they're specifically asked for. If the array were loaded this way:
@EXPORT_OK = qw(Op_Func %Table);
Then the user could load the module like so:
use YourModule qw(Op_Func %Table F1);
and import only the
hash, and the
function was listed in the
array. Notice that this does not automatically import
, even though they're in
. To get everything in
plus extras from
, use the special
tag, such as:
use YourModule qw(:DEFAULT %Table);
This hash is used by large modules like CGI or POSIX to create higher-level groupings of related import symbols. Its values are references to arrays of symbol names, all of which must be in either
. Here's a sample initialization:
%EXPORT_TAGS = (
Functions => [ qw(F1 F2 Op_Func) ],
Variables => [ qw(@List %Table) ],
An import symbol with a leading colon means to import a whole group of symbols. Here's an example:
use YourModule qw(:Functions %Table);
That pulls in all the symbols from
that is, it pulls in the
functions and then the
Although you don't list it in
, the implicit tag
automatically means everything in
You don't have to have all those variables defined in your module. You just need the ones that you expect people to be able to use.