use mro qw( ); use Scalar::Util qw( blessed ); sub get_package { my ($obj, $method_name) = @_; defined( my $class = blessed($obj) ) or return undef; for my $pkg_name (@{ mro::get_linear_isa($class) }) { my $pkg = do { no strict qw( refs ); *{ $pkg_name.'::'.$method_name } }; return $pkg_name if *{$pkg}{CODE}; } return undef; } #### use B qw( svref_2object ); sub get_package { my ($obj, $method_name) = @_; my $method_ref = $obj->can($method_name) or return undef; return svref_2object($method_ref)->GV->STASH->NAME; } #### use B qw( svref_2object ); sub get_package { my ($obj, $method_name) = @_; my $method_ref = $obj->can($method_name) or return undef; return svref_2object($method_ref)->FILE; }