Hello,
there is a bug in Module::ScanDeps which causes {type} to be set to 'data'
instead of 'autoload' in some cases - and changing if the same file is scanned
more than once.
I attach a patch to fix this and a testfile. With the patch *.bs files are
always reported as 'autoload' - is that correct?
Also I would like to ask if adding the test is considered appropriate. It takes
some time to run and maybe someone knows a better place in the testsuite to add
a check for the correctness of {type} entries. (To be exact, the attached test
does not check for correctness but for identity of results of 2 scan_deps calls.)
Cheers, Christoph
To reproduce the issue without the testing environment you can run the
following:
use strict;
use warnings;
use Module::ScanDeps;
use Test::More q/no_plan/;
open my $fh, '>', 'test.pl' or die "can't open file : $!\n";
print $fh "use AutoLoader;\n";
close $fh or die "can't close file : $!";
my $hash_ref = scan_deps(
files => [ 'test.pl' ],
recurse => 1,
) ;
normalize( $hash_ref );
for my $run(0..2){
my $c_hash_ref = scan_deps(
files => [ 'test.pl' ],
recurse => 1,
);
normalize( $c_hash_ref );
is_deeply($c_hash_ref, $hash_ref, "compare structures");
$hash_ref = $c_hash_ref;
}
# sort lists to make them comparable by is_deeply
sub normalize{
my $href = shift;
foreach my $entry(values %$href){
$entry->{$_} = [sort @{$entry->{$_}||=[]}] for (qw/uses used_by/);
}
}
--- C:\DOKUME~1\chris\LOKALE~1\Temp\ScanDeps.pm-revBASE.svn003.tmp.pm Di Jun
30 17:54:46 2009
+++ C:\Dokumente und Einstellungen\chris\Desktop\MSD\lib\Module\ScanDeps.pm
Di Jun 30 17:53:45 2009
@@ -518,8 +518,7 @@
next;
}
- $type = 'module';
- $type = 'data' unless $input_file =~ /\.p[mh]$/io;
+ $type = _gettype($input_file);
$path = $input_file;
if ($type eq 'module') {
# necessary because add_deps does the search for shared libraries
and such
@@ -925,8 +924,7 @@
next;
}
- my $type = 'module';
- $type = 'data' unless $file =~ /\.p[mh]$/i;
+ my $type = _gettype($file);
_add_info( rv => $rv, module => $module,
file => $file, used_by => $used_by,
type => $type );
@@ -940,9 +938,10 @@
my $ext = lc($1) if $_->{name} =~ /(\.[^.]+)$/;
next if $ext eq lc(lib_ext());
my $type = 'shared' if $ext eq lc(dl_ext());
- $type = 'autoload' if $ext eq '.ix' or $ext eq '.al';
+ $type = 'autoload' if $ext eq '.ix'
+ or $ext eq '.al'
+ or $ext eq '.bs';
$type ||= 'data';
-
_add_info( rv => $rv, module =>
"auto/$path/$_->{name}",
file => $_->{file}, used_by => $module,
type => $type );
#!/usr/bin/perl
use strict;
use warnings;
use lib 't';
use Test::More qw(no_plan); # no_plan because the number of objects
# in the dependency tree (and hence the
# number of tests) can change
use Utils;
BEGIN { use_ok( 'Module::ScanDeps' ); }
# scanning dependencies should always give identical results
# rev 1009 has a bug in handling {type}:
# *.bs files sometimes show up as 'data' sometimes as 'autoload'
#
# content of t/data/type-bug.pl:
# use AutoLoader;
my $file = 't/data/type-bug.pl';
my $rv = scan_deps($file);
my $rv2 = scan_deps($file);
compare_scandeps_rvs($rv,$rv2,[$file]);
__END__