I have code that requires the application to be fully downloaded and compiled before it runs.
Is there a way to check if my Perl program remains at compile time?
I have something that works, but there should 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;
source share