in reply to Abstract class methods
in thread Interfaces in Perl?
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; }
|
---|