From: David Golden Date: Wed, 8 Feb 2012 16:41:58 +0000 (-0500) Subject: add required 'version' arg to provides() X-Git-Tag: release_1.0.9~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c06d018717d6870aa177e0593f2220bcb1a130be;p=p5sagit%2FModule-Metadata.git add required 'version' arg to provides() --- diff --git a/Changes b/Changes index 878ebb8..ac7ff08 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,6 @@ + - API of 'provides' changed to require a 'version' argument to future + proof the function against CPAN Meta Spec changes + 1.0.8 2012-02-07 22:30:00 - Adds 'provides' method to generate a CPAN META provides data structure correctly; use of package_versions_from_directory is discouraged (DAGOLDEN) diff --git a/lib/Module/Metadata.pm b/lib/Module/Metadata.pm index 52394a3..189fbf9 100644 --- a/lib/Module/Metadata.pm +++ b/lib/Module/Metadata.pm @@ -169,6 +169,12 @@ sub new_from_module { die "provides() takes only one of 'dir' or 'files'\n" if $args{dir} && $args{files}; + die "provides() requires a 'version' argument" + unless defined $args{version}; + + die "provides() does not support version '$args{version}' metadata" + unless grep { $args{version} eq $_ } qw/1.4 2/; + $args{prefix} = 'lib' unless defined $args{prefix}; my $p; @@ -706,7 +712,9 @@ Module::Metadata - Gather package and POD information from perl module files my $version = $info->version; # CPAN META 'provides' field for .pm files in a directory - my $provides = Module::Metadata->provides(dir => 'lib'); + my $provides = Module::Metadata->provides( + dir => 'lib', version => 2 + ); =head1 DESCRIPTION @@ -767,6 +775,16 @@ pairs. Valid option keys include: =over +=item version B<(required)> + +Specifies which version of the L should be used as +the format of the C output. Currently only '1.4' and '2' +are supported (and their format is identical). This may change in +the future as the definition of C changes. + +The C option is required. If it is omitted or if +an unsupported version is given, then C will throw an error. + =item dir Directory to search recursively for F<.pm> files. May not be specified with diff --git a/t/metadata.t b/t/metadata.t index b93cefb..ab9c8c4 100644 --- a/t/metadata.t +++ b/t/metadata.t @@ -550,7 +550,7 @@ is_deeply( $got_pvfd, $exp_pvfd, "package_version_from_directory()" ) or diag explain $got_pvfd; { - my $got_provides = Module::Metadata->provides(dir => 'lib'); + my $got_provides = Module::Metadata->provides(dir => 'lib', version => 2); my $exp_provides = { 'Simple' => { 'file' => 'lib/Simple.pm', @@ -567,7 +567,7 @@ is_deeply( $got_pvfd, $exp_pvfd, "package_version_from_directory()" ) } { - my $got_provides = Module::Metadata->provides(dir => 'lib', prefix => 'other'); + my $got_provides = Module::Metadata->provides(dir => 'lib', prefix => 'other', version => 1.4); my $exp_provides = { 'Simple' => { 'file' => 'other/Simple.pm',