1LexAlias(3)           User Contributed Perl Documentation          LexAlias(3)
2
3
4

NAME

6       Devel::LexAlias - alias lexical variables
7

SYNOPSIS

9        use Devel::LexAlias qw(lexalias);
10
11        sub steal_my_x {
12            my $foo = 1;
13            lexalias(1, '$x', \$foo);
14        }
15
16        sub foo {
17            my $x = 22;
18            print $x; # prints 22
19
20            steal_my_x;
21            print $x; # prints 1
22        }
23

DESCRIPTION

25       Devel::LexAlias provides the ability to alias a lexical variable in a
26       subroutines scope to one of your choosing.
27
28       If you don't know why you'd want to do this, I'd suggest that you skip
29       this module.  If you think you have a use for it, I'd insist on it.
30
31       Still here?
32
33       lexalias( $where, $name, $variable )
34           $where refers to the subroutine in which to alias the lexical, it
35           can be a coderef or a call level such that you'd give to "caller"
36
37           $name is the name of the lexical within that subroutine
38
39           $variable is a reference to the variable to install at that
40           location
41

BUGS

43       lexalias delves into the internals of the interpreter to perform its
44       actions and is so very sensitive to bad data, which will likely result
45       in flaming death, or a core dump.  Consider this a warning.
46
47       There is no checking that you are attaching a suitable variable back
48       into the pad as implied by the name of the variable, so it is possible
49       to do the following:
50
51        lexalias( $sub, '$foo', [qw(an array)] );
52
53       The behaviour of this is untested, I imagine badness is very close on
54       the horizon though.
55

SEE ALSO

57       peek_sub from PadWalker, Devel::Peek
58

AUTHOR

60       Richard Clamp <richardc@unixbeard.net> with close reference to
61       PadWalker by Robin Houston
62
64       Copyright (c) 2002, 2013, Richard Clamp. All Rights Reserved.  This
65       module is free software. It may be used, redistributed and/or modified
66       under the same terms as Perl itself.
67
68
69
70perl v5.30.0                      2019-07-26                       LexAlias(3)
Impressum