When you do
use A;, that includes a call to
A->import but for A1 there is no import method so no variables are exported. One solution is to give A1 an import method - one that just redirects to A's import method.
package A1;
sub import
{
A->export_to_level(1, @_);
}
export_to_level is a special routine provided by
Exporter that allows you to control where the symbols will be exported to. The 1 here means export 1 level up. So it's saying "Hey A, don't export your symbols into my package (A1) export them into the package I was called from (B in your example)".
A quick plug for one of my modules. Exporter::Easy lets you write
BEGIN {
use Exporter();
use vars qw(@EXPORT @ISA);
@EXPORT = qw($var1);
@ISA = qw(Exporter);
}
use vars @EXPORT;
$var1 = "1";
as
use Exporter::Easiest q( EXPORT => $var1 );
$var1 = "1";
it handles setting up all the other
Exporter arrays too if you want it.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.