我有一些代码要求应用程序在执行之前完全加载和编译.
有没有办法检查我的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,$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