|P is for Practical|
(Ovid - minor code nits) Re: Adding autoloaded methods to symbol table with using strict refsby Ovid (Cardinal)
|on Feb 25, 2002 at 21:23 UTC||Need Help??|
This is one of those times where it's appropriate to disable strict refs. However, there are a couple of issues that you may wish to be aware of. First, I see a use vars statement right after the opening brace of the AUTOLOAD sub. If you're just putting it there because this is conceptually where you feel it should go, that's probably okay, even though I confess that I prefer my use statements grouped together at the beginning of a program/module. However, I see that many programmers put the use statement in a subroutine thinking that it will delay the use of the module or pragma until needed. If that's what you are doing, you should be aware that use happens at compile time, not run time. Unfortunately, you can't just require in the vars pragma and then pass in an import list as this will kill your program under strict. If you are using 5.6 or later, you can do this:
If you're using a prior version, you may as well slap a 'no strict' at the top of the subroutine (yuck). Otherwise, if you expect to be calling AUTOLOAD virtually every run of the program, I'd put the use statement at the top of the package.
No offense, but do you know what the following does?
You have created a scalar named $parent, but you don't use it. Further, you're assigning to $class with ref($proto) || $proto. What is your reason for doing the latter? This is typically used if you want to clone an object. This might be appropriate, but rarely is it. I would change your constructor to the following, unless you have a decent justification otherwise:
Once you get everything working with that, it should be fine. If you need the other functionality later, you can add it in as needed.
Hope this helps.
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.