Exporter::Lite(3)
π Exporter::Lite(3) β like, the lite babe of exporters
okay so bestie, you've stumbled into Exporter::Lite, part of the whole User Contributed Perl Documentation situation, and honestly? she's giving minimal icon energy. let's get into it β¨
πΈ NAME πΈ
Exporter::Lite β lightweight exporting of functions and variables. yes, that's the whole name, she's lowkey not doing too much π
β¨ SYNOPSIS β¨
so you're making a package, right? here's the setup:
package Foo;
use Exporter::Lite;
our @EXPORT = qw($This That); # default exports
our @EXPORT_OK = qw(@Left %Right); # optional exports
then in the code that's using the module:
use Foo;
# $This and &That are imported here
and the optional ones? you gotta explicitly ask for those, no mind-reading here:
use Foo qw/ @Left %Right /;
π¦ DESCRIPTION π¦
Exporter::Lite is the alternative to Exporter β like, an intentionally lightweight subset of the most commonly-used functionality. she supports import(), @EXPORT and @EXPORT_OK and honestly not a whole lot else. and that's on periodt π
Exporter::Lite simply exports its import() function into your namespace. you could call that a "mix-in" or a "role" β iykyk.
back when Exporter::Lite was written, if you wanted to use Exporter you had to write something like this whole thing:
use Exporter;
our @ISA = qw/ Exporter /;
Exporter::Lite saved you from writing that second line. BUT β and this is the plot twist π«Ά β since before 2010 you've been able to write:
use Exporter qw/ import /;
which imports the import function into your namespace from Exporter. so as a result, I would recommend that you use Exporter now, because it's a core module (shipped with Perl). like, she's already in the group chat, no extra download needed β¨
to make sure you get a version of Exporter that supports the above usage, specify a minimum version when you use it:
use Exporter 5.57 qw/ import /;
π Back to "Exporter::Lite" π
setting up a module to export its variables and functions is simple, bestie:
package My::Module;
use Exporter::Lite;
our @EXPORT = qw($Foo bar);
functions and variables listed in the @EXPORT package variable are automatically exported if you use the module and don't explicitly list any imports. so now, when you use My::Module, $Foo and bar() will show up. no cap π§
optional exports are listed in the @EXPORT_OK package variable:
package My::Module;
use Exporter::Lite;
our @EXPORT_OK = qw($Foo bar);
when My::Module is used, $Foo and bar() will not show up, unless you explicitly ask for them:
use My::Module qw($Foo bar);
β οΈ note that when you specify one or more functions or variables to import, then you must also explicitly list any of the default symbols you want to use. the defaults don't come along for the ride automatically. π
so if you have an exporting module:
package Games;
our @EXPORT = qw/ pacman defender /;
our @EXPORT_OK = qw/ galaga centipede /;
then if you want to use both pacman and galaga, then you'd write:
use Games qw/ pacman galaga /;
yes, you have to name pacman even though it's a default. that's the whole entire bit. π
π Methods π
Export::Lite has one public method, import(), which is called automatically when your modules is use()'d. (yes, that's exactly how the original says it, we're keeping it π)
in normal usage you don't have to worry about this at all. she handles herself, main character energy π
β import β
Some::Module->import;
Some::Module->import(@symbols);
works just like Exporter::import() excepting it only honors @Some::Module::EXPORT and @Some::Module::EXPORT_OK.
the given @symbols are exported to the current package provided they are in @Some::Module::EXPORT or @Some::Module::EXPORT_OK. otherwise an exception is thrown (ie. the program dies). like, flatlines. π
if @symbols is not given, everything in @Some::Module::EXPORT is exported.
π₯ DIAGNOSTICS π₯
so when things go sideways, here's what you might see:
'"%s" is not exported by the %s module'β you attempted to import a symbol which is not in@EXPORTor@EXPORT_OK. rude of you tbh, but okay π«Ά'Can\'t export symbol: %s'β you attempted to import a symbol of an unknown type (ie. the leading$@%salad wasn't recognized). yes, "salad", that's the technical term. π₯
π SEE ALSO π
okay this list is long, buckle up bestie, we're meeting the whole extended family:
Exporteris the grandaddy of all Exporter modules, and bundled with Perl itself, unlike the rest of the modules listed here. πAttribute::Exporterdefines attributes which you use to mark which subs and variables you want to export, and how.Exporter::Simplealso uses attributes to control the export of functions and variables from your module.Const::Exportermakes it easy to create a module that exports constants.Constant::Exporteris another module that makes it easy to create modules that define and export constants. (yes, two of them. yes, they're different. we don't make the rules π )Sub::Exporteris a "sophisticated exporter for custom-built routines"; it lets you provide generators that can be used to customise what gets imported when someone uses your module.Exporter::Tinyprovides the same features asSub::Exporter, but relying only on core dependencies.Exporter::Shinyis a shortcut forExporter::Tinythat provides a more concise notation for providing optional exports.Exporter::Declareprovides syntactic sugar to make the export status of your functions part of their declaration. Kind of. πAppConfig::Exporterlets you export part of an AppConfig-based configuration.Exporter::Lexicallets you export lexical subs from your module.Constant::Export::Lazylets you write a module that exports function-style constants, which are instantiated lazily.Exporter::Autowill export everything from your module that it thinks is a public function (name doesn't start with an underscore).Class::Exporterlets you export class methods as regular subroutines.Xporteris like Exporter, but with persistent defaults and auto-ISA.
π REPOSITORY π
<https://github.com/neilb/Exporter-Lite> β go say hi, star it, whatever, she's literally right there π«Ά
πΈ AUTHORS πΈ
Michael G Schwern <schwern@pobox.com> β icon, legend, the moment β¨
π LICENSE π
this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
see http://www.perl.com/perl/misc/Artistic.html
and that's the whole page bestie! brought to you by perl v5.42.0, dated 2022-03-05 β this manual page said slay and clocked out π
πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Exporter-Lite 0.09-bp160.1.11 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms