X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FModule%2FMetadata.pm;h=8a1f4396f9b0d235eea8e06a11f17f4901a3ad70;hb=ca33f3bdaed855f973142d952c708d8792d56045;hp=2016967d09a8dfc91503443c8db543deff9b3bc5;hpb=38b7ba308a07e8889ea6703b261d8e0e3161df54;p=p5sagit%2FModule-Metadata.git diff --git a/lib/Module/Metadata.pm b/lib/Module/Metadata.pm index 2016967..8a1f439 100644 --- a/lib/Module/Metadata.pm +++ b/lib/Module/Metadata.pm @@ -11,7 +11,7 @@ package Module::Metadata; use strict; use vars qw($VERSION); -$VERSION = '1.000006'; +$VERSION = '1.000007'; $VERSION = eval $VERSION; use File::Spec; @@ -160,6 +160,38 @@ sub new_from_module { return \%result; }; + sub provides { + my $class = shift; + + die "provides() requires key/value pairs \n" if @_ % 2; + my %args = @_; + + die "provides() takes only one of 'dir' or 'files'\n" + if $args{dir} && $args{files}; + + $args{prefix} = 'lib' unless defined $args{prefix}; + + my $p; + if ( $args{dir} ) { + $p = $class->package_versions_from_directory($args{dir}); + } + else { + die "provides() requires 'files' to be an array reference\n" + unless ref $args{files} eq 'ARRAY'; + $p = $class->package_versions_from_directory($args{files}); + } + + # Now, fix up files with prefix + if ( length $args{prefix} ) { # check in case disabled with q{} + $args{prefix} =~ s{/$}{}; + for my $v ( values %$p ) { + $v->{file} = "$args{prefix}/$v->{file}"; + } + } + + return $p + } + sub package_versions_from_directory { my ( $class, $dir, $files ) = @_; @@ -673,9 +705,8 @@ Module::Metadata - Gather package and POD information from perl module files my $info = Module::Metadata->new_from_file( $file ); my $version = $info->version; - # information about a directory full of .pm files - my $provides = - Module::Metadata->package_versions_from_directory('lib'); + # CPAN META 'provides' field for .pm files in a directory + my $provides = Module::Metadata->provides(dir => 'lib'); =head1 DESCRIPTION @@ -728,6 +759,45 @@ optional parameter, otherwise @INC is searched. Can be called as either an object or a class method. +=item C<< provides( %options ) >> + +This is a convenience wrapper around C +to generate a CPAN META C data structure. It takes key/value +pairs. Valid option keys include: + +=over + +=item dir + +Directory to search recursively for F<.pm> files. May not be specified with +C. + +=item files + +Array reference of files to examine. May not be specified with 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 +root. + +=back + +For example, given C of 'lib' and C of 'lib', the return value +is a hashref of the form: + + { + 'Package::Name' => { + version => '0.123', + file => 'lib/Package/Name.pm' + }, + 'OtherPackage::Name' => ... + } + =item C<< package_versions_from_directory($dir, \@files?) >> Scans C<$dir> for .pm files (unless C<@files> is given, in which case looks @@ -742,6 +812,14 @@ returning a hashref of the form: 'OtherPackage::Name' => ... } +The C and C
packages are always omitted, as are any "private" +packages that have leading underscores in the namespace (e.g. +C) + +Note that the file path is relative to C<$dir> if that is specified. +This B be used directly for CPAN META C. See +the C method instead. + =item C<< log_info (internal) >> Used internally to perform logging; imported from Log::Contextual if