in reply to declaring accessor methods from a list
sub $name {} isn't working the way you expect it to because named subs are picked up during the compilation of the BEGIN block.
What you want to do is edit the GLOB with the name of your accessor in a fasion similar to this:
BEGIN { my @accessors = qw(one two foo); foreach my $methname (@accessors) { no strict 'refs'; *$methname = sub { # accessor sub }; } }
As an alternative to rolling your own autogenerator you could look on the CPAN as there are several mentioned elsewhere in this thread.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: declaring accessor methods from a list
by Bro. Doug (Monk) on Apr 26, 2007 at 22:53 UTC | |
by Anonymous Monk on Apr 27, 2007 at 08:04 UTC |