Created
February 4, 2016 01:17
-
-
Save masartz/a0cc63e6935b274f9867 to your computer and use it in GitHub Desktop.
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/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