lamber45 has asked for the wisdom of the Perl Monks concerning the following question:
So I'm trying to build an interpreter for a certain non-perl bytecode, and I think I'll be able to represent classes in that system as perl packages.
Method invocations in that system are by method name (OK to overload) and argument types. When the bytecode says to call a method "foo" with descriptor "EGXX", I'd like my code to first check whether a sub "foo__EGXX" exists in the target package (or any of its base packages, recursively); if it doesn't find it, I'd like to check for a sub "foo" (also recursively).
Is there a (standard or easy-to-install) module that does the "find a sub, don't invoke it yet" part? If I have to roll my own, I guess I'd do recursive ascent through @ISA, but how do I test if a sub is defined? Is it as simple as
?if (${ $package . '::' }{ $longName }) { $value = eval '$objectref->' . $longName . '( @args )'; } else { $value = eval '$objectref->' . $shortName . '( @args )'; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to determine if a sub is defined in a package, without calling it?
by haukex (Archbishop) on Feb 27, 2017 at 20:34 UTC | |
|
Re: How to determine if a sub is defined in a package, without calling it?
by stevieb (Canon) on Feb 27, 2017 at 20:37 UTC |