12.1. Defining a Module's InterfaceProblemYou want the standard Exporter module to define the external interface to your module. SolutionIn module file YourModule.pm , place the following code. Fill in the ellipses as explained in the Discussion section. package YourModule; use strict; use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION); use Exporter; $VERSION = 1.00; # Or higher @ISA = qw(Exporter); @EXPORT = qw(...); # Symbols to autoexport (:DEFAULT tag) @EXPORT_OK = qw(...); # Symbols to export on request %EXPORT_TAGS = ( # Define names for sets of symbols TAG1 => [...], TAG2 => [...], ... ); ######################## # your code goes here ######################## 1; # this should be your last line In other files where you want to use YourModule, choose one of these lines: use YourModule; # Import default symbols into my package. use YourModule qw(...); # Import listed symbols into my package. use YourModule (); # Do not import any symbols use YourModule qw(:TAG1); # Import whole tag set Discussion
The standard Exporter module handles the module's external interface. Although you could define your own
When someone says
See AlsoThe documentation for the standard Exporter module, also found in Chapter 7 of Programming Perl ; Recipe 12.7 ; Recipe 12.18 |
|