Exporter
Implements a default import method for other modules to inherit if they don’t want to define their own. If you are writing a module, you can do the following:
package Module;
use Exporter ();
@ISA = qw(Exporter);
@EXPORT = qw(...);
@EXPORT_OK = qw(...);
%EXPORT_TAGS = (tag => [...]);
where @EXPORT
is a list of symbols to export by default,
@EXPORT_OK
is a list of symbols to export on request, and %EXPORT_TAGS
is a hash that
defines names for sets of symbols. Names in %EXPORT_TAGS
must also appear
in @EXPORT
or @EXPORT_OK
.
Then Perl programs that want to use your module just say:
use Module; # Import default symbols use Module qw(...); # Import listed symbols use Module (); # Do not import any symbols
The Exporter can handle
specialized import lists. An import list is the list of arguments passed to the
import
method. If the first entry begins with
!
, :
, or /
, the list is treated as a
series of specifications that add to or delete from the list. A leading
!
means delete, rather than add.
Symbol | Meaning |
---|---|
[!]
name
|
This |
[!]:DEFAULT
| All names in @EXPORT
|
[!]:
tag
|
All names in |
[!]/
pattern
/
|
All names in |
Exporter methods are:
Get Perl in a Nutshell 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.