Think about Loose Coupling | |
PerlMonks |
goto &method and skipping call frameby LanX (Saint) |
on Mar 04, 2021 at 20:12 UTC ( [id://11129129]=perlquestion: print w/replies, xml ) | Need Help?? |
LanX has asked for the wisdom of the Perl Monks concerning the following question:
Hi goto &NAME is a way to call a sub NAME() while autoloading and transparently skipping the actual frame for sub AUTOLOAD() on the call stack. Hence caller wouldn't show AUTOLOAD but the line which triggered it. That's also of practical importance when using carp() et al from Carp , because you don't wanna get the error shown inside the AUTOLOAD's code. But what if I want to delegate to a method from an autoloaded sub? My best guess is to call it as a normal sub and to prepend the object to @_
And - to my big surprise - this is even respecting inheritance, i.e. if the method belongs to a super-class of OBJ, it's properly delegated. Questions:
Cheers Rolf PS: Hey Mike can't wait to hear about your huge "expertise" from JAVA, bread-trucks and millions of lines of PHP ...
UPDATE2 monks msged me Where does $OBJ come from? In this simplified example you can consider it a global, like our $OBJ = SomeClass->new(); The real use case is a more complicated implementation of a with construct (like in with), where $OBJ is a closure var and AUTOLOAD is localized to a blocks context.
Back to
Seekers of Perl Wisdom
|
|