您可以爲您的掃描儀軟件包創建一個自定義導入子。 Exporting Without Using Exporter's import Method。
請注意,如果用戶只依賴默認的@EXPORT,則此代碼僅適用。如果你希望他們能夠指定他們想要的功能,那麼你必須在調用export_to_level之前進行過濾。
package Scanner;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(scannersub);
use strict;
use warnings;
sub import {
Scanner->export_to_level(1, @_);
ScannerTwo->export_to_level(1, @_);
}
sub scannersub {
print "scanner->sub says hi\n";
}
package ScannerTwo;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(scannertwosub);
sub scannertwosub {
print "scannertwo->sub says hi\n";
}
1;
__END__
和腳本
use Scanner;
use strict;
use warnings;
scannersub();
scannertwosub();
1;
__END__
最後,我會是房產管理信息系統,如果我沒有提到,這不是它的表面上的好主意。這個代碼的未來維護者不會輕易追蹤這些潛艇。所以無論你想在同一個文件中使用不同的軟件包的理由,我懷疑有一個更好的解決方案。
爲什麼他們需要在同一個文件 – justintime
@justintime,模塊隨着時間的推移而演變,必須保持在一起。將它們保存在一個文件中是確保它們相互匹配並保持在一起的方式之一。 – nsg
他們爲什麼「必須呆在一起」。系統發展,有時你需要重新組織代碼的可維護性。 – justintime