in reply to Re^5: Modules for autogenerating accessor/mutator methods
in thread Modules for autogenerating accessor/mutator methods
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Modules for autogenerating accessor/mutator methods
by diotalevi (Canon) on Jun 05, 2005 at 00:42 UTC | |
by tlm (Prior) on Jun 05, 2005 at 02:32 UTC | |
by diotalevi (Canon) on Jun 05, 2005 at 02:35 UTC | |
by tlm (Prior) on Jun 05, 2005 at 03:15 UTC | |
by diotalevi (Canon) on Jun 05, 2005 at 04:17 UTC | |
| |
by tilly (Archbishop) on Jun 05, 2005 at 04:11 UTC |