in reply to feedback on subroutine as both function and method in one
That said, you can do something like this to detect being called as a function, as a package method, or as an object method, even in the face of inheritance:
sub myEverythingMethod { my $classOrObject = shift if UNIVERSAL::isa( $_[0], __PACKAGE__ ); if (!defined($classOrObject) ) { # function } elsif (ref($classOrObject)) { # object method } else { #package method } }
update: fixed setting of classOrObject
|
|---|