in reply to Does Method Exist?
I don't want to put it in an eval because that could potentially execute bottom.
Do you have a problem executing top?
$object->top->bottom
is the same as
( $object->top() )->bottom
and that executes top.
If the problem is that you are dealing with multiple classes, and some don't implement top and bottom, using a role/trait might make more sense (Class::Role, Class::Trait)
If the problem is that an object might not have a bottom or top sibling and returns false/undefined in those cases, the following would be better:
orif ($object->top && $object->top->bottom) { ... }
if (defined($object->top) && defined($object->top->bottom)) { ... }
|
|---|