#!/usr/bin/perl -w use strict; use vars qw/ $mods $files %ismod/; use FindRequires; use DBI; my $dbh=DBI->connect('dbi:DBM(RaiseError=1):'); recurse($mods->[0],''); sub recurse { my($mod,$insert)=@_; return unless $mod; print "$insert$mod\n"; $insert .= ' '; for my $modfile(@{$files->{$mod}}) { recurse($modfile,$insert); } } package FindRequires; # by [theorbtwo] use warnings; use strict; my $reallibimport; use lib; BEGIN { $reallibimport = \&lib::import; } { no warnings 'redefine'; sub lib::import { $reallibimport->(@_); ($INC[0], $INC[1]) = ($INC[1], $INC[0]); } } unshift @INC, sub { my ($self, $lookingfor) = @_; # != works if it is OK, but if it's not, this is probably a string. # Use ne to avoid warning, even though we're about to die. if ($INC[0] ne $self) { die "\@INC got messed up"; } # return if $lookingfor =~ /\.al$/; if ($lookingfor =~ /\.pm$/) { $lookingfor =~ s![:/]!::!g; $lookingfor =~ s/\.pm$//; } my ($filename, $line,@mods); my $level=0; while (1) { (undef, $filename, $line) = caller($level); last unless $filename =~ /^\(eval/; $level++; } my $modfile = $filename; for my $i(@INC) { $modfile =~ s!$i!!; } if ($modfile =~ /\.pm$/) { $modfile =~ s![:/]!::!g; $modfile =~ s/\.pm$//; } push @{$main::mods}, $modfile unless $main::ismod{$modfile}++; push @{ $main::files->{$modfile} }, $lookingfor; # print "$lookingfor required at line $line of [$modfile] $filename\n"; }; 1;