Beefy Boxes and Bandwidth Generously Provided by pair Networks
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??


in reply to How many ways are there to use AUTOLOAD?

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-03-28 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found