Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Abstract class methods

by Anonymous Monk
on Feb 04, 2005 at 09:48 UTC ( [id://428000]=note: print w/replies, xml ) Need Help??


in reply to Abstract class methods
in thread Interfaces in Perl?

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://428000]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found