Perl-Sensitive Sunglasses | |
PerlMonks |
Methods, within a class, pass callbacks; how to deal with that in derived class?by Anonymous Monk |
on Oct 13, 2024 at 09:34 UTC ( [id://11162231]=perlquestion: print w/replies, xml ) | Need Help?? |
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
It says (which doesn't require explanation, that's not the question):
The callbacks in above classes look the same for the SSCCE, but let's pretend they are different, and I only want to change callback behaviour in derived class. In practice, there are multiple changes, including some of the "callbacks". My class inherits from CAM::PDF, one of its "cornerstones" is the traverse method, which is called by a few specialized methods with a callback as an argument. e.g., verbatim, a short one: and relevant line in traverse is:
Is calling a callback i.e. code reference as method on an instance the accepted and OK practice, to begin with? In derived class, I'm now in some mess of a situation. Should I override every "specialized" method (even those I didn't intend to) and replace coderefs with strings? Will it hurt performance, and how much? Maybe I can fix all that at the "central location" (i.e. traverse) without touching every "specialized method" -- to convert a coderef to sub name? How to do that using Perl built-in (or core) functions? Would this solution be better (faster, cleaner, etc.)?
Back to
Seekers of Perl Wisdom
|
|