Sub::Ex...Lexical(3)
π Sub::Ex...Lexical(3): the bestie edit π
okay so this is the Sub::Ex...Lexical(3) page for Sub::Exporter::Lexical, version 1.000 β itβs giving βlexical subs that clean themselves up,β and Iβm obsessed. Letβs go. π
πΈ NAME πΈ
Sub::Exporter::Lexical β to export lexically-available subs with Sub::Exporter. Thatβs the whole NAME vibe, no cap. β¨
π¦ VERSION π¦
version 1.000 β short, sweet, iconic. π
β¨ SYNOPSIS β¨
In an exporting library:
package Some::Toolkit;
use Sub::Exporter -setup => {
exports => [ qw(foo bar baz) ],
};
sub foo { ... }
sub bar { ... }
sub baz { ... }
In an importing library:
package Vehicle::Autobot;
use Sub::Exporter::Lexical lexical_installer => { -as => 'lex' };
...;
{
use Some:::Toolkit { installer => lex }, qw(foo bar);
foo(1,2,3);
my $x = bar;
...
};
# ... and here, foo and bar are no longer available ...
π DESCRIPTION π
Sub::Exporter::Lexical provides an alternate installer for Sub::Exporter. Installers are documented in Sub::Exporterβs documentation; all you need to know is that by using Sub::Exporter::Lexicalβs installer, you can import routines into a lexical scope that will be cleaned up when that scope ends. Literally so clean. π§
There are two places it makes sense to use the lexical installer: when configuring Sub::Exporter in your exporting package or when importing from a package that uses Sub::Exporter. For the first case, do something like this:
package Some::Toolkit;
use Sub::Exporter::Lexical ();
use Sub::Exporter -setup => {
exports => [ ... ],
installer => Sub::Exporter::Lexical::lexical_installer,
};
For the second:
package My::Library;
use Sub::Exporter::Lexical ();
use Some::Toolkit
{ installer => Sub::Exporter::Lexical::lexical_installer },
qw(foo bar baz);
π PERL VERSION π
This module is shipped with no promise about what version of perl it will require in the future. In practice, this tends to mean βyou need a perl from the last three years,β but you canβt rely on that. If a new version of perl ship, this software may begin to require it for any reason, and there is no promise that patches will be accepted to lower the minimum required perl. Read that twice, bestie. π
π EXPORTS π
Sub::Exporter::Lexical offers only one routine for export, and it may also be called by its full package name:
π₯ lexical_installer π₯
This routine returns an installer suitable for use as the "installer" argument to Sub::Exporter. It installs all requested routines as usual, but marks them to be removed from the target package as soon as the block in which it was called is complete. Block ends, subs dip. π
It does not affect the behavior of routines exported into scalar references.
More importantly, it does not affect scopes in which it is invoked at runtime, rather than compile time.
β οΈ This is important! It means that this works:
{
use Some::Toolkit { installer => lexical_installer }, qw(foo);
foo(1,2,3);
}
foo(); # this dies
...but this does not...
{
require Some::Toolkit;
Some::Toolkit->import({ installer => lexical_installer }, qw(foo));
foo(1,2,3);
}
foo(); # this does not die, even though you might expect it to
Finally, you canβt supply a -as => \$var install destination yet. Not yet, bestie. π«Ά
π AUTHOR π
Ricardo Signes <cpan@semiotic.systems> β iconic. π
π CONTRIBUTORS π
- Hans Dieter Pearcey β
hdp@weftsoar.net - Ricardo Signes β
rjbs@semiotic.systems
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2023 by Ricardo Signes.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. slay, legally speaking ππ
xoxo, your Perl bestie π β this page came from perl v5.40.0, dated 2024-09-02, and its manpage name is Sub::Ex...Lexical(3). π¦
π¦ where this page comes from
- epel 10: perl-Sub-Exporter-Lexical 1.000-1.el10_0 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms