From: Malcolm Beattie Date: Mon, 15 Sep 1997 14:09:11 +0000 (+0000) Subject: Add undefined-subs option to Lint.pm. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2938739d2e019a7e34b70a9c71ba3903201f6d6d;p=p5sagit%2Fp5-mst-13.2.git Add undefined-subs option to Lint.pm. p4raw-id: //depot/perlext/Compiler@65 --- diff --git a/B/Lint.pm b/B/Lint.pm index 3b4ea7e..d9659f9 100644 --- a/B/Lint.pm +++ b/B/Lint.pm @@ -67,6 +67,15 @@ lives in a non-current package but begins with an underscore ("_"). Warnings aren't issued for the special case of the single character name "_" by itself (e.g. $_ and @_). +=item B + +This option warns whenever an undefined subroutine is invoked. +This option will only catch explicitly invoked subroutines such +as C and not indirect invocations such as C<&$subref()> +or C<$obj-Emeth()>. Note that some programs or modules delay +definition of subs until runtime by means of the AUTOLOAD +mechanism. + =item B Turn all warnings on. @@ -129,7 +138,7 @@ my %valid_check; BEGIN { map($valid_check{$_}++, qw(context implicit_read implicit_write dollar_underscore - private_names)); + private_names undefined_subs)); } # Debugging options @@ -239,6 +248,17 @@ sub B::GVOP::lint { warning('Illegal reference to private name %s', $gv->NAME); } } + if ($check{undefined_subs}) { + if ($op->ppaddr eq "pp_gv" && $op->next->ppaddr eq "pp_entersub") { + my $gv = $op->gv; + my $subname = $gv->STASH->NAME . "::" . $gv->NAME; + no strict 'refs'; + if (!defined(&$subname)) { + $subname =~ s/^main:://; + warning('Undefined subroutine %s called', $subname); + } + } + } } sub B::GV::lintcv {