Typeglob a bunch of closures. Save AUTOLOAD for a problem that needs the power. Here is an untested version.
Drawbacks? You have to write the line of code that lists the accessors. Advantages? You leave AUTOLOAD free to do something else, you don't get things that you didn't intend to AUTOLOAD being AUTOLOADed, your methods are visible to UNIVERSAL::can, missing methods don't get accidentally interpreted as accessors (a good AUTOLOAD can address this, but requires more code)...package Whatever::Makes::Sense; sub create_accessors { my $class = caller(); foreach my $accessor (@_) { no strict 'refs'; *{"$class\::$accessor"} = sub { my $self = shift; $self->{$accessor} = shift if @_; return $self->{$accessor}; }; } } # And elsewhere... Whatever::Makes::Sense::create_accessors(qw(foo bar baz));
In reply to Re^5: Modules for autogenerating accessor/mutator methods
by tilly
in thread Modules for autogenerating accessor/mutator methods
by srdst13
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |