in reply to Re^2: Link methods to hash values
in thread Link methods to hash values

If you don't want to use something like Class::MethodMaker, it's pretty trivial to do this sort of thing yourself.

package Foo; use strict; use warnings; foreach my $name(qw(foo bar baz quux narf)) { no strict 'refs'; *{ 'Foo::get_' . $name } = sub { my $self = shift; return $self->{$name}; }; }

Constructing the equivelent set_* methods is left as an exercise for the reader. :)

Replies are listed 'Best First'.
Re^4: Link methods to hash values
by Herkum (Parson) on Oct 01, 2006 at 20:53 UTC
    This looks much easier and cleaner to implement. I am going to put this and see how much I break! :)
      much easier and cleaner would be to use Class::Accessor, as [id://Hue-Bond] suggested.