{
    "mode": "info",
    "parameter": "Exporter::Tiny::Manual::Exporting",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/Exporter%3A%3ATiny%3A%3AManual%3A%3AExporting/json",
    "generated": "2026-07-05T09:37:46Z",
    "synopsis": "Read Exporter::Tiny::Manual::QuickStart first!",
    "sections": {
        "Exporter::Tiny::ManualUserpContributed PExporter::Tiny::Manual::Exporting(3pm)": {
            "content": "",
            "subsections": []
        },
        "NAME": {
            "content": "Exporter::Tiny::Manual::Exporting - creating an exporter using\nExporter::Tiny\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "Read Exporter::Tiny::Manual::QuickStart first!\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Simple configuration works the same as Exporter; inherit from\nExporter::Tiny, and use the @EXPORT, @EXPORTOK, and %EXPORTTAGS\npackage variables to list subs to export.\n\nUnlike Exporter, Exporter::Tiny performs most of its internal duties\n(including resolution of tag names to sub names, resolution of sub\nnames to coderefs, and installation of coderefs into the target\npackage) as method calls, which means that your module (which is a\nsubclass of Exporter::Tiny) can override them to provide interesting\nbehaviour.\n\nAdvanced Tag Stuff\nYou 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\nExporter::Tiny into an infinite loop expanding the tags. Don't do that.\n\nMore on Generators\nExporter::Tiny has always allowed exported subs to be generated (like\nSub::Exporter), but until version 0.025 did not have an especially nice\nAPI for it.\n\nNow, it's easy. If you want to generate a sub \"foo\" to export, list it\nin @EXPORT or @EXPORTOK as usual, and then simply give your exporter\nmodule 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\nthing we didn't show was that $globals gets passed in there.  This is\nthe global options hash, as described in\nExporter::Tiny::Manual::Importing. It can often be useful. In\nparticular it will tell you what package the generated sub is destined\nto 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\nHooks\nSometimes as well as exporting stuff, you want to do some setup or\nsomething.\n\nYou can define a couple of class methods in your package, and they'll\nget called at the appropriate 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\nparticular, \"$globals->{into}\" is useful because it tells you what\npackage has imported you.\n\nAs you might have guessed, these methods were originally intended to\nvalidate the global options hash, but can be used to perform any\ngeneral duties before the real exporting work is done.\n\nOverriding Internals\nAn important difference between Exporter and Exporter::Tiny is that the\nlatter calls all its internal functions as class methods. This means\nthat your subclass can override them to alter their behaviour.\n\nThe following methods are available to be overridden. Despite being\nnamed with a leading underscore, they are considered public methods.\n(The underscore is there to avoid accidentally colliding with any of\nyour 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\noptions provided for the exports that the tag expanded to.\n\n\"exporterexpandtag($name, $args, $globals)\"\nThis method is called to expand an import tag (e.g. \":constants\").\nIt is passed the tag name (minus the leading \":\"), an optional\nhashref of options (like \"{ -prefix => \"foo\" }\"), and the global\noptions hashref.\n\nIt is expected to return a list of ($name, $args) arrayref pairs.\nThese names can be sub names to export, or further tag names (which\nmust have their \":\"). If returning tag names, be careful to avoid\ncreating a tag expansion loop!\n\nThe default implementation uses %EXPORTTAGS to expand tags, and\nprovides fallbacks for the \":default\" and \":all\" tags.\n\n\"exporterexpandregexp($regexp, $args, $globals)\"\nLike \"exporterexpandregexp\", but given a regexp-like string\ninstead of a tag name.\n\nThe default implementation greps through @EXPORTOK for imports,\nand the list of already-imported functions for exports.\n\n\"exporterexpandsub($name, $args, $globals)\"\nThis method is called to translate a sub name to a hash of name =>\ncoderef pairs for exporting to the caller. In general, this would\njust be a hash with one key and one value, but, for example,\nType::Library overrides this method so that \"+Foo\" gets expanded\nto:\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\nexported (using the \"exporterpermittedregexp\" method), gets the\ncoderef using the generator if there is one (or by calling \"can\" on\nyour 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\nof exportable subs. If a sub doesn't match the regexp, then the\ndefault implementation of \"exporterexpandsub\" will refuse to\nexport it. (Of course, you may override the default\n\"exporterexpandsub\".)\n\nThe default implementation of this method assembles the regexp from\n@EXPORT and @EXPORTOK.\n\n\"exporterfail($name, $args, $globals)\"\nCalled by \"exporterexpandsub\" if it can't find a coderef to\nexport.\n\nThe default implementation just throws an exception. But you could\nemit a warning instead, or just ignore the failed export.\n\nIf you don't throw an exception then you should be aware that this\nmethod is called in list context, and any list it returns will be\ntreated as an \"exporterexpandsub\"-style hash of names and\ncoderefs for export.\n\n\"exporterinstallsub($name, $args, $globals, $coderef)\"\nThis method actually installs the exported sub into its new\ndestination.  Its return value is ignored.\n\nThe default implementation handles sub renaming (i.e. the \"-as\",\n\"-prefix\" and \"-suffix\" functions. This method does a lot of stuff;\nif you need to override it, it's probably a good idea to just pre-\nprocess the arguments and then call the super method rather than\ntrying to handle 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",
            "subsections": []
        },
        "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\nthe same terms as the Perl 5 programming language system itself.\n",
            "subsections": []
        },
        "DISCLAIMER OF WARRANTIES": {
            "content": "THIS PACKAGE IS PROVIDED \"AS IS\" AND WITHOUT ANY EXPRESS OR IMPLIED\nWARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\nMERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\nperl v5.30.0                      2020-0Exporter::Tiny::Manual::Exporting(3pm)",
            "subsections": []
        }
    },
    "summary": "Exporter::Tiny::Manual::Exporting - creating an exporter using Exporter::Tiny",
    "flags": [],
    "examples": [],
    "see_also": []
}