Fix provides() when passed a list of files
[p5sagit/Module-Metadata.git] / lib / Module / Metadata.pm
index d11c8c0..05f4cc1 100644 (file)
@@ -198,6 +198,9 @@ sub new_from_module {
     croak "provides() takes only one of 'dir' or 'files'\n"
       if $args{dir} && $args{files};
 
+    croak "provides() takes only one of 'files' or 'prefix'\n"
+      if $args{files} && $args{prefix};
+
     croak "provides() requires a 'version' argument"
       unless defined $args{version};
 
@@ -213,11 +216,11 @@ 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});
+      $p = $class->package_versions_from_directory('', $args{files});
     }
 
     # Now, fix up files with prefix
-    if ( length $args{prefix} ) { # check in case disabled with q{}
+    if ( not $args{files} and length $args{prefix} ) { # check in case disabled with q{}
       $args{prefix} =~ s{/$}{};
       for my $v ( values %$p ) {
         $v->{file} = "$args{prefix}/$v->{file}";
@@ -908,15 +911,16 @@ C<files>.
 
 =item files
 
-Array reference of files to examine.  May not be specified with C<dir>.
+Array reference of files to examine.  May not be combined with C<dir> or
+C<prefix>.
 
 =item prefix
 
 String to prepend to the C<file> field of the resulting output. This defaults
 to F<lib>, which is the common case for most CPAN distributions with their
 F<.pm> files in F<lib>.  This option ensures the META information has the
-correct relative path even when the C<dir> or C<files> arguments are
-absolute or have relative paths from a location other than the distribution
+correct relative path even when the C<dir> argument is
+absolute or has relative paths from a location other than the distribution
 root.
 
 =back