I have used Module::Metadata to get a Perl module's name from its location, but it doesn't work for some modules (like DBIx::Class::Carp, DateTimePP) where the package information is missing.
use strict;
use warnings;
# Modules corresponding to Perl module information
use File::Find;
use Module::Metadata;
my @files = ();
find({
    wanted => sub {
      push @files, $File::Find::fullname
          if (defined $File::Find::fullname
        && (-f $File::Find::fullname && /\.pm$/));
    },
    follow      => 1,
    follow_skip => 2,
  },
  @INC
);
my ($file_path, $module_name, $info) = ("", "", "");
my %modules = ();
foreach $file_path (@files) {    # loop through all the perl module (.pms) found
  $info        = Module::Metadata->new_from_file($file_path);
  $module_name = $info->name;
  if (!$module_name) {
    print $file_path . "\n";
  }
  $modules{$file_path} = $module_name;
}
 
     
    