UNIVERSAL::can(__PACKAGE__, 'myfunc')
####
UNIVERSAL::can($pkg, 'myfunc')
##
##
sub check_for_func {
my ($func_name) = @_;
my @pkgs_with_func;
my $helper; # Don't combine this line with the assignement.
$helper = sub {
my ($pkg_name) = @_;
my $pkg = do { no strict 'refs'; \%{$pkg_name.'::'} };
push(@pkgs_with_func, $pkg_name)
if $pkg->{$func_name}
&& *{$pkg->{$func_name}}{CODE};
my $pkg_name_ = ($pkg_name eq 'main'
? ''
: $pkg_name.'::'
);
/^(.*)::$/ && $1 ne 'main' && &$helper($pkg_name_.$1)
foreach (keys(%$pkg));
};
&$helper('main');
return @pkgs_with_func;
}
print(join(', ', check_for_func('test')), $/);