Subject: | provides() doesn't work with 'files' arg |
I was looking at the code and noticed that when provides() doesn't have a 'dir' arg it assumes 'files', but when it delegates to package_versions_from_directory() it doesn't pass the necessary $dir arg, so it errors:
Module::Metadata->provides(version => 2, files => ["lib/Simple.pm"])
Can't stat ARRAY(0x1325c68): No such file or directory
I confirmed with a test case (patch attached).
Since the dir arg (which provides() doesn't know) is used in abs2rel() I'm not sure if '.' is a sensible default or not... I haven't really thought through the use cases. I did have to pass a 'prefix' in the test case to make it make sense, but again I haven't really thought through the use cases, I just knew the method didn't work as it was.
Adjust the patch or refine the docs or whatever as you see fit.
Subject: | provides-files-test.patch |
diff --git a/lib/Module/Metadata.pm b/lib/Module/Metadata.pm
index d11c8c0..077fbdc 100644
--- a/lib/Module/Metadata.pm
+++ b/lib/Module/Metadata.pm
@@ -213,7 +213,9 @@ sub new_from_module {
else {
croak "provides() requires 'files' to be an array reference\n"
unless ref $args{files} eq 'ARRAY';
- $p = $class->package_versions_from_directory($args{files});
+ # The $dir arg won't be used for find() but will be used for abs2rel().
+ # FIXME: What should it be?
+ $p = $class->package_versions_from_directory('.', $args{files});
}
# Now, fix up files with prefix
diff --git a/t/metadata.t b/t/metadata.t
index 38649bd..32ce35a 100644
--- a/t/metadata.t
+++ b/t/metadata.t
@@ -260,7 +260,7 @@ package Simple-Edward;
);
my %pkg_names = reverse @pkg_names;
-plan tests => 63 + (2 * keys( %modules )) + (2 * keys( %pkg_names ));
+plan tests => 64 + (2 * keys( %modules )) + (2 * keys( %pkg_names ));
require_ok('Module::Metadata');
@@ -712,6 +712,23 @@ is_deeply( $got_pvfd, $exp_pvfd, "package_version_from_directory()" )
or diag explain $got_provides;
}
+{
+ my $got_provides = Module::Metadata->provides(files => ['lib/Simple.pm'], prefix => '', version => 1.4);
+ my $exp_provides = {
+ 'Simple' => {
+ 'file' => 'lib/Simple.pm',
+ 'version' => '0.01'
+ },
+ 'Simple::Ex' => {
+ 'file' => 'lib/Simple.pm',
+ 'version' => '0.02'
+ }
+ };
+
+ is_deeply( $got_provides, $exp_provides, "provides(file => [...])" )
+ or diag explain $got_provides;
+}
+
# Check package_versions_from_directory with regard to case-sensitivity
{
$dist->change_file( 'lib/Simple.pm', <<'---' );