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;
}