I wrote up a little example script using the new
Module::Info->subroutines_called. Anyone that's ever tried to use
grep to find a function call in a perl program will appreciate this.
The following finds all function/method calls to isa().
$ pfunc isa /usr/share/perl/5.6.1/*.pm
Called as function in /usr/share/perl/5.6.1/CGI.pm at line 316
Called as function in /usr/share/perl/5.6.1/CGI.pm at line 327
Called as function in /usr/share/perl/5.6.1/CGI.pm at line 397
Called as function in /usr/share/perl/5.6.1/CGI.pm at line 494
Called as function in /usr/share/perl/5.6.1/CGI.pm at line 495
Called as object method in /usr/share/perl/5.6.1/CPAN.pm at line 4957
Called as function in /usr/share/perl/5.6.1/Dumpvalue.pm at line 191
Called as function in /usr/share/perl/5.6.1/Dumpvalue.pm at line 218
Called as function in /usr/share/perl/5.6.1/Dumpvalue.pm at line 248
Called as function in /usr/share/perl/5.6.1/Dumpvalue.pm at line 251
Called as function in /usr/share/perl/5.6.1/Dumpvalue.pm at line 254
Called as object method in /usr/share/perl/5.6.1/Shell.pm at line 28
Called as object method in /usr/share/perl/5.6.1/base.pm at line 12
pfunc will be distributed with Module::Info from now on.
PS The above won't work quite right with 0.11 due to a fistful of bugs
I just fixed.
#!/usr/bin/perl -w
$| = 1;
use Module::Info;
my $func = shift;
foreach my $file (@ARGV) {
my $mod = Module::Info->new_from_file($file);
unless( $mod ) {
warn "Can't find $file\n";
next;
}
my @calls = sort { $a->{line} <=> $b->{line} }
grep { defined $_->{name} and $_->{name} eq $func }
$mod->subroutines_called;
foreach my $call (@calls) {
print "Called as $call->{type} in $file at line $call->{line}\n";
}
}
--
Michael G. Schwern <[EMAIL PROTECTED]> http://www.pobox.com/~schwern/
Perl Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One
I knew right away that my pants and your inner child could be best friends.