我有一些代码需要应用程序完全加载和编译,然后才能执行。如何检查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