The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Lexical::Util - utilities for lexical item manipulation

SYNOPSIS

        use Lexical::Util qw(alias);

        $cvref = frame_to_cvref($level);
        lexalias($cvref, '$name', \$variable);

DESCRIPTION

Lexical::Util is a module containing some common routines used by modules dealing with the lexical variables of routines other than their own. They are taken from various sources, including PadWalker, Perl6::Binding, and Lexical::Alias. This module is used in version 0.7 and greater of Perl6::Binding, as well as in the fields::aliased package, to prevent duplication of code.

This package should not be used by end users.

EXPORTABLE ROUTINES

frame_to_cvref

$cvref = frame_to_cvref($level);

Finds the code reference (subroutine) for the stack frame indicated by $level, which is similar to the argument for "caller" in perlfunc. If the return value is true, the function succeeded.

lexalias

lexalias($cvref, '$name', \$value);

Creates a lexical alias for a variable called $name pointing to the variable $value. $cvref is a code reference returned by "frame_to_cvref". If $cvref is undef, this routine dies.

KNOWN ISSUES

  • If $cvref is the scalar 0, then lexalias must have been called from the top level of the program (outside of any subroutines) and the variable being aliased must also exist at the top level. This doesn't appear to work under the debugger, however. I hope to eliminate this restriction with more research.

COPYRIGHT AND LICENSE

Copyright 2004 Kevin Michael Vail

This program is free software. It may be copied and/or redistributed under the same terms as Perl itself.

AUTHOR

Kevin Michael Vail <kevin@vaildc.net>