This code enables a module to export subroutines from parent classes. It prepares the module on import while simply using Exporter for the dirty work.
package MyMymodule; # example module
use strict;
use Carp;
use Exporter;
use SomeOtherPackage;
our $DEBUG = 0;
our @ISA = qw/SomeOtherPackage/;
our @EXPORT_OK = qw/sub1 sub2 sub3/;
sub import {
my $class = shift;
no strict 'refs';
foreach my $sub (grep /^\w/, @_) { # only subs start with \w -
+ right ?
next if *{$class.'::'.$sub}{CODE};
for (@ISA) {
next unless *{$_.'::'.$sub}{CODE};
carp "Found routine $sub for class $class in c
+lass $_" if $DEBUG;
*{$class.'::'.$sub} = *{$_.'::'.$sub}{CODE};
last;
}
}
unshift @_, $class;
goto &Exporter::import; # let exporter do it's thing
}