Created
June 14, 2012 07:20
-
-
Save sng2c/2928677 to your computer and use it in GitHub Desktop.
module dependency checker for cpanm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use File::Find; | |
use Module::Which; | |
use Module::ExtractUse; | |
my %depend; | |
finddepth({wanted=>\&wanted,follow_fast=>1} ,@ARGV); | |
print join "\n",keys %depend; | |
sub wanted{ | |
my $dir = $File::Find::dir; | |
my $name = $File::Find::fullname; | |
my $n = $File::Find::name; | |
return unless($name=~/\.pl$/ || $name=~/\.pm$/); | |
#return unless( $name=~/\.pm$/); | |
finddepend($name,$n); | |
} | |
sub finddepend{ | |
my $name = shift; | |
my $n = shift; | |
print "[$n]\n"; | |
#open my $file, '<' ,$name; | |
#local($/); | |
#undef($/); | |
#my $l = <$file>; | |
#close($file); | |
#my @uses = ($l =~ /use ([A-Z]\S+).*;/g); | |
my $p = Module::ExtractUse->new; | |
$p->extract_use($name); | |
my @uses = $p->array; | |
#print "@uses\n"; | |
my $info = which(@uses,{verbose =>1}); | |
while( my ($mod,$info) = each %$info ){ | |
if( !defined($info->{path}) ){ | |
$depend{$mod}=1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment