package thisPack; sub smartish_sub { my $self; # for instance reference, if called that way my $class; # for classname, if called that way if (ref $_[0]) { if (UNIVERSAL::isa($self,'thisPack')) { # ( corrected from earlier ->isa call) # it's an instance method invocation my $self = shift @_; } # else it's not an instance, but it is a ref, so # it must be a fully-qualified invocation } else { # not a reference; ought to be class invocation my $class = shift; die "first argument to smartsub must be hashref\n" unless UNIVERSAL::isa($class, 'thisPack'); } # now any class- or instance- invocations have been # shifted off @_ my ($hash, $string) = @_; # might want error-checking here. print "$hash->{foo}\n$string"; } sub new { bless {}, shift; }