After studying the Perl require docs and other links like this on Stackoverflow I’m still none the wiser, must be missing a fairly simple trick. I’m loading a module at runtime and calling a subroutine in it. The problem is I don’t necessarily know the name of the exported subroutine, but there must be one and it is exported.
The modules all look like this, ie. they roughly follow a template taken from perlmonks.org
package modules::Test;
use strict;
use Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
$VERSION = 1.00;
@ISA = qw(Exporter);
@EXPORT = (*TestSubSomeUnknownName);
@EXPORT_OK = qw(&TestSubSomeUnknownName);
%EXPORT_TAGS = ( ALL => [qw(&TestSubSomeUnknownName)]
);
sub TestSubSomeUnknownName
{
# return a hash reference
}
Then I can access the sub like this, assuming I know its name:
use Module::Load;
my $package = "modules::Test";
my $subr = "TestSubSomeUnknownName";
load $package;
# Call the subroutine
my $hashref = $package->$subr;
But what if someone mis-spelled the name in a package or I don’t know it? The solution seems to be to use one of the EXPORTs to see what’s in there, but how can it be done?
@EXPORTshould contain names not symbols.1at the end of a module.If you want to check what a package can do, use
can.