2 package Module::Install::Metadata;
5 use Module::Install::Base;
7 use vars qw{$VERSION $ISCORE @ISA};
11 @ISA = qw{Module::Install::Base};
34 my @resource_keys = qw{
41 sub Meta_ScalarKeys { @scalar_keys }
42 sub Meta_TupleKeys { @tuple_keys }
43 sub Meta_ResourceKeys { @resource_keys }
45 foreach my $key ( @scalar_keys ) {
48 return $self->{values}{$key} if defined wantarray and !@_;
49 $self->{values}{$key} = shift;
54 foreach my $key ( @resource_keys ) {
58 return () unless $self->{values}{resources};
59 return map { $_->[1] }
60 grep { $_->[0] eq $key }
61 @{ $self->{values}{resources} };
63 return $self->{values}{resources}{$key} unless @_;
64 my $uri = shift or die(
65 "Did not provide a value to $key()"
67 $self->resources( $key => $uri );
75 my $module = shift or last;
76 my $version = shift || 0;
77 push @{ $self->{values}{requires} }, [ $module, $version ];
79 $self->{values}{requires};
85 my $module = shift or last;
86 my $version = shift || 0;
87 push @{ $self->{values}{build_requires} }, [ $module, $version ];
89 $self->{values}{build_requires};
92 sub configure_requires {
95 my $module = shift or last;
96 my $version = shift || 0;
97 push @{ $self->{values}{configure_requires} }, [ $module, $version ];
99 $self->{values}{configure_requires};
105 my $module = shift or last;
106 my $version = shift || 0;
107 push @{ $self->{values}{recommends} }, [ $module, $version ];
109 $self->{values}{recommends};
115 my $module = shift or last;
116 my $version = shift || 0;
117 push @{ $self->{values}{bundles} }, [ $module, $version ];
119 $self->{values}{bundles};
123 my %lc_resource = map { $_ => 1 } qw{
133 my $name = shift or last;
134 my $value = shift or next;
135 if ( $name eq lc $name and ! $lc_resource{$name} ) {
136 die("Unsupported reserved lowercase resource '$name'");
138 $self->{values}{resources} ||= [];
139 push @{ $self->{values}{resources} }, [ $name, $value ];
141 $self->{values}{resources};
144 # Aliases for build_requires that will have alternative
145 # meanings in some future version of META.yml.
146 sub test_requires { shift->build_requires(@_) }
147 sub install_requires { shift->build_requires(@_) }
149 # Aliases for installdirs options
150 sub install_as_core { $_[0]->installdirs('perl') }
151 sub install_as_cpan { $_[0]->installdirs('site') }
152 sub install_as_site { $_[0]->installdirs('site') }
153 sub install_as_vendor { $_[0]->installdirs('vendor') }
157 return $self->{values}{sign} if defined wantarray and ! @_;
158 $self->{values}{sign} = ( @_ ? $_[0] : 1 );
165 warn "You MUST provide an explicit true/false value to dynamic_config\n";
168 $self->{values}{dynamic_config} = $_[0] ? 1 : 0;
174 return $self->{values}{perl_version} unless @_;
175 my $version = shift or die(
176 "Did not provide a value to perl_version()"
179 # Convert triple-part versions (eg, 5.6.1 or 5.8.9) to
180 # numbers (eg, 5.006001 or 5.008009).
182 $version =~ s/^(\d+)\.(\d+)\.(\d+)$/sprintf("%d.%03d%03d",$1,$2,$3)/e;
184 $version =~ s/_.+$//;
185 $version = $version + 0; # Numify
186 unless ( $version >= 5.005 ) {
187 die "Module::Install only supports 5.005 or newer (use ExtUtils::MakeMaker)\n";
189 $self->{values}{perl_version} = $version;
195 return $self->{values}{license} unless @_;
196 my $license = shift or die(
197 'Did not provide a value to license()'
199 $self->{values}{license} = $license;
201 # Automatically fill in license URLs
202 if ( $license eq 'perl' ) {
203 $self->resources( license => 'http://dev.perl.org/licenses/' );
210 my ( $self, $file ) = @_;
212 unless ( defined($file) ) {
213 my $name = $self->name or die(
214 "all_from called with no args without setting name() first"
216 $file = join('/', 'lib', split(/-/, $name)) . '.pm';
217 $file =~ s{.*/}{} unless -e $file;
218 unless ( -e $file ) {
219 die("all_from cannot find $file from $name");
222 unless ( -f $file ) {
223 die("The path '$file' does not exist, or is not a file");
226 # Some methods pull from POD instead of code.
227 # If there is a matching .pod, use that instead
229 $pod =~ s/\.pm$/.pod/i;
230 $pod = $file unless -e $pod;
232 # Pull the different values
233 $self->name_from($file) unless $self->name;
234 $self->version_from($file) unless $self->version;
235 $self->perl_version_from($file) unless $self->perl_version;
236 $self->author_from($pod) unless $self->author;
237 $self->license_from($pod) unless $self->license;
238 $self->abstract_from($pod) unless $self->abstract;
245 my $provides = ( $self->{values}{provides} ||= {} );
246 %$provides = (%$provides, @_) if @_;
252 return $self unless $self->is_admin;
253 unless (-e 'MANIFEST') {
254 warn "Cannot deduce auto_provides without a MANIFEST, skipping\n";
257 # Avoid spurious warnings as we are not checking manifest here.
258 local $SIG{__WARN__} = sub {1};
259 require ExtUtils::Manifest;
260 local *ExtUtils::Manifest::manicheck = sub { return };
262 require Module::Build;
263 my $build = Module::Build->new(
264 dist_name => $self->name,
265 dist_version => $self->version,
266 license => $self->license,
268 $self->provides( %{ $build->find_dist_packages || {} } );
274 my $features = ( $self->{values}{features} ||= [] );
277 if ( @_ == 1 and ref( $_[0] ) ) {
278 # The user used ->feature like ->features by passing in the second
279 # argument as a reference. Accomodate for that.
289 ref($_) ? ( ref($_) eq 'HASH' ) ? %$_ : @$_ : $_
299 while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) {
300 $self->feature( $name, @$mods );
302 return $self->{values}{features}
303 ? @{ $self->{values}{features} }
310 push @{ $self->{values}{no_index}{$type} }, @_ if $type;
311 return $self->{values}{no_index};
316 $self->include_deps( 'YAML::Tiny', 0 );
319 my $data = YAML::Tiny::LoadFile('META.yml');
321 # Call methods explicitly in case user has already set some values.
322 while ( my ( $key, $value ) = each %$data ) {
323 next unless $self->can($key);
324 if ( ref $value eq 'HASH' ) {
325 while ( my ( $module, $version ) = each %$value ) {
326 $self->can($key)->($self, $module => $version );
329 $self->can($key)->($self, $value);
337 return $self unless $self->is_admin;
338 $self->admin->write_meta;
343 require ExtUtils::MM_Unix;
344 my ( $self, $file ) = @_;
345 $self->version( ExtUtils::MM_Unix->parse_version($file) );
349 require ExtUtils::MM_Unix;
350 my ( $self, $file ) = @_;
353 { DISTNAME => $self->name },
355 )->parse_abstract($file)
359 # Add both distribution and module name
361 my ($self, $file) = @_;
363 Module::Install::_read($file) =~ m/
370 my ($name, $module_name) = ($1, $1);
373 unless ( $self->module_name ) {
374 $self->module_name($module_name);
377 die("Cannot determine name from $file\n");
381 sub perl_version_from {
384 Module::Install::_read($_[0]) =~ m/
392 my $perl_version = $1;
393 $perl_version =~ s{_}{}g;
394 $self->perl_version($perl_version);
396 warn "Cannot determine perl version info from $_[0]\n";
403 my $content = Module::Install::_read($_[0]);
405 =head \d \s+ (?:authors?)\b \s*
408 =head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s*
409 .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s*
412 my $author = $1 || $2;
413 $author =~ s{E<lt>}{<}g;
414 $author =~ s{E<gt>}{>}g;
415 $self->author($author);
417 warn "Cannot determine author info from $_[0]\n";
424 Module::Install::_read($_[0]) =~ m/
427 (?:licen[cs]e|licensing|copyright|legal)\b
433 my $license_text = $1;
435 'under the same (?:terms|license) as perl itself' => 'perl', 1,
436 'GNU general public license' => 'gpl', 1,
437 'GNU public license' => 'gpl', 1,
438 'GNU lesser general public license' => 'lgpl', 1,
439 'GNU lesser public license' => 'lgpl', 1,
440 'GNU library general public license' => 'lgpl', 1,
441 'GNU library public license' => 'lgpl', 1,
442 'BSD license' => 'bsd', 1,
443 'Artistic license' => 'artistic', 1,
447 'Artistic' => 'artistic', 1,
449 'proprietary' => 'proprietary', 0,
451 while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) {
452 $pattern =~ s{\s+}{\\s+}g;
453 if ( $license_text =~ /\b$pattern\b/i ) {
454 if ( $osi and $license_text =~ /All rights reserved/i ) {
455 print "WARNING: 'All rights reserved' in copyright may invalidate Open Source license.\n";
457 $self->license($license);
463 warn "Cannot determine license info from $_[0]\n";
467 sub bugtracker_from {
469 my $content = Module::Install::_read($_[0]);
470 my @links = $content =~ m/L\<(http\:\/\/rt\.cpan\.org\/[^>]+)\>/g;
472 warn "Cannot determine bugtracker info from $_[0]\n";
476 warn "Found more than on rt.cpan.org link in $_[0]\n";
481 bugtracker( $links[0] );
487 my $args = $self->makemaker_args;
488 my $exe = $args->{EXE_FILES} ||= [];
492 } elsif ( -d 'script' and -f "script/$_" ) {
493 push @$exe, "script/$_";
495 die("Cannot find script '$_'");