To that end, I came up with a bit of code to include in MyOOModule that checks to see if 'base.pm' is anywhere in its calling stack, and if so, exports its symbols to the proper package (the one before 'base'). I'll show it, but not before admitting how pretty silly this all seems now. Should I have just sucked it up and donepackage LikeOOModule; use base 'MyOOModule'; sub foo { my $self = shift; if ($self->mode == OO_THIS) { ... } elsif ($self->mode == OO_THAT) { ... } }
? I mean, it's 100% less work, but I'd prefer the mechanism to be hidden from the person using MyOOModule.use base 'MyOOModule'; MyOOModule->import;
# this handles 'use base "MyOOModule"' # which doesn't call 'import' { my ($level, $prev, $pkg); while (my ($curr) = caller $level++) { $pkg = $curr, last if $prev and $prev eq "base" # NB: base.pm shows and $curr ne "base"; # up twice in a row $prev = $curr; } __PACKAGE__->export_to_level($level, $pkg, @EXPORT) if $pkg; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: use base 'XYZ' and exporting (broken)
by tye (Sage) on May 28, 2005 at 15:15 UTC | |
by japhy (Canon) on May 29, 2005 at 16:59 UTC | |
|
Re: use base 'XYZ' and exporting
by borisz (Canon) on May 28, 2005 at 13:43 UTC | |
|
Re: use base 'XYZ' and exporting
by dragonchild (Archbishop) on May 28, 2005 at 20:29 UTC | |
by japhy (Canon) on May 29, 2005 at 16:57 UTC | |
|
Re: use base 'XYZ' and exporting
by fergal (Chaplain) on May 28, 2005 at 15:28 UTC | |
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 | |
|
Re: use base 'XYZ' and exporting
by tlm (Prior) on May 28, 2005 at 13:46 UTC | |
|
Re: use base 'XYZ' and exporting
by ihb (Deacon) on May 29, 2005 at 18:46 UTC |