Hey all,

I've looked all over but can't quite figure out how to do the following without what seems to be onerous code:

I have a module, "Foo/Core.pm" that has a few functions, variables, and tags (:DEFAULT, etc) to export.

I have another module, "Foo/Core/Specialized.pm" that I'd like to be able to have export all of Foo::Core's stuff, plus some other stuff -- including the ability to specify some parameters in the use line.

Here's a code example of what syntax I want:

... use Foo::Core::Specialized qw(Mixed func_a, func_b, :TAG_A); ...

I've got a custom Foo::Core::Specialized::import() sub that does this:

### From Foo::Core::Specialized use Foo::Core; sub import { my $this_pkg = shift; my @imports = @_; ### Catch the word "Mixed" in the import list and react to it, ### removing it before continuting. foreach (my $i = 0; $i < scalar(@imports); $i++) { if ($imports[$i] eq 'Mixed') { do_something(); splice(@imports, $i--, 1); } } ### The goal here is to switch to the calling package, do the ### import from the Foo::Core package into that calling package, ### then switch back to this package. The problem is, it ### doesn't work... there's no error, but the symbols aren't ### exported (anywhere I can find them =) either. my $caller = caller(); eval "package $caller;"; Foo::Core->import(@imports); eval "package $this_pkg;"; }

This kind of "parasitic" export would simply piggy-pack off the other module's export routine, adding some functionality of its own in some way or another.

When I use the Foo::Core package directly the symbols are exported properly (but obviously I don't get the specialized behavior). I could do:

... use Foo::Core qw(func_a, func_b, :DEFAULT); use Foo::Core::Specialized 'Mixed'; ...

but it seems like I shouldn't have to. If I *have* to loop through the @Foo::Core::EXPORT, @Foo::Core::EXPORT_OK, and %FOO::Core::EXPORT_TAGS lists and map the symbols manually, I can do that, but again ... it seems like I shouldn't have to.

I'm not sure if it matters, but the caller will be 'main' the vast majority of the time.

Thanks!

Updated: I forgot to mention that Foo::Core::Specialized uses Foo::Core

In reply to Creating "parasitic" exports by sirrobert

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.