Skip to content

Instantly share code, notes, and snippets.

@masartz
Created February 4, 2016 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masartz/a0cc63e6935b274f9867 to your computer and use it in GitHub Desktop.
Save masartz/a0cc63e6935b274f9867 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use File::Find;
use File::Slurp;
use Data::Dumper;
use List::MoreUtils;
my $path = $ARGV[0];
my @used_module;
File::Find::find({
wanted => sub {
my $path = $File::Find::name;
if ($path =~ qr{(.*\.(pl|pm))$}xms) {
push @used_module , _investigate_file( $path );
}
},
preprocess => sub {
grep { $_ ne '.git' } @_;
},
}, $path);
@used_module = List::MoreUtils::uniq( @used_module );
print Dumper \@used_module;
exit;
sub _investigate_file{
my $path = shift;
my @lines = File::Slurp::read_file( $path );
my @each_used_module;
for my $row (@lines){
if( $row =~ /(use|require) ([\w|::]+);$/ ){
my $used_file = $2;
chomp $used_file;
push @each_used_module , $used_file;
}
}
return @each_used_module;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment