なぜモジュールは、それ自体でコンパイルが、他の場所から使用した場合に失敗しますか?
-
18-09-2019 - |
質問
私は、それ自体で罰金コンパイルに表示されるPerlモジュールを持っていますが、それが含まれているときに、他のプログラムがコンパイルを失敗の原因となっている。
me@host:~/code $ perl -c -Imodules modules/Rebat/Store.pm
modules/Rebat/Store.pm syntax OK
me@host:~/code $ perl -c -Imodules bin/rebat-report-status
Attempt to reload Rebat/Store.pm aborted
Compilation failed in require at bin/rebat-report-status line 4.
BEGIN failed--compilation aborted at bin/rebat-report-status line 4.
rebat-report-status
の最初の数行である
...
3 use Rebat;
4 use Rebat::Store;
5 use strict;
...
解決
編集(後世のために):これが発生するためにもう一つの理由は、おそらく最も一般的な理由は、あなたが使用しているモジュール間の循環依存関係があることがある。
。 <時間>手がかりのためRebat/Store.pm
でご覧ください。あなたのログは、のリロードのへの試行が中止されたと言います。たぶんRebat
はすでにRebat::Store
をインポートし、Rebat::Store
は二回ロードされることに対して、いくつかのパッケージスコープのチェックを持っています。
このコードは、私が意味する状況の種類を示しています
# m1.pl:
use M1;
use M1::M2;
M1::M2::x();
# M1.pm
package M1;
use M1::M2;
1;
# M1/M2.pm
package M1::M2;
our $imported = 0;
sub import {
die "Attempt to reload M1::M2 aborted.\n" if $imported++;
}
sub x { print "42\n" }
1;
<時間>
$ perl m1.pl
Attempt to reload M1::M2 aborted.
BEGIN failed--compilation aborted at m1.pl line 3.
あなただけuse M1::M2
でm1.pl
行を削除する場合はのコードはコンパイル(および42を印刷)します。あなたのケースでは、明示的にあなたのプログラムにuse Rebat::Store
する必要はないかもしれません。
他のヒント
Attempt to reload %s aborted.
(F) You tried to load a file with "use" or "require" that failed to
compile once already. Perl will not try to compile this file again
unless you delete its entry from %INC. See "require" in perlfunc
and "%INC" in perlvar.
所属していません StackOverflow