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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
Outside of code tags, you may need to use entities for some characters:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||