in reply to Re^5: Modules for autogenerating accessor/mutator methods
in thread Modules for autogenerating accessor/mutator methods
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Modules for autogenerating accessor/mutator methods
by wazoox (Prior) on Jun 05, 2005 at 07:34 UTC |