in reply to use base 'XYZ' and exporting
Won't this fail if a second module tries to use base?
You could make your own customised class which follows the conventions of "use":
use baseimp 'Foo' => ['Import', 'some', 'stuff'], 'Bar', # import defaults 'Buz' => [] # don't call import, just like use Buz () package baseimp; use base 'base'; # :) # unfortunately most modules (including base.pm) are hardwired to use +caller(0) so trickery is needed use Sub::Uplevel; sub import { my $pkg = shift; $base_import = UNIVERSAL::can(__PACKAGE__, "SUPER::import"); while (my $class = shift) { # let base do it's thing uplevel(1, $base_import, $class); # now do what use would do my $imp_args; if (ref($_[0])) { $imp_args = shift; undef $imp_args unless @$imp_args; } else { $imp_args = []; } if ($imp_args) { $class_import = UNIVERSAL::can($class, "import"); uplevel(1, $class_import, $class, @$imp_args); } } }
So without any array refs, this works exactly like base except it _does_ import stuff, when you add array refs you get to control the imports exactly as with a normal use.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: use base 'XYZ' and exporting
by ihb (Deacon) on May 29, 2005 at 19:16 UTC | |
by fergal (Chaplain) on May 29, 2005 at 23:04 UTC | |
by ihb (Deacon) on May 30, 2005 at 00:33 UTC | |
by fergal (Chaplain) on May 30, 2005 at 10:14 UTC |