package alias;
use strict;
BEGIN {
use base qw(Exporter);
@alias::EXPORT = qw(make_alias);
}
sub make_alias {
tie $_[0], __PACKAGE__, \$_[1];
}
sub TIESCALAR {
my($class, $target_ref) = @_;
bless $target_ref, $class;
}
sub STORE {
my $self = shift;
$$self = shift;
}
sub FETCH {
my $self = shift;
$$self;
}
1;
No XS here, works fine with 5.x, but maybe a little slow :)
use alias;
my $self = { x => 1 };
make_alias my $x, $self->{x};
$x = 100;
print $self->{x}; # 100
--
Tatsuhiko Miyagawa
miyagawa@cpan.org
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.