{
    "mode": "man",
    "parameter": "Exporter",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/man/Exporter/json",
    "generated": "2026-10-22T13:06:02Z",
    "synopsis": "In module YourModule.pm:\npackage YourModule;\nuse Exporter 'import';\nour @EXPORTOK = qw(munge frobnicate);  # symbols to export on request\nor\npackage YourModule;\nrequire Exporter;\nour @ISA = qw(Exporter);  # inherit all of Exporter's methods\nour @EXPORTOK = qw(munge frobnicate);  # symbols to export on request\nor\npackage YourModule;\nuse parent 'Exporter';  # inherit all of Exporter's methods\nour @EXPORTOK = qw(munge frobnicate);  # symbols to export on request\nIn other files which wish to use \"YourModule\":\nuse YourModule qw(frobnicate);      # import listed symbols\nfrobnicate ($left, $right)          # calls YourModule::frobnicate\nTake a look at \"Good Practices\" for some variants you will like to use in modern Perl code.",
    "sections": {
        "NAME": {
            "content": "Exporter - Implements default import method for modules\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "In module YourModule.pm:\n\npackage YourModule;\nuse Exporter 'import';\nour @EXPORTOK = qw(munge frobnicate);  # symbols to export on request\n\nor\n\npackage YourModule;\nrequire Exporter;\nour @ISA = qw(Exporter);  # inherit all of Exporter's methods\nour @EXPORTOK = qw(munge frobnicate);  # symbols to export on request\n\nor\n\npackage YourModule;\nuse parent 'Exporter';  # inherit all of Exporter's methods\nour @EXPORTOK = qw(munge frobnicate);  # symbols to export on request\n\nIn other files which wish to use \"YourModule\":\n\nuse YourModule qw(frobnicate);      # import listed symbols\nfrobnicate ($left, $right)          # calls YourModule::frobnicate\n\nTake a look at \"Good Practices\" for some variants you will like to use in modern Perl code.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The Exporter module implements an \"import\" method which allows a module to export functions\nand variables to its users' namespaces.  Many modules use Exporter rather than implementing\ntheir own \"import\" method because Exporter provides a highly flexible interface, with an\nimplementation optimised for the common case.\n\nPerl automatically calls the \"import\" method when processing a \"use\" statement for a module.\nModules and \"use\" are documented in perlfunc and perlmod.  Understanding the concept of\nmodules and how the \"use\" statement operates is important to understanding the Exporter.\n",
            "subsections": [
                {
                    "name": "How to Export",
                    "content": "The arrays @EXPORT and @EXPORTOK in a module hold lists of symbols that are going to be\nexported into the users name space by default, or which they can request to be exported,\nrespectively.  The symbols can represent functions, scalars, arrays, hashes, or typeglobs.\nThe symbols must be given by full name with the exception that the ampersand in front of a\nfunction is optional, e.g.\n\nour @EXPORT    = qw(afunc $scalar @array);   # afunc is a function\nour @EXPORTOK = qw(&bfunc %hash *typeglob); # explicit prefix on &bfunc\n\nIf you are only exporting function names it is recommended to omit the ampersand, as the\nimplementation is faster this way.\n"
                },
                {
                    "name": "Selecting What to Export",
                    "content": "Do not export method names!\n\nDo not export anything else by default without a good reason!\n\nExports pollute the namespace of the module user.  If you must export try to use @EXPORTOK\nin preference to @EXPORT and avoid short or common symbol names to reduce the risk of name\nclashes.\n\nGenerally anything not exported is still accessible from outside the module using the\n\"YourModule::itemname\" (or \"$blessedref->method\") syntax.  By convention you can use a\nleading underscore on names to informally indicate that they are 'internal' and not for\npublic use.\n\n(It is actually possible to get private functions by saying:\n\nmy $subref = sub { ... };\n$subref->(@args);            # Call it as a function\n$obj->$subref(@args);        # Use it as a method\n\nHowever if you use them for methods it is up to you to figure out how to make inheritance\nwork.)\n\nAs a general rule, if the module is trying to be object oriented then export nothing.  If\nit's just a collection of functions then @EXPORTOK anything but use @EXPORT with caution.\nFor function and method names use barewords in preference to names prefixed with ampersands\nfor the export lists.\n\nOther module design guidelines can be found in perlmod.\n"
                },
                {
                    "name": "How to Import",
                    "content": "In other files which wish to use your module there are three basic ways for them to load your\nmodule and import its symbols:\n\n\"use YourModule;\"\nThis  imports  all  the symbols from YourModule's @EXPORT into the namespace of the \"use\"\nstatement.\n\n\"use YourModule ();\"\nThis causes perl to load your module but does not import any symbols.\n\n\"use YourModule qw(...);\"\nThis imports only the symbols listed by the caller  into  their  namespace.   All  listed\nsymbols must be in your @EXPORT or @EXPORTOK, else an error occurs.  The advanced export\nfeatures of Exporter are accessed like this, but with list entries that are syntactically\ndistinct from symbol names.\n\nUnless  you  want  to use its advanced features, this is probably all you need to know to use\nExporter.\n"
                }
            ]
        },
        "Advanced Features": {
            "content": "",
            "subsections": [
                {
                    "name": "Specialised Import Lists",
                    "content": "If any of the entries in an import list begins with !, : or / then the list is treated  as  a\nseries  of  specifications  which  either  add to or delete from the list of names to import.\nThey are processed left to right. Specifications are in the form:\n\n[!]name         This name only\n[!]:DEFAULT     All names in @EXPORT\n[!]:tag         All names in $EXPORTTAGS{tag} anonymous array\n[!]/pattern/    All names in @EXPORT and @EXPORTOK which match\n\nA leading ! indicates that matching names should be deleted from the list of names to import.\nIf the first specification is a deletion it is treated as though preceded  by  :DEFAULT.   If\nyou  just  want  to  import extra names in addition to the default set you will still need to\ninclude :DEFAULT explicitly.\n\ne.g., Module.pm defines:\n\nour @EXPORT      = qw(A1 A2 A3 A4 A5);\nour @EXPORTOK   = qw(B1 B2 B3 B4 B5);\nour %EXPORTTAGS = (T1 => [qw(A1 A2 B1 B2)], T2 => [qw(A1 A2 B3 B4)]);\n\nNote that you cannot use tags in @EXPORT or @EXPORTOK.\n\nNames in EXPORTTAGS must also appear in @EXPORT or @EXPORTOK.\n\nAn application using Module can say something like:\n\nuse Module qw(:DEFAULT :T2 !B3 A3);\n\nOther examples include:\n\nuse Socket qw(!/^[AP]F/ !SOMAXCONN !SOLSOCKET);\nuse POSIX  qw(:errnoh :termiosh !TCSADRAIN !/^EXIT/);\n\nRemember that most patterns (using //) will need to be  anchored  with  a  leading  ^,  e.g.,\n\"/^EXIT/\" rather than \"/EXIT/\".\n\nYou  can  say  \"BEGIN  {  $Exporter::Verbose=1  }\"  to  see  how the specifications are being\nprocessed and what is actually being imported into modules.\n"
                },
                {
                    "name": "Exporting Without Using Exporter's import Method",
                    "content": "Exporter has a special method, 'exporttolevel' which is used in situations where you  can't\ndirectly call Exporter's import method.  The exporttolevel method looks like:\n\nMyPackage->exporttolevel(\n$wheretoexport, $package, @whattoexport\n);\n\nwhere  $wheretoexport  is  an  integer  telling how far up the calling stack to export your\nsymbols, and @whattoexport is an array telling what symbols *to* export  (usually  this  is\n@).  The $package argument is currently unused.\n\nFor example, suppose that you have a module, A, which already has an import function:\n\npackage A;\n\nour @ISA = qw(Exporter);\nour @EXPORTOK = qw($b);\n\nsub import\n{\n$A::b = 1;     # not a very useful import method\n}\n\nand you want to Export symbol $A::b back to the module that called package A.  Since Exporter\nrelies  on  the  import method to work, via inheritance, as it stands Exporter::import() will\nnever get called.  Instead, say the following:\n\npackage A;\nour @ISA = qw(Exporter);\nour @EXPORTOK = qw($b);\n\nsub import\n{\n$A::b = 1;\nA->exporttolevel(1, @);\n}\n\nThis will export the symbols one level 'above' the current package - ie: to  the  program  or\nmodule that used package A.\n\nNote:  Be  careful  not to modify @ at all before you call exporttolevel - or people using\nyour package will get very unexplained results!\n"
                },
                {
                    "name": "Exporting Without Inheriting from Exporter",
                    "content": "By including Exporter in your @ISA you inherit an Exporter's import()  method  but  you  also\ninherit  several  other  helper  methods  which  you  probably  don't want and complicate the\ninheritance tree.  To avoid this you can do:\n\npackage YourModule;\nuse Exporter qw(import);\n\nwhich will export Exporter's own import() method into YourModule.  Everything  will  work  as\nbefore but you won't need to include Exporter in @YourModule::ISA.\n\nNote: This feature was introduced in version 5.57 of Exporter, released with perl 5.8.3.\n"
                },
                {
                    "name": "Module Version Checking",
                    "content": "The  Exporter  module will convert an attempt to import a number from a module into a call to\n\"$modulename->VERSION($value)\".  This can be used to validate that the version of the module\nbeing used is greater than or equal to the required version.\n\nFor historical reasons, Exporter supplies a \"requireversion\" method that simply delegates to\n\"VERSION\".   Originally,   before   \"UNIVERSAL::VERSION\"   existed,   Exporter   would   call\n\"requireversion\".\n\nSince the \"UNIVERSAL::VERSION\" method treats the $VERSION number as a simple numeric value it\nwill  regard version 1.10 as lower than 1.9.  For this reason it is strongly recommended that\nyou use numbers with at least two decimal places, e.g., 1.09.\n"
                },
                {
                    "name": "Managing Unknown Symbols",
                    "content": "In some situations you may want to prevent certain symbols from  being  exported.   Typically\nthis  applies  to  extensions  which  have  functions or constants that may not exist on some\nsystems.\n\nThe names of any symbols that cannot be exported should be listed in the @EXPORTFAIL array.\n\nIf a module attempts to import any of these symbols the Exporter  will  give  the  module  an\nopportunity  to  handle  the situation before generating an error.  The Exporter will call an\nexportfail method with a list of the failed symbols:\n\n@failedsymbols = $modulename->exportfail(@failedsymbols);\n\nIf the \"exportfail\" method returns an empty list then no  error  is  recorded  and  all  the\nrequested symbols are exported.  If the returned list is not empty then an error is generated\nfor  each  symbol and the export fails.  The Exporter provides a default \"exportfail\" method\nwhich simply returns the list unchanged.\n\nUses for the \"exportfail\" method include giving better error messages for some  symbols  and\nperforming  lazy architectural checks (put more symbols into @EXPORTFAIL by default and then\ntake them out if someone actually tries to use them and an expensive check  shows  that  they\nare usable on that platform).\n"
                },
                {
                    "name": "Tag Handling Utility Functions",
                    "content": "Since  the  symbols  listed  within  %EXPORTTAGS  must  also  appear  in  either  @EXPORT or\n@EXPORTOK, two utility functions are provided which allow you to easily add tagged  sets  of\nsymbols to @EXPORT or @EXPORTOK:\n\nour %EXPORTTAGS = (foo => [qw(aa bb cc)], bar => [qw(aa cc dd)]);\n\nExporter::exporttags('foo');     # add aa, bb and cc to @EXPORT\nExporter::exportoktags('bar');  # add aa, cc and dd to @EXPORTOK\n\nAny  names which are not tags are added to @EXPORT or @EXPORTOK unchanged but will trigger a\nwarning (with \"-w\") to  avoid  misspelt  tags  names  being  silently  added  to  @EXPORT  or\n@EXPORTOK.  Future versions may make this a fatal error.\n"
                },
                {
                    "name": "Generating Combined Tags",
                    "content": "If several symbol categories exist in %EXPORTTAGS, it's usually useful to create the utility\n\":all\" to simplify \"use\" statements.\n\nThe simplest way to do this is:\n\nour  %EXPORTTAGS = (foo => [qw(aa bb cc)], bar => [qw(aa cc dd)]);\n\n# add all the other \":class\" tags to the \":all\" class,\n# deleting duplicates\n{\nmy %seen;\n\npush @{$EXPORTTAGS{all}},\ngrep {!$seen{$}++} @{$EXPORTTAGS{$}} foreach keys %EXPORTTAGS;\n}\n\nCGI.pm  creates  an  \":all\"  tag  which contains some (but not really all) of its categories.\nThat could be done with one small change:\n\n# add some of the other \":class\" tags to the \":all\" class,\n# deleting duplicates\n{\nmy %seen;\n\npush @{$EXPORTTAGS{all}},\ngrep {!$seen{$}++} @{$EXPORTTAGS{$}}\nforeach qw/html2 html3 netscape form cgi internal/;\n}\n\nNote that the tag names in %EXPORTTAGS don't have the leading ':'.\n"
                },
                {
                    "name": "\"AUTOLOAD\"ed Constants",
                    "content": "Many modules make use of \"AUTOLOAD\"ing for constant subroutines to avoid  having  to  compile\nand  waste  memory  on  rarely used values (see perlsub for details on constant subroutines).\nCalls to such constant subroutines are not optimized away at compile time because they  can't\nbe checked at compile time for constancy.\n\nEven  if  a  prototype  is  available  at compile time, the body of the subroutine is not (it\nhasn't been \"AUTOLOAD\"ed yet).  perl needs to examine both the \"()\" prototype and the body of\na subroutine at compile time to detect that it can safely replace calls  to  that  subroutine\nwith the constant value.\n\nA workaround for this is to call the constants once in a \"BEGIN\" block:\n\npackage My ;\n\nuse Socket ;\n\nfoo( SOLINGER );  ## SOLINGER NOT optimized away; called at runtime\nBEGIN { SOLINGER }\nfoo( SOLINGER );  ## SOLINGER optimized away at compile time.\n\nThis  forces  the  \"AUTOLOAD\"  for  \"SOLINGER\" to take place before SOLINGER is encountered\nlater in \"My\" package.\n\nIf you are writing a package  that  \"AUTOLOAD\"s,  consider  forcing  an  \"AUTOLOAD\"  for  any\nconstants  explicitly  imported by other packages or which are usually used when your package\nis \"use\"d.\n"
                }
            ]
        },
        "Good Practices": {
            "content": "",
            "subsections": [
                {
                    "name": "Declaring @EXPORT_OK and Friends",
                    "content": "When using \"Exporter\" with the standard \"strict\" and \"warnings\" pragmas, the \"our\" keyword is\nneeded to declare the package variables @EXPORTOK, @EXPORT, @ISA, etc.\n\nour @ISA = qw(Exporter);\nour @EXPORTOK = qw(munge frobnicate);\n\nIf backward compatibility for Perls under 5.6 is important, one must  write  instead  a  \"use\nvars\" statement.\n\nuse vars qw(@ISA @EXPORTOK);\n@ISA = qw(Exporter);\n@EXPORTOK = qw(munge frobnicate);\n"
                },
                {
                    "name": "Playing Safe",
                    "content": "There  are  some  caveats  with the use of runtime statements like \"require Exporter\" and the\nassignment to package variables, which can be very subtle for the unaware  programmer.   This\nmay  happen  for instance with mutually recursive modules, which are affected by the time the\nrelevant constructions are executed.\n\nThe ideal way to never have to think about that is to  use  \"BEGIN\"  blocks  and  the  simple\nimport method.  So the first part of the \"SYNOPSIS\" code could be rewritten as:\n\npackage YourModule;\n\nuse strict;\nuse warnings;\n\nuse Exporter 'import';\nBEGIN {\nour @EXPORTOK = qw(munge frobnicate);  # symbols to export on request\n}\n\nOr if you need to inherit from Exporter:\n\npackage YourModule;\n\nuse strict;\nuse warnings;\n\nBEGIN {\nrequire Exporter;\nour @ISA = qw(Exporter);  # inherit all of Exporter's methods\nour @EXPORTOK = qw(munge frobnicate);  # symbols to export on request\n}\n\nThe  \"BEGIN\"  will  assure  that  the  loading of Exporter.pm and the assignments to @ISA and\n@EXPORTOK happen immediately like \"use\", leaving no room for something to get awry  or  just\nplain wrong.\n\nWith  respect  to  loading  \"Exporter\" and inheriting, there are alternatives with the use of\nmodules like \"base\" and \"parent\".\n\nuse base qw(Exporter);\n# or\nuse parent qw(Exporter);\n\nAny of these statements are nice replacements for \"BEGIN  {  require  Exporter;  our  @ISA  =\nqw(Exporter); }\" with the same compile-time effect.  The basic difference is that \"base\" code\ninteracts  with declared \"fields\" while \"parent\" is a streamlined version of the older \"base\"\ncode to just establish the IS-A relationship.\n\nFor more details, see the documentation and code of base and parent.\n\nAnother thorough remedy to that runtime vs. compile-time trap is to use Exporter::Easy, which\nis a wrapper of Exporter that allows all boilerplate  code  at  a  single  gulp  in  the  use\nstatement.\n\nuse Exporter::Easy (\nOK => [ qw(munge frobnicate) ],\n);\n# @ISA setup is automatic\n# all assignments happen at compile time\n"
                },
                {
                    "name": "What Not to Export",
                    "content": "You have been warned already in \"Selecting What to Export\" to not export:\n\n•   method names (because you don't need to and that's likely to not do what you want),\n\n•   anything by default (because you don't want to surprise your users...  badly)\n\n•   anything you don't need to (because less is more)\n\nThere's  one  more  item  to  add  to this list.  Do not export variable names.  Just because\n\"Exporter\" lets you do that, it does not mean you should.\n\n@EXPORTOK = qw($svar @avar %hvar); # DON'T!\n\nExporting variables is not a good idea.  They can change under the hood,  provoking  horrible\neffects  at-a-distance  that  are too hard to track and to fix.  Trust me: they are not worth\nit.\n\nTo provide the capability to set/get class-wide settings,  it  is  best  instead  to  provide\naccessors as subroutines or class methods instead.\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "\"Exporter\" is definitely not the only module with symbol exporter capabilities.  At CPAN, you\nmay  find a bunch of them.  Some are lighter.  Some provide improved APIs and features.  Pick\nthe one that fits your needs.  The following is a sample list of such modules.\n\nExporter::Easy\nExporter::Lite\nExporter::Renaming\nExporter::Tidy\nSub::Exporter / Sub::Installer\nPerl6::Export / Perl6::Export::Attrs\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "This library is free software.  You can redistribute it and/or modify it under the same terms\nas Perl itself.\n\nperl v5.38.2                                 2026-08-18                              Exporter(3perl)",
            "subsections": []
        }
    },
    "summary": "Exporter - Implements default import method for modules",
    "flags": [],
    "examples": [],
    "see_also": []
}