Do you know where your variables are? | |
PerlMonks |
Re: How many ways are there to use AUTOLOAD?by mortis (Pilgrim) |
on Jul 20, 2004 at 21:26 UTC ( [id://376096]=note: print w/replies, xml ) | Need Help?? |
I've used this kind of technique over and over in my Perl projects. I go one step further and in addition to logging the mistake, I make it a hard error by throwing an exception (or using confess) so I get a full stack trace so I can see how things got that way. I sometimes use the idiom $obj->$method, so it's not always clear how the incorrect (typod) method name happened by looking only a single stack frame up.
It would be nice if perl had a 'use strict qw(methods);' mode for detecting as many of these issues as possible at compile time (of course you'd also have to be disciplined about declaring variable types) instead of having to deferr them to run-time. I usualy put that kind of AUTOLOAD into the base class for all my objects. As far as using AUTOLOAD to do anything else I usualy avoid it as it can make for harder to maintain and understand code in my opinion. There are some places where it can be very useful but I don't find myself using it too frequently (more often I will use code generation for refactorable syntax). Kyle
In Section
Seekers of Perl Wisdom
|
|