jds17 has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
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:
What I get as an error is:
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:
Here, $package_name is the fully qualified name of the role consuming package determined at runtime and method1,... are methods exported by this package.my $package_name = get_package_name(); eval "require $package_name"; eval "$package_name->import( qw( method1 method2 method3 )";
What I get as an error is:
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.Undefined subroutine &MyPackage::num_records called at ...
|
---|
Back to
Seekers of Perl Wisdom