Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How can I use AUTOLOAD to magically define get and set methods for my member data?

by chromatic (Archbishop)
on Apr 20, 2000 at 23:20 UTC ( [id://8248]=note: print w/replies, xml ) Need Help??


in reply to How can I use AUTOLOAD to magically define get and set methods for my member data?

Here's a quick and dirty autoloader. It assumes your member data is stored in a hash, and that the get and set functions take the form "get_foo" and "set_bar".
use vars '$AUTOLOAD'; # a while later sub AUTOLOAD { my $self = shift; return if ($AUTOLOAD =~ /DESTROY/); # don't mess with garbage c +ollection if ($AUTOLOAD =~ /.*::set_(\w+)/) and (@_) { return $self->{$1} = shift; } elsif ($AUTOLOAD ~= /.*::get_(\w+)/) { return $self->{$1}; } # handle bad methods here, return undef ? }
  • Comment on Re: How can I use AUTOLOAD to magically define get and set methods for my member data?
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-16 15:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found