use MightyMod;
use XML::Simple;
my $y = BadSub(0);
my $z = GoodSub(0);
print "$y $z";
####
package MightyMod;
use strict;
require Exporter;
our @EXPORT = qw(GoodSub);
our @ISA = qw(Exporter);
sub GoodSub {
return 42 + LostSub(@_);
}
1;
####
#!/usr/bin/perl -w
use strict;
use File::Find;
my %known;
find(
sub{$known{$File::Find::name}=1 if /\.pm$/},
grep {$_ ne '.'} @INC
);
my $pgm = shift or die;
my @xref = `perl -MO=Xref,-r $pgm 2>/dev/null` or die;
# Xref data looks like this:
# test.pl (definitions) 5 main & GoodSub subdef
# test.pl (main) 4 (lexical) $ y intro
# test.pl (main) 4 main & BadSub subused
my %h;
foreach (@xref) {
my ($file, $where, $line, $package, $sym, $name, $how) = split;
next if $how eq 'subused' and $known{$file};
$h{$how}{$name}++;
}
foreach (sort keys %{$h{subused}}) {
print "$_\n" unless $h{subdef}{$_};
}
####
$ ./Find_Undefined_Subroutines.pl test.pl
BadSub
LostSub