Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Autoload versus auto-generating accessors

by kbrannen (Beadle)
on Feb 29, 2016 at 17:30 UTC ( [id://1156466]=note: print w/replies, xml ) Need Help??


in reply to Autoload versus auto-generating accessors

I almost never use AUTOLOAD for performance reasons and to avoid the issue of it going to the wrong parent (if using inheritance). No, I've never had it go to the wrong parent, I'm just concerned about that. :)

If the number of "getters" is 5 (or so) or less, I just hand code them. If it's a larger number, then I do something like the AM does above with:
BEGIN { for my $opt ( qw< a b c d e f g > ) { no strict 'refs'; my $sub = "get_$opt"; *$sub = sub { $self=shift; return $self->{$opt}; }; } }
I might have to have a hash or something that maps english names to internal names to help that out, but still, that's the basics of it and I've been pleased with it.

I always hand code "setters" because there are normally so few of them, but I could do the above method for them too if I had to.

HTH,
Kevin

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-29 10:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found