So you want MyStandardModules to use other modules and export routines from those modules into the package you use it from?

If so, you could try something like this:

package MyStandardModules; use Time::HiRes (); sub import { my $dest_pkg = caller(); eval "package $dest_pkg; Time::HiRes->import('gettimeofday');"; } 1;
#!/usr/bin/perl -wl use strict; use MyStandardModules; print scalar gettimeofday();

Exporter uses caller to determine where to export to, so you could use caller() yourself, and fake the respective package that import() is being called from (as done in the eval above).

Update: a similar technique can also be used for lexical pragmas, like use strict (which don't really export anything):

package MyStandardModules; use strict; sub import { strict->import(); } 1;
#!/usr/bin/perl { use MyStandardModules; print $foo; # error } print $bar; # "OK", as outside of strict's scope __END__ $ ./889426.pl Global symbol "$foo" requires explicit package name at ./889426.pl lin +e 5. Execution of ./889426.pl aborted due to compilation errors.

In reply to Re: Export again by Eliya
in thread Export again by Cagao

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.