The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Export::Lexical - Lexically scoped subroutine imports

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 the no 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 5.10.0+

INCOMPATIBILITIES

None reported.

BUGS AND LIMITATIONS

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.

Please report any bugs or feature requests to https://github.com/sirhc/perl-Export-Lexical/issues/.

AUTHOR

Christopher D. Grau

This module is an expansion of an idea presented by Damian Conway.

COPYRIGHT AND LICENSE

Copyright 2008-2015, Christopher D. Grau.

This is free software, licensed under the MIT (X11) License.

SEE ALSO

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