I tried to use this with a hybrid module containing a class implementation and few functions (legacy code) exported using Exporter, and after few days struggling found two problems:
1) This code will not call SUPER::import when it's imported by itself because of the first return.
2) Exporter uses caller() to populate the namespace, which is broken by this.
My modified code is here:
sub import {
my $pkg = shift;
if ($pkg ne __PACKAGE__) {
foreach my $meth ( qw(foo bar) ) {
$pkg->can($meth) or croak("Class $pkg does not define meth
+od $meth");
}
}
my $is_exp = $pkg->isa('Exporter');
$Exporter::ExportLevel++ if $is_exp;
$pkg->SUPER::import(@_);
$Exporter::ExportLevel-- if $is_exp;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
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:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.