Here's how to do it without any eval at all. As a plus, you get compile-time syntax checking:
sub Instance_Var ($) { my $package=__PACKAGE__; my ($var)=@_; my $accessor_name = "$package\::$var"; my $acc = sub { my $t = shift; $t->{$var}=$_[0] if @_; $t->{$var}; }; # Now install our anonymous subroutine as $package::$var no strict 'refs'; *{ $accessor_name } = $acc; }
You might also want to see Class::Accessor and any of the other Accessor modules. Maybe also Class::Data::Inheritable.
In reply to Re: How do I get to this 'simple' helper?
by Corion
in thread How do I get to this 'simple' helper?
by perl-diddler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |