Exporter::Easy(3pm)
π Exporter::Easy(3pm) π
okay bestie, welcome to the User Contributed Perl Documentation section of the manual, and specifically to Exporter::Easy(3pm) β the module that takes the drudgery out of exporting symbols. yes that's its actual job description. and yes it's amazing. π
β¨ NAME β¨
Exporter::Easy β takes the drudgery out of Exporting symbols. π
πΈ SYNOPSIS πΈ
so in your module, YourModule.pm, you're gonna write this:
package YourModule;
use Exporter::Easy (
OK => [ '$munge', 'frobnicate' ] # symbols to export on request
);
and then in other files that wanna use YourModule:
use ModuleName qw(frobnicate); # import listed symbols
frobnicate ($left, $right) # calls YourModule::frobnicate
that's it. that's the whole vibe. π¦
π DESCRIPTION π
Exporter::Easy makes using Exporter easy. no cap. in its simplest case, it lets you drop all that boilerplate code that comes with using Exporter, so this whole situation:
require Exporter;
use base qw( Exporter );
use vars qw( @EXPORT );
@EXPORT = ( 'init' );
literally just becomes this:
use Exporter::Easy ( EXPORT => [ 'init' ] );
and then when things get more complicated β like when you're using tags to build lists, and then building more tags out of those tags β it stays easy, like this:
use Exporter::Easy (
EXPORT => [qw( init :base )],
TAGS => [
base => [qw( open close )],
read => [qw( read sysread readline )],
write => [qw( print write writeline )],
misc => [qw( select flush )],
all => [qw( :base :read :write :misc)],
no_misc => [qw( :all !:misc )],
],
OK => [qw( some other stuff )],
);
this will set @EXPORT, @EXPORT_OK, @EXPORT_FAIL and %EXPORT_TAGS in the current package, add Exporter to that package's @ISA, and do a use vars on all the variables mentioned. the rest is handled as normal by Exporter. slay. β¨
π HOW TO USE IT π
just put
use Exporter::Easy ( KEY => value, ...);
in your package. arguments are passed as key-value pairs, and these are the keys you've got available:
TAGSβ the value should be a reference to a list shaped like(TAG_NAME, TAG_VALUE, TAG_NAME, TAG_VALUE, ...), whereTAG_NAMEis a string andTAG_VALUEis a reference to an array of symbols and tags. for example:
TAGS => [
file => [ 'open', 'close', 'read', 'write'],
string => [ 'length', 'substr', 'chomp' ],
hash => [ 'keys', 'values', 'each' ],
all => [ ':file', ':string', ':hash' ],
some => [':all', '!open', ':hash'],
]
this is used to fill the %EXPORT_TAGS in your package. and here's the iconic part β you can build tags out of other tags. in the example above, the all tag will contain all the symbols from file, string and hash. you can also subtract symbols and tags β in that same example, some contains the symbols from all but with open removed, and all the symbols from hash removed.
the rule is: any symbol starting with a ':' is taken to be a tag which has been defined previously (and if it's not defined, you'll get an error, sorry bestie π). if a symbol is preceded by a '!' it will be subtracted from the list, otherwise it is added.
if you try to redefine a tag you will also get an error.
all the symbols which occur while building the tags are automatically added to your package's @EXPORT_OK array. π«Ά
OKβ the value should be a reference to a list of symbols and tags (which will be expanded). these symbols will be added to the@EXPORT_OKarray in your package. usingOKandOK_ONLYtogether will give an error.OK_ONLYβ the value should be a reference to a list of symbols and tags (which will be expanded). the@EXPORT_OKarray in your package will contain only these symbols. this totally overrides the automatic population of this array. if you just wanna add some symbols to the list thatExporter::Easyhas automatically built, then you should useOKinstead. usingOK_ONLYandOKtogether will give an error.EXPORTβ the value should be a reference to a list of symbol names and tags. any tags will be expanded and the resulting list of symbol names will be placed in the@EXPORTarray in your package. heads up: the tag created by theALLkey is not available at this stage.FAILβ the value should be a reference to a list of symbol names and tags. the tags will be expanded and the resulting list of symbol names will be placed in the@EXPORT_FAILarray in your package. they will also be added to the@EXPORT_OKlist.ALLβ the value should be the name of a tag that doesn't yet exist. this tag will contain a list of all symbols which can be exported.ISAβ if you set this to0thenExporterwill not be added to your@ISAlist.VARSβ if this is set to1, or not provided at all, then all$,@and%variables mentioned previously will be available to use in your package as if you had done ause varson them. if it's set to a reference to a list of symbols and tags, then only those symbols will be available. if it's set to0then you'll have to do your ownuse varsin your package.
π§ PROCESSING ORDER π§
we need to take the information provided and build @EXPORT, @EXPORT_OK, @EXPORT_FAIL and %EXPORT_TAGS in the calling package. we may also need to build a tag with all of the symbols, and to make all the variables useable under strict.
the arguments are processed in the following order: TAGS, EXPORT, OK, OK_ONLY and FAIL, ALL, VARS and finally ISA. which means you cannot use the tag created by ALL anywhere except in VARS (although vars defaults to using all symbols anyway). so like, keep that in mind. π
π SEE ALSO π
Exporteris the grandaddy of all Exporter modules, and it's bundled with Perl itself, unlike the rest of the modules listed here. go look at the documentation for this module to see more explanation of theOK,EXPORTand other variables.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.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 anAppConfig-based configuration.Exporter::Lexicallets you export lexical subs from your module.Constant::Exporter::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 likeExporter, but with persistent defaults and auto-ISA.
β REPOSITORY β
the repo is right here bestie: https://github.com/neilb/Exporter-Easy π«Ά
π AUTHOR π
written by Fergal Daly <fergal@esatclear.ie>. iconic of him honestly.
π LICENSE π
under the same license as Perl itself.
okay that's the whole page, you're literally a Perl exporter expert now, main character energy fr fr π β¨
this was perl v5.36.0, dated 2022-10-22 β catch you in the next Exporter::Easy(3pm) era, mwah ππ
π¦ where this page comes from
- ubuntu noble: libexporter-easy-perl 0.18-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libexporter-easy-perl 0.18-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libexporter-easy-perl 0.18-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms