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

I just wanted to use a more explicit method name rather than pass a value all the time. I figured it, cannot be that hard right?

Let me take a look at Class:MethodMaker and see if that gives me what I want...

Thanks!

Replies are listed 'Best First'.
Re^3: Link methods to hash values
by friedo (Prior) on Oct 01, 2006 at 19:18 UTC

    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. :)

      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.