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:
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 { my $package = "CGI::Application::Plugin::Session"; $_[0] = $package; goto $package->can("import"); }
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.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, @_); }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |