1

I've researched (google) for without success, so I turn to S.O. for help.

I seem to remember a way of coding a perl package so that if any missing methods that are called, a helper function will perform the action.

All the 'missing' methods have the same look and feel. They just need call another library with the passed in arguments, plus the name of the 'missing' method.

The class will have some concrete methods, eg. constructor and destructors.

Many thanks.

1 Answer 1

3

I think you're looking for autoloading

Normally, you can't call a subroutine that isn't defined. However, if there is a subroutine named AUTOLOAD in the undefined subroutine's package (or in the case of an object method, in the package of any of the object's base classes), then the AUTOLOAD subroutine is called with the same arguments that would have been passed to the original subroutine. You can define the AUTOLOAD subroutine to return values just like a regular subroutine, or you can make it define the routine that didn't exist and then call that as if it'd been there all along.

The function/method name called is available thus:

my $method= our $AUTOLOAD;
Sign up to request clarification or add additional context in comments.

3 Comments

See above for the function name (and the linked doc)
Thanks for the great and quick answer. Appreciated.
No problem. I felt your pain since I knew I'd seen the above years ago, but couldn't remember what it was called

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.