diff --git a/bin/cpan-outdated b/bin/cpan-outdated
index f9954af..a198a87 100644
--- a/bin/cpan-outdated
+++ b/bin/cpan-outdated
@@ -4,6 +4,7 @@ use warnings;
use Getopt::Long;
use Pod::Usage;
use ExtUtils::MakeMaker;
+use File::Find;
use File::Temp;
use File::Spec;
use Config;
@@ -57,6 +58,24 @@ sub main {
while (my $line = <$fh>) {
last if $line eq "\n";
}
+
+ # Find the list of installed modules.
+ my %paths;
+ for my $dir (@libpath) {
+ next if $dir eq '.';
+ my $len = length $dir;
+ find {
+ wanted => sub {
+ return unless substr $_, -3, 3, '' eq '.pm';
+ return unless -f _;
+ substr $_, 0, 1 + $len, '';
+ s{[\\/]}{::}g;
+ push @{ $paths{$_} }, $File::Find::name;
+ },
+ no_chdir => 1
+ }, $dir;
+ }
+
# body part
my %seen;
my %dist_latest_version;
@@ -64,12 +83,10 @@ sub main {
my ($pkg, $version, $dist) = split /\s+/, $line;
next if $version eq 'undef';
next if $dist =~ m{/perl-[0-9._]+\.tar\.(gz|bz2)$};
- (my $file = $pkg) =~ s!::!/!g;
- $file = "${file}.pm";
- SCAN_INC: for my $dir (@libpath) {
- my $path = "$dir/$file";
- next SCAN_INC unless -f $path;
+ next unless exists $paths{$pkg};
+ my @paths = @{ $paths{$pkg} };
+ SCAN_INC: for my $path (@paths) {
# ignore old distribution.
# This is a heuristic approach. It is not a strict.
# If you want a strict check, cpan-outdated looks 02packages.details.txt.gz twice.
@@ -80,6 +97,7 @@ sub main {
# This strategy works well for now.
# ref
https://github.com/tokuhirom/cpan-outdated/issues#issue/4
my $info = CPAN::DistnameInfo->new($dist);
+ next unless $info;
if (my $latest = $dist_latest_version{$info->dist}) {
# $info->version < $latest
if (compare_version($info->version, $latest)) {
@@ -90,7 +108,7 @@ sub main {
$dist_latest_version{$info->dist} = $info->version;
my $inst_version = parse_version($path);
- $inst_version =~ s/\s+//; # workaround for Attribute::Params::Validate
+ $inst_version =~ s/\s+//; # workaround for Attribute::Params::Validate
next if $inst_version eq 'undef';
if (compare_version($inst_version, $version)) {
next if $seen{$dist}++;