NAME
Export::Lexical - Lexically scoped subroutine imports
VERSION
This document describes Export::Lexical version 0.0.2
SYNOPSIS
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
}
DESCRIPTION
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.
INTERFACE
Import Modifiers
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().
Subroutine Attributes
:ExportLexical
-
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 theno
statement.
DIAGNOSTICS
No diagnostics exist in this version of Export::Lexical.
CONFIGURATION AND ENVIRONMENT
Export::Lexical requires no configuration files or environment variables.
DEPENDENCIES
Perl v5.10.0+
INCOMPATIBILITIES
None reported.
BUGS AND LIMITATIONS
No bugs have been 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.
The use
statements are processed at compile time, so having multiple statements in the same scope will cause the last one encountered to affect the entire scope.
Please report any bugs or feature requests to bug-export-lexical@rt.cpan.org
, or through the web interface at http://rt.cpan.org.
AUTHOR
Chris Grau <cgrau@cpan.org>
This module is an expantion of an idea presented by Damian Conway.
COPYRIGHT AND LICENSE
Copyright (c) 2008, Chris Grau <cgrau@cpan.org>
. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.