in reply to Re: Detecting undefined subroutines at compile time
in thread Detecting undefined subroutines at compile time

In absence of AUTOLOAD, you don't even need to eval the calls. You can just use defined &func to check whether a subroutine was defined. This will supposedly even see through forward declarations of

sub foo;

You still need to run the BEGIN blocks of all use statements at least.

Replies are listed 'Best First'.
Re^3: Detecting undefined subroutines at compile time (B::Xref)
by LanX (Saint) on May 02, 2011 at 18:15 UTC
    just found that B::Xref lists sub-calls and(!) sub-definitions:
    perl -MO=Xref tst.pl |grep foo tst.pl syntax OK &foo s1 &foo &1, &4 Subroutine foo

    so just needing to parse¹ and compare the output.

    But I agree that the dynamic nature of Perl makes such static parsing look strange.

    Cheers Rolf

    1) especially the raw output could be easily processed:

    $ perl -MO=Xref,-r tst.pl |grep foo tst.pl (definitions) 1 main & foo + subdef tst.pl syntax OK tst.pl (main) 1 main & foo + subused tst.pl (main) 4 main & foo + subused tst.pl foo 3 main $ _ + used $ cat tst.pl foo(); sub foo { print } foo();