in reply to Detecting undefined subroutines at compile time

As far as I can tell, Perl cannot detect undefined subroutines at compile time.
Update: Corion /msg'd me to inform me that the following is a runtime error. I created an invalid test. A Super Search where title contains all of "undef", "sub", "comp" reveals these related threads:

It seems like Perl can detect undefined subroutines at compile time:

use warnings; use strict; foo(); __END__ Undefined subroutine &main::foo called
Can you show an example of the problem you are having?

Replies are listed 'Best First'.
Re^2: Detecting undefined subroutines at compile time
by LanX (Saint) on May 02, 2011 at 17:43 UTC
    compile(!) time :)

    ~:/tmp$ cat >tst use warnings; use strict; foo(); ~:/tmp$ perl -c tst tst syntax OK

    Cheers Rolf

Re^2: Detecting undefined subroutines at compile time
by wind (Priest) on May 02, 2011 at 17:45 UTC
    It seems like Perl can detect undefined subroutines at compile time..

    Nope, that's still runtime.

    use strict; use warnings; print "hello world\n"; foo();

    Output

    $perl func.pl hello world Undefined subroutine &main::foo called at func.pl line 6.

    I'm not sure how big of a problem this really is. This is why you make test scripts and actually verify your code. But I also wish I knew a solution for this issue as well.

      This is why you make test scripts and actually verify your code.
      I did make a test script and ran it to verify my code, as I clearly demonstrated. My problem was that my test was invalid due to my ignorance in the distinction between compile-time and runtime in this instance (also clearly demonstrated:). I'm here to learn, and I learn by making mistakes (sometimes in public).
Re^2: Detecting undefined subroutines at compile time
by tchrist (Pilgrim) on May 02, 2011 at 23:18 UTC
    Grasshopper, you can determine undefined subroutines at compile time just as soon as you have plucked the Halting Problem from the palm of my hand:
    no strict; no warnings; no less tricky; foo(lish); his::bar(tab); silly->stuff; come on, please give up; package UNIVERSAL; sub AUTOLOAD { print "I am masquerading as $AUTOLOAD(@_)\n" }
    yields when run:
    I am masquerading as main::foo(lish) I am masquerading as his::bar(tab) I am masquerading as silly::stuff(silly) I am masquerading as on::come(on) I am masquerading as give::please(give up)
      Did he really ask for undefined methods? Those calls are per definition only resolved at runtime.

      Despite manipulating UNIVERSAL in your example, the functions foo() and bar() are still found by B::Xref

      $ perl -MO=Xref,-r tst.pl|grep subused tst.pl (main) 2 main & foo + subused tst.pl (main) 3 his & bar + subused ...

      I agree that every approach can be somehow tricked out, but IMHO the vanilla cases are well covered by B::Xref.

      Cheers Rolf