{
    "mode": "perldoc",
    "parameter": "Exporter::Tiny::Manual::Exporting",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Exporter%3A%3ATiny%3A%3AManual%3A%3AExporting/json",
    "generated": "2026-06-12T11:50:14Z",
    "synopsis": "Read Exporter::Tiny::Manual::QuickStart first!",
    "sections": {
        "NAME": {
            "content": "Exporter::Tiny::Manual::Exporting - creating an exporter using Exporter::Tiny\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "Read Exporter::Tiny::Manual::QuickStart first!\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Simple configuration works the same as Exporter; inherit from Exporter::Tiny, and use the\n@EXPORT, @EXPORTOK, and %EXPORTTAGS package variables to list subs to export.\n\nUnlike Exporter, Exporter::Tiny performs most of its internal duties (including resolution of\ntag names to sub names, resolution of sub names to coderefs, and installation of coderefs into\nthe target package) as method calls, which means that your module (which is a subclass of\nExporter::Tiny) can override them to provide interesting behaviour.\n",
            "subsections": [
                {
                    "name": "Advanced Tag Stuff",
                    "content": "You can define tags using other tags:\n\nuse Exporter::Shiny qw(\nblack white red green blue cyan magenta yellow\n);\n\nour %EXPORTTAGS = (\nrgb        => [qw( red green blue )],\ncym        => [qw( cyan magenta yellow )],\ncymk       => [qw( black :cym )],\nmonochrome => [qw( black white )],\nall        => [qw( :rgb :cymk :monochrome )],\n);\n\nCAVEAT: If you create a cycle in the tags, this could put Exporter::Tiny into an infinite loop\nexpanding the tags. Don't do that.\n"
                },
                {
                    "name": "More on Generators",
                    "content": "Exporter::Tiny has always allowed exported subs to be generated (like Sub::Exporter), but until\nversion 0.025 did not have an especially nice API for it.\n\nNow, it's easy. If you want to generate a sub \"foo\" to export, list it in @EXPORT or @EXPORTOK\nas usual, and then simply give your exporter module a class method called \"generatefoo\".\n\npush @EXPORTOK, 'foo';\n\nsub generatefoo {\nmy $class = shift;\nmy ($name, $args, $globals) = @;\n\nreturn sub {\n...;\n}\n}\n\nWe showed how to do that in Exporter::Tiny::Manual::QuickStart, but one thing we didn't show was\nthat $globals gets passed in there. This is the global options hash, as described in\nExporter::Tiny::Manual::Importing. It can often be useful. In particular it will tell you what\npackage the generated sub is destined to be installed into.\n\nTo generate non-code symbols, name your generators like this:\n\nsub generateScalarFoo { ... }  # generate a symbol $Foo\nsub generateArrayBar  { ... }  # generate a symbol @Bar\nsub generateHashBaz   { ... }  # generate a symbol %Baz\n\nYou can also generate tags:\n\nmy %constants;\nBEGIN {\n%constants = (FOO => 1, BAR => 2);\n}\nuse constant \\%constants;\n\n$EXPORTTAGS{constants} = sub {\nmy $class = shift;\nmy ($name, $args, $globals) = @;\n\nreturn keys(%constants);\n};\n"
                },
                {
                    "name": "Hooks",
                    "content": "Sometimes as well as exporting stuff, you want to do some setup or something.\n\nYou can define a couple of class methods in your package, and they'll get called at the\nappropriate time:\n\npackage MyUtils;\n\n...;\n\nsub exportervalidateopts {\nmy $class = shift;\nmy ($globals) = @;\n\n...;   # do stuff here\n\n$class->SUPER::exportervalidateopts(@);\n}\n\nsub exportervalidateunimportopts {\nmy $class = shift;\nmy ($globals) = @;\n\n...;   # do stuff here\n\n$class->SUPER::exportervalidateunimportopts(@);\n}\n\nThe $globals variable is that famous global options hash. In particular, \"$globals->{into}\" is\nuseful because it tells you what package has imported you.\n\nAs you might have guessed, these methods were originally intended to validate the global options\nhash, but can be used to perform any general duties before the real exporting work is done.\n"
                },
                {
                    "name": "Overriding Internals",
                    "content": "An important difference between Exporter and Exporter::Tiny is that the latter calls all its\ninternal functions as *class methods*. This means that your subclass can *override them* to\nalter their behaviour.\n\nThe following methods are available to be overridden. Despite being named with a leading\nunderscore, they are considered public methods. (The underscore is there to avoid accidentally\ncolliding with any of your own function names.)\n\n\"exportervalidateopts($globals)\"\nDocumented above.\n\n\"exportervalidateunimportopts($globals)\"\nDocumented above.\n\n\"exportermergeopts($tagopts, $globals, @exports)\"\nCalled to merge options which have been provided for a tag into the options provided for the\nexports that the tag expanded to.\n\n\"exporterexpandtag($name, $args, $globals)\"\nThis method is called to expand an import tag (e.g. \":constants\"). It is passed the tag name\n(minus the leading \":\"), an optional hashref of options (like \"{ -prefix => \"foo\" }\"), and\nthe global options hashref.\n\nIt is expected to return a list of ($name, $args) arrayref pairs. These names can be sub\nnames to export, or further tag names (which must have their \":\"). If returning tag names,\nbe careful to avoid creating a tag expansion loop!\n\nThe default implementation uses %EXPORTTAGS to expand tags, and provides fallbacks for the\n\":default\" and \":all\" tags.\n\n\"exporterexpandregexp($regexp, $args, $globals)\"\nLike \"exporterexpandregexp\", but given a regexp-like string instead of a tag name.\n\nThe default implementation greps through @EXPORTOK for imports, and the list of\nalready-imported functions for exports.\n\n\"exporterexpandsub($name, $args, $globals)\"\nThis method is called to translate a sub name to a hash of name => coderef pairs for\nexporting to the caller. In general, this would just be a hash with one key and one value,\nbut, for example, Type::Library overrides this method so that \"+Foo\" gets expanded to:\n\n(\nFoo         => sub { $type },\nisFoo      => sub { $type->check(@) },\ntoFoo      => sub { $type->assertcoerce(@) },\nassertFoo  => sub { $type->assertreturn(@) },\n)\n\nThe default implementation checks that the name is allowed to be exported (using the\n\"exporterpermittedregexp\" method), gets the coderef using the generator if there is one\n(or by calling \"can\" on your exporter otherwise) and calls \"exporterfail\" if it's unable\nto generate or retrieve a coderef.\n\nDespite the name, is also called for non-code symbols.\n\n\"exporterpermittedregexp($globals)\"\nThis method is called to retrieve a regexp for validating the names of exportable subs. If a\nsub doesn't match the regexp, then the default implementation of \"exporterexpandsub\" will\nrefuse to export it. (Of course, you may override the default \"exporterexpandsub\".)\n\nThe default implementation of this method assembles the regexp from @EXPORT and @EXPORTOK.\n\n\"exporterfail($name, $args, $globals)\"\nCalled by \"exporterexpandsub\" if it can't find a coderef to export.\n\nThe default implementation just throws an exception. But you could emit a warning instead,\nor just ignore the failed export.\n\nIf you don't throw an exception then you should be aware that this method is called in list\ncontext, and any list it returns will be treated as an \"exporterexpandsub\"-style hash of\nnames and coderefs for export.\n\n\"exporterinstallsub($name, $args, $globals, $coderef)\"\nThis method actually installs the exported sub into its new destination. Its return value is\nignored.\n\nThe default implementation handles sub renaming (i.e. the \"-as\", \"-prefix\" and \"-suffix\"\nfunctions. This method does a lot of stuff; if you need to override it, it's probably a good\nidea to just pre-process the arguments and then call the super method rather than trying to\nhandle all of it yourself.\n\nDespite the name, is also called for non-code symbols.\n\n\"exporteruninstallsub($name, $args, $globals)\"\nThe opposite of \"exporterinstallsub\".\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "Exporter::Shiny, Exporter::Tiny.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Toby Inkster <tobyink@cpan.org>.\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENCE": {
            "content": "This software is copyright (c) 2013-2014, 2017 by Toby Inkster.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n",
            "subsections": []
        },
        "DISCLAIMER OF WARRANTIES": {
            "content": "THIS PACKAGE IS PROVIDED \"AS IS\" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\nWITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.\n",
            "subsections": []
        }
    },
    "summary": "Exporter::Tiny::Manual::Exporting - creating an exporter using Exporter::Tiny",
    "flags": [],
    "examples": [],
    "see_also": []
}