I've got a polymorphic array of objects which implement two (informal) interfaces. I want to be able to differentiate them with reflection along the lines of:
if (hasattr(obj, 'some_method')) {
# `some_method` is only implemented by one interface.
# Now I can use the appropriate dispatch semantics.
} else {
# This must be the other interface.
# Use the alternative dispatch semantics.
}
Maybe something like this works?:
if (*ref(obj)::'some_method') {
# ...
I have difficulty telling when the syntax will try to invoke a subroutine and when it will return a subroutine reference. I'm not too familiar with package symbol tables ATM and I'm just trying to hack something out. :-)
Thanks in advance!