If you're trying to find out what modules your program is using, then the following piece of magic may suffice:
END {
foreach my $file (sort keys %INC) {
my $module = $file ;
my $located = $INC{$file} ;
$module =~ s|\.pm$|| ;
$module =~ s|[/\\]|::|g ;
my $version ;
{ no strict 'refs' ; $version = ${$module.'::VERSION'} || '??' ; }
+ ;
print STDERR "$module v$version $located\n" ;
} ;
} ;
if inserted at the start of your program, just before it ends it will print to STDERR all the module file names it has seen
require and/or
use for. Which may give you a fighting chance of constructing a suitable install package.
Mind you, this will miss any require operations which your test run does not actually execute... I cannot imagine that this will be a problem, but it's tricky to guarantee. If that worries you, you can try:
END {
my %myINC = () ;
foreach my $file (keys %INC) {
my $module = $file ;
$module =~ s|\.pm$|| ;
$module =~ s|[/\\]|::|g ;
$myINC{$module} = $INC{$file} ;
} ;
foreach my $module (sort keys %myINC) {
my $located = $myINC{$module} ;
my $version ;
{ no strict 'refs' ; $version = ${$module.'::VERSION'} || '??' ; }
+ ;
print STDERR "$module v$version $located\n" ;
open my $FH, "<", $located or die "failed to open $located: $!"
+;
while (<$FH>) {
if ((m/^(?:\s+|[^#;];\s*)*?require\s+([A-Za-z]\w+(?:::\w+)*)\b/)
&& !exists($myINC{$1
+})) {
printf STDERR " %5d: %s", $., $_ ;
} ;
} ;
} ;
} ;
which has a stab at scanning all the
required files, looking for
require statements for modules (ignores version numbers) that refer to modules that are not already known.
NB: this comes without warranty of any kind, in particular no warranty of fitness for any purpose whatsoever; and if you use this you acknowledge that such exclusion of warranty is entirely reasonable, given the level of the fee :-)