From: Karen Etheridge Date: Sun, 8 Dec 2013 05:35:20 +0000 (-0800) Subject: Fix provides() when passed a list of files X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Ftopic%2Ffix_provides_files;p=p5sagit%2FModule-Metadata.git Fix provides() when passed a list of files provides(files => [ ... ]) never worked before, because package_versions_from_directory() must always be passed a directory name, for use in abs2rel when resolving found files. Plus the ability to combine the 'files' and 'prefix' options has been removed, as it is paradoxical anyway - we cannot know what bits of the path would need to be swapped out for the prefix. --- diff --git a/Changes b/Changes index e588266..6009064 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ Release history for Module-Metadata - new is_indexable() object method (ether, RT#84357) - removed cruft in test infrastructure left behind from separation from Module::Build (ether) + - fixed broken provides() where a list of files is passed (ether) 1.000019 2013-10-06 - warnings now disabled inside during the evaluation of generated version diff --git a/lib/Module/Metadata.pm b/lib/Module/Metadata.pm index d11c8c0..05f4cc1 100644 --- a/lib/Module/Metadata.pm +++ b/lib/Module/Metadata.pm @@ -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. =item files -Array reference of files to examine. May not be specified with C. +Array reference of files to examine. May not be combined with C or +C. =item prefix String to prepend to the C field of the resulting output. This defaults to F, which is the common case for most CPAN distributions with their F<.pm> files in F. This option ensures the META information has the -correct relative path even when the C or C arguments are -absolute or have relative paths from a location other than the distribution +correct relative path even when the C argument is +absolute or has relative paths from a location other than the distribution root. =back diff --git a/t/metadata.t b/t/metadata.t index 55d06c6..3ac9c8e 100644 --- a/t/metadata.t +++ b/t/metadata.t @@ -262,7 +262,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'); @@ -743,7 +743,11 @@ Simple Simon } }; - is_deeply( $got_provides, $exp_provides, "provides()" ) + is_deeply( $got_provides, $exp_provides, "provides(dir => ...)" ) + or diag explain $got_provides; + + $got_provides = Module::Metadata->provides(files => ['lib/Simple.pm'], version => 2); + is_deeply( $got_provides, $exp_provides, "provides(files => ...)" ) or diag explain $got_provides; } @@ -760,7 +764,7 @@ Simple Simon } }; - is_deeply( $got_provides, $exp_provides, "provides()" ) + is_deeply( $got_provides, $exp_provides, "provides(dir => ..., prefix => ...)" ) or diag explain $got_provides; } }