in reply to AUTOLOAD functions & inheritence

This is just an example, right, that you've given us? Because I'm just wondering why you have the statements like
if ($fname eq 'foo') { ... }
etc. You're not going to put in statements like that for every possible method that you're trying to trap in the AUTOLOAD, are you? Because that kind of defeats the purpose of having an AUTOLOAD method--if you're just testing for specific methods, why not define them in the first place?

This has a point, because my contention is that the example you've given us isn't all that helpful. AUTOLOAD should trap any methods that you don't explicitly handle in your code; so in package B, how do you know when you should pass a certain method on to A's AUTOLOAD? You're not just planning on explicitly testing for all of those cases in B, are you?

I'd like to get a better idea of what you're trying to do, because it's possible that you're asking an XYZ question. In other words, perhaps there's another way to do what you're doing, but I don't know what it could be, because I don't know what you're trying to do.

Replies are listed 'Best First'.
RE: Re: AUTOLOAD functions & inheritence
by Anonymous Monk on Mar 30, 2000 at 02:43 UTC
    It is an XYZ question. I want to know if it is possible to make things happen this specific way. This isn't a question to solve a specific problem. It is a question about the functionality of PERL. Thanks, for caring enough to post :). -Sean.

      In reply to myself (I didn't realize I was anonymous), I think I could give you a less abstract description of the specific problem that inspired this question about perl AUTOLOAD behavior.

      I created a class called AutoType that would autoload accessor methods. AutoType is meant to be a base class. The method names/data names were stored in an array. The code if ($fname -eq 'foo') was actually if (grep {$fname -eq $_} @attribs).

      I was afraid that if someone used AutoType but then created a AUTOLOAD function of their own, AutoType's AUTOLOAD function would never be used and AutoType wouldn't function.

      What I could do instead would be to test for the functions' existence and eval $func_decl the function if it doens't already exist.

      -Sean.