I have written a module where I would like to use Role::Basic. At runtime, I want to require a specific module consuming such a role and also to import some of its names.
I could not get the import of the names right. What I tried is the following:
my $package_name = get_package_name();
eval "require $package_name";
qw( method1 method2 method3 )";
Here, $package_name is the fully qualified name of the role consuming package determined at runtime and method1,... are methods exported by this package.
What I get as an error is:
Undefined subroutine &MyPackage::num_records called at ...
where MyPackage is the name of the current package (i.e. the one the above code is in) and not the desired one, i.e. $package_name.