The general approach seems perfectly reasonable to me. However I think you have a problem with the implementation: the methods you are injecting will be closures over the current $self, so it won't work if you have more than one object in the class.
I also think the code would be easier to read (and therefore maintain) if you create the method then goto it, rather than duplicating the functionality, something like (untested):
die "No such method $AUTOLOAD. Barfing\n" unless exists $self->{$field}; if ($self->{$field}{editable}) { *$AUTOLOAD = sub { my $self = shift; $self->{$field}{value} = shift if @_; $self->{$field}{value}; }; } else { *$AUTOLOAD = sub { my $self = shift; die "Can't modify readonly field '$field'" if @_; $self->{$field}{value}; }; } goto &$AUTOLOAD;
Hugo
In reply to Re: Subroutines with differing behaviour created from AUTOLOAD
by hv
in thread Subroutines with differing behaviour created from AUTOLOAD
by davis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |