[Bioperl-l] Re: Automatic generation of set and get methods
Allen Day
allenday@ucla.edu
Fri, 15 Nov 2002 08:15:29 -0800 (PST)
... and don't forget the array based classes.
--
use strict;
use Yada::Yada::Yada; #yes, it really exists
my @func = qw(foo bar baz);
use enum(@func);
{
no strict "refs";
foreach my $func ( @func ) {
*$func = sub {
my $self = shift;
my $current = $self->[$func];
...
}
}
}
> *$func = sub {
> my $self = shift;
> my $current = $self->{$field};
> if(@_) {
> $self->{$field} = shift;
> if( $self->can("validate_$field") ) {
> $self->validate_$field; # throws exception if trouble
> }
> }
> return $current;
> }