Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Link methods to hash values

by friedo (Prior)
on Oct 01, 2006 at 19:18 UTC ( [id://575809]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://575809]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-03-28 10:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found