It goes something like this:
As you can infer from the above, this version assumes that the instances of this class are implemented as hash refs. However, I don't like using AUTOLOAD when I have a lot of inheritance going on (but then, I don't use inheritance much).sub AUTOLOAD { my $self = $_[ 0 ]; ( my $name = our $AUTOLOAD ) =~ s/.*:://; return if $name eq 'DESTROTY'; die "Unknown field: $name" unless exists $OK_FIELDS{ $name }; return @_ ? $self->{ $name } = shift : $self->{ $name }; }
I've seen many descriptions of this technique. You can find one in this section of perltoot. Also, The Perl Cookbook, the Alpaca book, Object Oriented Perl discuss the use of AUTOLOAD to generate accessors. I'm sure this list is far from exhaustive.
the lowliest monk
In reply to Re^6: Modules for autogenerating accessor/mutator methods
by tlm
in thread Modules for autogenerating accessor/mutator methods
by srdst13
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |