1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
#!/usr/bin/perl
$VERSION = '0.06';
use strict;
use Config;
use Getopt::Std;
use Module::ScanDeps;
use ExtUtils::MakeMaker;
use subs qw( _name _modtree );
my %opts;
getopts('BVxce:', \%opts);
my (%map, %skip);
my $core = $opts{B};
my $verbose = $opts{V};
my $eval = $opts{e};
if ($eval) {
require File::Temp;
my ($fh, $filename) = File::Temp::tempfile( UNLINK => 1 );
print $fh $eval, "\n" or die $!;
close $fh;
push @ARGV, $filename;
}
die "Usage: $0 [ -B ] [ -V ] [ -x | -c ] [ -e STRING | FILE ... ]\n" unless @ARGV;
my @files = @ARGV;
while (<>) {
next unless /^package\s+([\w:]+)/;
$skip{$1}++;
}
my $map = scan_deps(
files => \@files,
recurse => 1,
$opts{x} ? ( execute => 1 ) :
$opts{c} ? ( compile => 1 ) : (),
);
my $len = 0;
my @todo;
my (%seen, %dist, %core, %bin);
foreach my $key (sort keys %$map) {
my $mod = $map->{$key};
my $name = $mod->{name} = _name($key);
print "# $key [$mod->{type}]\n" if $verbose;
if ($mod->{type} eq 'shared') {
$key =~ s!auto/!!;
$key =~ s!/[^/]+$!!;
$key =~ s!/!::!;
$bin{$key}++;
}
next unless $mod->{type} eq 'module';
next if $skip{$name};
if ($mod->{file} eq "$Config::Config{privlib}/$key"
or $mod->{file} eq "$Config::Config{archlib}/$key") {
next unless $core;
$core{$name}++;
}
elsif (my $dist = _modtree->{$name}) {
$seen{$name} = $dist{$dist->package}++;
}
$len = length($name) if $len < length($name);
$mod->{used_by} ||= [];
push @todo, $mod;
}
$len += 2;
warn "# Legend: [C]ore [X]ternal [S]ubmodule [?]NotOnCPAN\n" if $verbose;
foreach my $mod (sort {
"@{$a->{used_by}}" cmp "@{$b->{used_by}}" or
$a->{key} cmp $b->{key}
} @todo) {
my $version = MM->parse_version($mod->{file});
if (!$verbose) {
printf "%-${len}s => '$version',", "'$mod->{name}'" if $version;
} else {
printf "%-${len}s => '0', # ", "'$mod->{name}'";
my @base = map(_name($_), @{$mod->{used_by}});
print $seen{$mod->{name}} ? 'S' : ' ';
print $bin{$mod->{name}} ? 'X' : ' ';
print $core{$mod->{name}} ? 'C' : ' ';
print _modtree && !_modtree->{$mod->{name}} ? '?' : ' ';
print " # ";
print "@base" if @base;
}
print "\n";
}
warn "No modules found!\n" unless @todo;
sub _name {
my $str = shift;
$str =~ s!/!::!g;
$str =~ s!.pm$!!i;
$str =~ s!^auto::(.+)::.*!$1!;
return $str;
}
my $modtree;
sub _modtree {
$modtree ||= eval {
require CPANPLUS::Backend;
CPANPLUS::Backend->new->module_tree;
} || {};
}
1;
__END__
=head1 NAME
scandeps.pl - Scan file prerequisites
=head1 SYNOPSIS
% scandeps.pl *.pm # Print PREREQ_PM section for *.pm
% scandeps.pl -e 'STRING' # Scan an one-liner
% scandeps.pl -B *.pm # Include core modules
% scandeps.pl -V *.pm # Show autoload/shared/data files
=head1 DESCRIPTION
F<scandeps.pl> is a simple-minded utility that prints out the
C<PREREQ_PM> section needed by modules.
If you have B<CPANPLUS> installed, modules that are part of an
earlier module's distribution with be denoted with C<S>; modules
without a distribution name on CPAN are marked with C<?>.
Also, if the C<-B> option is specified, module belongs to a perl
distribution on CPAN (and thus uninstallable by C<CPAN.pm> or
C<CPANPLUS.pm>) are marked with C<C>.
Finally, modules that has loadable shared object files (usually
needing a compiler to install) are marked with C<X>; with the
C<-V> flag, those files (and all other files found) will be listed
before the main output.
=head1 OPTIONS
=over 4
=item -e STRING
Scan I<STRING> as a string containing perl code.
=item -c
Compiles the code and inspects its C<%INC>, in addition to static scanning.
=item -x
Executes the code and inspects its C<%INC>, in addition to static scanning.
=item -B
Include core modules in the output and the recursive search list.
=item -V
Verbose mode: Output all files found during the process;
show dependencies between modules and availability.
=back
=head1 SEE ALSO
L<Module::ScanDeps>, L<CPANPLUS::Backend>, L<PAR>
=head1 ACKNOWLEDGMENTS
Simon Cozens, for suggesting this script to be written.
=head1 AUTHORS
Audrey Tang E<lt>autrijus@autrijus.orgE<gt>
=head1 COPYRIGHT
Copyright 2003, 2004, 2005 by Audrey Tang E<lt>autrijus@autrijus.orgE<gt>.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
See L<http://www.perl.com/perl/misc/Artistic.html>
=cut
|