Note: Data::Alias doesn't compile on Windows since it accesses private Perl internals (which the Window build process forbids) to make its powerful syntax possible. I just found Lexical::Alias which doesn't have that problem.
use Lexical::Alias qw( alias );
my ($ident, $value) = @_[0,1];
alias $_[1], $VALUES{ $ident );
$_[1] = $value if defined($value);
splice(@_, 0, 2);
Update: It looks like Lexical::Alias can't alias a scalar to a hash element. It looks like you'll need to use tie as a fallback after all. Here's a slightly simpler version than what you had:
{
package My::Tie::Scalar::Alias;
use strict;
use warnings;
use Tie::Scalar qw( );
our @ISA = 'Tie::Scalar';
sub TIESCALAR {
my ($class, $ref) = @_;
return bless $ref, $class;
}
sub FETCH { my $self = shift; return $$self; }
sub STORE { my $self = shift; $$self = shift; }
}
tie $_[1], 'My::Tie::Scalar::Alias', \$VALUES{ $_[0] };
|