in reply to feedback on subroutine as both function and method in one

My personal bias is against having dual-mode routines (even dual-mode constructors, which seem to be common). I find that with time, the usage of the different modes diverges enough to make them different routines. And it can be semantically confusing. If you want to share code, factor out the common code into a private routine and call it from both your function and your method.

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