in reply to Re^2: Calling arbitrary method from new
in thread Calling arbitrary method from new

If I have a number of very similar methods, I like to highlight that by generating them in a loop with something like:

for my $method (qw/ foo bar /) { no strict 'refs'; *$method = sub { use strict 'refs'; my $self = shift; $self->{"_$method"} = shift if @_; return $self->{"_$method"}; } }

I'd usually use AUTOLOAD for this only if the list is infinite - for example if attribute methods are created on demand for arbitrary attributes supplied for the user.

Hugo