我创建了两个测试模块,X.pm
并且X2.pm
. 该X.pm
模块有效。该X2.pm
模块没有,至少不像我期望的那样。
下午
package X {
use enum::fields qw(I_VAL);
use parent qw(Exporter);
our @EXPORT = qw(I_VAL);
}
X2.pm
package X2 {
our @EXPORT = qw(I2_VAL);
use enum::fields (@EXPORT);
use parent qw(Exporter);
}
测试程序是:
use X;
use X2;
printf("I_VAL = %d\n", I_VAL);
printf("I2_VAL = %d\n", I2_VAL);
输出是:
bash$ ./tmp/testit
I_VAL = 0
Undefined subroutine &X2::I2_VAL called at /home/bennett/tmp/testit line 15.
真正的项目有几十个enum::fields
,并且X2.pm
是我尝试使枚举与导出保持同步。
我的问题是:
- 为什么不起作用
X2
?enum::fields
是在运行前导出(导入) 吗? - 我该怎么办?