3 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
4 if 0; # not running under some shell
12 use ExtUtils::MakeMaker;
13 use subs qw( _name _modtree );
16 getopts('BVRxce:C:', \%opts);
20 my $verbose = $opts{V};
22 my $recurse = $opts{R} ? 0 : 1;
26 my ($fh, $filename) = File::Temp::tempfile( UNLINK => 1 );
27 print $fh $eval, "\n" or die $!;
29 push @ARGV, $filename;
32 die "Usage: $0 [ -B ] [ -V ] [ -x | -c ] [ -R ] [-C FILE ] [ -e STRING | FILE ... ]\n" unless @ARGV;
36 next unless /^package\s+([\w:]+)/;
43 $opts{x} ? ( execute => 1 ) :
44 $opts{c} ? ( compile => 1 ) : (),
45 $opts{V} ? ( warn_missing => 1 ) : (),
46 $opts{C} ? ( cache_file => $opts{C}) : (),
52 my (%seen, %dist, %core, %bin);
54 foreach my $key (sort keys %$map) {
55 my $mod = $map->{$key};
56 my $name = $mod->{name} = _name($key);
58 print "# $key [$mod->{type}]\n" if $verbose;
60 if ($mod->{type} eq 'shared') {
67 next unless $mod->{type} eq 'module';
71 my $privPath = "$Config::Config{privlibexp}/$key";
72 my $archPath = "$Config::Config{archlibexp}/$key";
73 $privPath =~ s|\\|\/|og;
74 $archPath =~ s|\\|\/|og;
75 if ($mod->{file} eq $privPath
76 or $mod->{file} eq $archPath) {
81 elsif (my $dist = _modtree->{$name}) {
82 $seen{$name} = $dist{$dist->package}++;
85 $len = length($name) if $len < length($name);
86 $mod->{used_by} ||= [];
93 print "# Legend: [C]ore [X]ternal [S]ubmodule [?]NotOnCPAN\n" if $verbose;
95 foreach my $mod (sort {
96 "@{$a->{used_by}}" cmp "@{$b->{used_by}}" or
97 $a->{key} cmp $b->{key}
100 my $version = MM->parse_version($mod->{file});
103 printf "%-${len}s => '$version',", "'$mod->{name}'" if $version;
105 printf "%-${len}s => '0', # ", "'$mod->{name}'";
106 my @base = map(_name($_), @{$mod->{used_by}});
107 print $seen{$mod->{name}} ? 'S' : ' ';
108 print $bin{$mod->{name}} ? 'X' : ' ';
109 print $core{$mod->{name}} ? 'C' : ' ';
110 print _modtree && !_modtree->{$mod->{name}} ? '?' : ' ';
112 print "@base" if @base;
118 warn "No modules found!\n" unless @todo;
124 $str =~ s!^auto::(.+)::.*!$1!;
131 require CPANPLUS::Backend;
132 CPANPLUS::Backend->new->module_tree;
143 scandeps.pl - Scan file prerequisites
147 % scandeps.pl *.pm # Print PREREQ_PM section for *.pm
148 % scandeps.pl -e 'STRING' # Scan an one-liner
149 % scandeps.pl -B *.pm # Include core modules
150 % scandeps.pl -V *.pm # Show autoload/shared/data files
151 % scandeps.pl -R *.pm # Don't recurse
152 % scandeps.pl -C CACHEFILE # use CACHEFILE to cache dependencies
156 F<scandeps.pl> is a simple-minded utility that prints out the
157 C<PREREQ_PM> section needed by modules.
159 If you have B<CPANPLUS> installed, modules that are part of an
160 earlier module's distribution with be denoted with C<S>; modules
161 without a distribution name on CPAN are marked with C<?>.
163 Also, if the C<-B> option is specified, module belongs to a perl
164 distribution on CPAN (and thus uninstallable by C<CPAN.pm> or
165 C<CPANPLUS.pm>) are marked with C<C>.
167 Finally, modules that has loadable shared object files (usually
168 needing a compiler to install) are marked with C<X>; with the
169 C<-V> flag, those files (and all other files found) will be listed
170 before the main output. Additionally, all module files that the
171 scanned code depends on but were not found (and thus not scanned
172 recursively) are listed. These may include genuinely missing
173 modules or false positives. That means, modules your code does
174 not depend on (on this particular platform) but that were picked
175 up by the heuristic anyway.
183 Scan I<STRING> as a string containing perl code.
187 Compiles the code and inspects its C<%INC>, in addition to static scanning.
191 Executes the code and inspects its C<%INC>, in addition to static scanning.
195 Include core modules in the output and the recursive search list.
199 Only show dependencies found in the files listed and do not recurse.
203 Verbose mode: Output all files found during the process;
204 show dependencies between modules and availability.
206 Additionally, warns of any missing dependencies. If you find missing
207 dependencies that aren't really dependencies, you have probably found
212 Use CACHEFILE to speed up the scanning process by caching dependencies.
213 Creates CACHEFILE if it does not exist yet.
219 L<Module::ScanDeps>, L<CPANPLUS::Backend>, L<PAR>
221 =head1 ACKNOWLEDGMENTS
223 Simon Cozens, for suggesting this script to be written.
227 Audrey Tang E<lt>autrijus@autrijus.orgE<gt>
231 Copyright 2003, 2004, 2005, 2006 by Audrey Tang E<lt>autrijus@autrijus.orgE<gt>.
233 This program is free software; you can redistribute it and/or modify it
234 under the same terms as Perl itself.
236 See L<http://www.perl.com/perl/misc/Artistic.html>