As I already made clear, I use AUTOLOAD for very simple modules. In fact, I have never needed AUTOLOAD for anything else, so I have not attained the point of wanting to "save it". (What can I say? I'm a lowly script writer, not a heavy-hitting module meister.) I'm aware of the technique you describe, though I am sorry to say that I use it with AUTOLOAD:
(Yes, I posted a different version in another the reply, because I think it is more standard and easier to follow.)sub AUTOLOAD { my $self = $_[ 0 ]; ( my $name = our $AUTOLOAD ) =~ s/.*:://; return if $name eq 'DESTROTY'; die "Unknown field: $name" unless exists $self->{ $name }; no strict 'refs'; *$AUTOLOAD = sub { my $self = shift; return @_ ? $self->{ $name } = shift : $self->{ $name + }; }; goto &$AUTOLOAD; }
So, please tell me, what are the things one should be saving AUTOLOAD for instead of wasting it on accessors?
Update: Bug in the original version fixed.
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: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |