Export::Lexical - Lexically scoped subroutine imports
package Foo; use Export::Lexical; sub foo :ExportLexical { # do something } sub bar :ExportLexical { # do something else } # In a nearby piece of code... use Foo; foo(); # calls foo() bar(); # calls bar() { no Foo 'bar'; # disables bar() foo(); # calls foo() bar(); # throws an exception }
The Export::Lexical module provides a simple interface to the custom user pragma interface in Perl 5.10. Simply by marking subroutines of a module with the :ExportLexical attribute, they will automatically be flagged for lexically scoped import.
:ExportLexical
By default, subroutines not currently exported to the lexical scope will raise exceptions when called. This behavior can be modified in two ways.
:silent
use Export::Lexical ':silent';
Causes subroutines not imported into the current lexical scope to be no-ops.
:warn
use Export::Lexical ':warn';
Causes subroutines not imported into the current lexical scope to warn with carp() instead of dying with croak().
package Foo; sub foo :ExportLexical { # do something }
This marks the foo() subroutine for lexically scoped import. When the Foo module in this example is used, the foo() subroutine is available only in the scope of the use statement. The foo() subroutine can be made into a no-op with the no statement.
use
no
No diagnostics exist in this version of Export::Lexical.
Export::Lexical requires no configuration files or environment variables.
Perl 5.10.0+
None reported.
Do not define import() or unimport() subroutines when using Export::Lexical. These will redefine the subroutines created by the Export::Lexical module, disabling the special properties of the attributes. In practice, this probably isn't a big deal.
import()
unimport()
Please report any bugs or feature requests to https://github.com/sirhc/perl-Export-Lexical/issues/.
Christopher D. Grau
This module is an expansion of an idea presented by Damian Conway.
Copyright 2008-2015, Christopher D. Grau.
This is free software, licensed under the MIT (X11) License.
Exporter::Lexical is another exporter module which provides for lexically scoped imports.
Lexical::Import lets you import functions and variables from another package into the importing lexical namespace.
Exporter::LexicalVars has a similar name, but it lets you export lexical (my) variables from your module.
perlpragma
To install Export::Lexical, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Export::Lexical
CPAN shell
perl -MCPAN -e shell install Export::Lexical
For more information on module installation, please visit the detailed CPAN module installation guide.