I have some code the requires the application to be completely loaded and compiled before it should be executed.
Is there a way to check whether my Perl program is still in the compilation stage?
I have something that works, but there must be a better way:
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();
and subpkg.pm contains:
package subpkg;
use strict;
use warnings;
printf("initing subpkg\n");
main::check_compile();
1; # successfully loaded