Debian Codegraph @

bin/pfunc

raw
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 pfunc - grep for perl functions
6
7 =head1 SYNOPSIS
8
9 pfunc subroutine FILES...
10
11 =head1 DESCRIPTION
12
13 B<pfunc> searches the named FILES for all calls to the given
14 subroutine. It will report back the file and line number each call is
15 found on along with what sort of call it is
16
17 function foo()
18 class method Class->foo()
19 object method $obj->foo()
20
21 =head1 EXAMPLE
22
23 $ pfunc isa /usr/share/perl/5.6.1/*.pm
24 Called as function in /usr/share/perl/5.6.1/CGI.pm at line 316
25 Called as function in /usr/share/perl/5.6.1/CGI.pm at line 327
26 Called as function in /usr/share/perl/5.6.1/CGI.pm at line 397
27 Called as function in /usr/share/perl/5.6.1/CGI.pm at line 494
28 Called as function in /usr/share/perl/5.6.1/CGI.pm at line 495
29 Called as object method in /usr/share/perl/5.6.1/CPAN.pm at line 4957
30 Called as function in /usr/share/perl/5.6.1/Dumpvalue.pm at line 191
31 Called as function in /usr/share/perl/5.6.1/Dumpvalue.pm at line 218
32 Called as function in /usr/share/perl/5.6.1/Dumpvalue.pm at line 248
33 Called as function in /usr/share/perl/5.6.1/Dumpvalue.pm at line 251
34 Called as function in /usr/share/perl/5.6.1/Dumpvalue.pm at line 254
35 Called as object method in /usr/share/perl/5.6.1/Shell.pm at line 28
36 Called as object method in /usr/share/perl/5.6.1/base.pm at line 12
37
38 =head1 NOTES
39
40 Its not fast, but its accurate.
41
42 =head1 AUTHOR
43
44 Michael G Schwern <[email protected]>
45
46 =head1 SEE ALSO
47
48 L<Module::Info>
49
50
51 =cut
52
53 $| = 1;
54
55 use Module::Info;
56
57 my $func = shift;
58 foreach my $file (@ARGV) {
59 my $mod = Module::Info->new_from_file($file);
60 unless( $mod ) {
61 warn "Can't find $file\n";
62 next;
63 }
64 my @calls = sort { $a->{line} <=> $b->{line} }
65 grep { defined $_->{name} and $_->{name} eq $func }
66 $mod->subroutines_called;
67 foreach my $call (@calls) {
68 my $as = $call->{type} =~ /class method/
69 ? "$call->{type} via $call->{class}"
70 : $call->{type};
71 printf "Called as %s in %s at line %d\n",
72 $as, $file, $call->{line}
73 }
74 }
75