in reply to Compile-time checking for undef subroutines?

Is there a way I can check the validity of all the subroutines in my perl program
Unfortunately no. Because subroutines can be called and created dynamically there's no way of telling at compile time whether every subroutine has been defined (which is potentially any subroutine). You could possibly do some trickery with the B:: modules to get some way towards your goal (i.e if you assume all subroutines and subroutines calls are static). And if you're dealing with methods then it'd be difficult, if not impossible, to determine whether every method exists due, in no small part, to inheritance
HTH

_________
broquaint

  • Comment on Re: Compile-time checking for undef subroutines?

Replies are listed 'Best First'.
Re: Compile-time checking for undef subroutines?
by Abigail-II (Bishop) on May 05, 2003 at 23:48 UTC
    Well, there's a bit more to that. Remember that in Perl you can call subroutines without using parenthesis. The compiler will only allow that if it knows about such a subroutine - the compiler must have seen either a definition or a declaration of the subroutine; that is, there must be an entry in the namespace stash. This means that when the compiler encounters something that looks like a subroutine (bareword that was declared defined as a sub, bareword followed by parenthesis or a bareword preceeded by &), it knows whether it's at that moment defined or declared.

    The reason you state, it can be created at runtime, is the reason the compiler doesn't balk, but postpones it to the runtime environment.

    So, the answer is, "yes, the compiler knows, and no, that information isn't available, but if it were, it wouldn't be half as useful as you might think - which is also the reason why it isn't available".

    Abigail