我有一些代碼需要應用程序完全加載和編譯,然後才能執行。如何檢查Perl編譯是否已經完成?
有沒有辦法來檢查我的Perl程序是否仍處於編譯階段?
我有一些作品,但必須有一個更好的辦法:
sub check_compile {
printf("checking\n");
foreach my $depth (0..10) {
my ($package, $filename, $line, $subroutine) = caller($depth);
last unless (defined($package));
printf(" %s %s %s %s %s\n", $depth, $package, $filename, $line, $subroutine);
if ($subroutine =~ /::BEGIN$/) {
printf("in compile\n");
return 1;
}
}
printf("not in compile\n");
return 0;
}
BEGIN {
check_compile();
}
use subpkg;
check_compile();
和subpkg.pm包含:
package subpkg;
use strict;
use warnings;
printf("initing subpkg\n");
main::check_compile();
1; # successfully loaded
爲什麼不在編譯完成後簡單地設置全局標誌,並檢查該標誌的值? – Ether 2010-08-26 23:32:29