Devel::LexAlias(3pm)

Devel::LexAlias3pm

Alias lexical variables

Usage

 use Devel::LexAlias qw(lexalias);
 sub steal_my_x {
     my $foo = 1;
     lexalias(1, '$x', \$foo);
 }
 sub foo {
     my $x = 22;
     print $x; # prints 22
     steal_my_x;
     print $x; # prints 1
 }

Overview

Devel::LexAlias provides the ability to alias a lexical variable in a subroutines scope to one of your choosing.

If you don't know why you'd want to do this, I'd suggest that you skip this module. If you think you have a use for it, I'd insist on it.

Still here?

lexalias( $where, $name, $variable )

$where refers to the subroutine in which to alias the lexical, it can be a coderef or a call level such that you'd give to "caller"

$name is the name of the lexical within that subroutine

$variable is a reference to the variable to install at that location

Releases

9 releases since Debian 5.0 (Lenny); the text changed 7 times.

  1. 5.0–6.0
  2. 7
  3. 8
  4. 9
  5. 10
  6. 11
  7. 12
  8. 13

Bugs

lexalias delves into the internals of the interpreter to perform its actions and is so very sensitive to bad data, which will likely result in flaming death, or a core dump. Consider this a warning.

There is no checking that you are attaching a suitable variable back into the pad as implied by the name of the variable, so it is possible to do the following:

 lexalias( $sub, '$foo', [qw(an array)] );

The behaviour of this is untested, I imagine badness is very close on the horizon though.

Author

Richard Clamp <[email protected]> with close reference to PadWalker by Robin Houston

From libdevel-lexalias-perl 0.05-3+b4 in Debian 13 (Trixie). Parsed by carta from the page's man source.