First tip. Get in the habit of using @EXPORT_OK rather than @EXPORT. You can thank me when you are debugging and are trying to find where scotch comes from.

The usual way to solve this problem is to import and re-export. But that is what you don't want to do. So what else can we do?

Well the underhanded way to do what you want is:

use CGI::Application::Plugin::Session; sub import { my $package = "CGI::Application::Plugin::Session"; $_[0] = $package; goto $package->can("import"); }
But that is kind of magic. And won't work if you want to do the re-export trick more than once. After peeking at Exporter carefully, you should be able to do the same thing as the above with the following:
use CGI::Application::Plugin::Session; sub import { shift; # Throw away my class my $call_package = caller(); my $export_package = "CGI::Application::Plugin::Session"; Exporter::export($export_package, $call_package, @_); }
And the advantage of this is that if you wanted to do this trick for multiple packages you could look in the @EXPORT and @EXPORT_OK lists for each, and call export on each while passing through the right arguments.

Update: GrandFather noted a missing ')'. Fixed.


In reply to Re: get package x to import package y if you use package z by tilly
in thread get package x to import package y if you use package z by leocharre

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.