2
package Module::Install::Metadata;
5
use Module::Install::Base;
7
use vars qw{$VERSION @ISA $ISCORE};
10
@ISA = qw{Module::Install::Base};
14
my @boolean_keys = qw{
39
my @resource_keys = qw{
50
sub Meta_BooleanKeys { @boolean_keys }
51
sub Meta_ScalarKeys { @scalar_keys }
52
sub Meta_TupleKeys { @tuple_keys }
53
sub Meta_ResourceKeys { @resource_keys }
54
sub Meta_ArrayKeys { @array_keys }
56
foreach my $key ( @boolean_keys ) {
59
if ( defined wantarray and not @_ ) {
60
return $self->{values}->{$key};
62
$self->{values}->{$key} = ( @_ ? $_[0] : 1 );
67
foreach my $key ( @scalar_keys ) {
70
return $self->{values}->{$key} if defined wantarray and !@_;
71
$self->{values}->{$key} = shift;
76
foreach my $key ( @array_keys ) {
79
return $self->{values}->{$key} if defined wantarray and !@_;
80
$self->{values}->{$key} ||= [];
81
push @{$self->{values}->{$key}}, @_;
86
foreach my $key ( @resource_keys ) {
90
return () unless $self->{values}->{resources};
91
return map { $_->[1] }
92
grep { $_->[0] eq $key }
93
@{ $self->{values}->{resources} };
95
return $self->{values}->{resources}->{$key} unless @_;
96
my $uri = shift or die(
97
"Did not provide a value to $key()"
99
$self->resources( $key => $uri );
104
foreach my $key ( grep { $_ ne "resources" } @tuple_keys) {
107
return $self->{values}->{$key} unless @_;
110
my $module = shift or last;
111
my $version = shift || 0;
112
push @added, [ $module, $version ];
114
push @{ $self->{values}->{$key} }, @added;
115
return map {@$_} @added;
120
my %lc_resource = map { $_ => 1 } qw{
130
my $name = shift or last;
131
my $value = shift or next;
132
if ( $name eq lc $name and ! $lc_resource{$name} ) {
133
die("Unsupported reserved lowercase resource '$name'");
135
$self->{values}->{resources} ||= [];
136
push @{ $self->{values}->{resources} }, [ $name, $value ];
138
$self->{values}->{resources};
141
# Aliases for build_requires that will have alternative
142
# meanings in some future version of META.yml.
143
sub test_requires { shift->build_requires(@_) }
144
sub install_requires { shift->build_requires(@_) }
146
# Aliases for installdirs options
147
sub install_as_core { $_[0]->installdirs('perl') }
148
sub install_as_cpan { $_[0]->installdirs('site') }
149
sub install_as_site { $_[0]->installdirs('site') }
150
sub install_as_vendor { $_[0]->installdirs('vendor') }
155
warn "You MUST provide an explicit true/false value to dynamic_config\n";
158
$self->{values}->{dynamic_config} = $_[0] ? 1 : 0;
164
return $self->{values}->{perl_version} unless @_;
165
my $version = shift or die(
166
"Did not provide a value to perl_version()"
169
# Normalize the version
170
$version = $self->_perl_version($version);
172
# We don't support the reall old versions
173
unless ( $version >= 5.005 ) {
174
die "Module::Install only supports 5.005 or newer (use ExtUtils::MakeMaker)\n";
177
$self->{values}->{perl_version} = $version;
182
perl => 'http://dev.perl.org/licenses/',
183
apache => 'http://apache.org/licenses/LICENSE-2.0',
184
artistic => 'http://opensource.org/licenses/artistic-license.php',
185
artistic_2 => 'http://opensource.org/licenses/artistic-license-2.0.php',
186
lgpl => 'http://opensource.org/licenses/lgpl-license.php',
187
lgpl2 => 'http://opensource.org/licenses/lgpl-2.1.php',
188
lgpl3 => 'http://opensource.org/licenses/lgpl-3.0.html',
189
bsd => 'http://opensource.org/licenses/bsd-license.php',
190
gpl => 'http://opensource.org/licenses/gpl-license.php',
191
gpl2 => 'http://opensource.org/licenses/gpl-2.0.php',
192
gpl3 => 'http://opensource.org/licenses/gpl-3.0.html',
193
mit => 'http://opensource.org/licenses/mit-license.php',
194
mozilla => 'http://opensource.org/licenses/mozilla1.1.php',
195
open_source => undef,
196
unrestricted => undef,
197
restrictive => undef,
203
return $self->{values}->{license} unless @_;
204
my $license = shift or die(
205
'Did not provide a value to license()'
207
$self->{values}->{license} = $license;
209
# Automatically fill in license URLs
210
if ( $license_urls{$license} ) {
211
$self->resources( license => $license_urls{$license} );
218
my ( $self, $file ) = @_;
220
unless ( defined($file) ) {
221
my $name = $self->name or die(
222
"all_from called with no args without setting name() first"
224
$file = join('/', 'lib', split(/-/, $name)) . '.pm';
225
$file =~ s{.*/}{} unless -e $file;
226
unless ( -e $file ) {
227
die("all_from cannot find $file from $name");
230
unless ( -f $file ) {
231
die("The path '$file' does not exist, or is not a file");
234
# Some methods pull from POD instead of code.
235
# If there is a matching .pod, use that instead
237
$pod =~ s/\.pm$/.pod/i;
238
$pod = $file unless -e $pod;
240
# Pull the different values
241
$self->name_from($file) unless $self->name;
242
$self->version_from($file) unless $self->version;
243
$self->perl_version_from($file) unless $self->perl_version;
244
$self->author_from($pod) unless $self->author;
245
$self->license_from($pod) unless $self->license;
246
$self->abstract_from($pod) unless $self->abstract;
253
my $provides = ( $self->{values}->{provides} ||= {} );
254
%$provides = (%$provides, @_) if @_;
260
return $self unless $self->is_admin;
261
unless (-e 'MANIFEST') {
262
warn "Cannot deduce auto_provides without a MANIFEST, skipping\n";
265
# Avoid spurious warnings as we are not checking manifest here.
266
local $SIG{__WARN__} = sub {1};
267
require ExtUtils::Manifest;
268
local *ExtUtils::Manifest::manicheck = sub { return };
270
require Module::Build;
271
my $build = Module::Build->new(
272
dist_name => $self->name,
273
dist_version => $self->version,
274
license => $self->license,
276
$self->provides( %{ $build->find_dist_packages || {} } );
282
my $features = ( $self->{values}->{features} ||= [] );
285
if ( @_ == 1 and ref( $_[0] ) ) {
286
# The user used ->feature like ->features by passing in the second
287
# argument as a reference. Accomodate for that.
297
ref($_) ? ( ref($_) eq 'HASH' ) ? %$_ : @$_ : $_
307
while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) {
308
$self->feature( $name, @$mods );
310
return $self->{values}->{features}
311
? @{ $self->{values}->{features} }
318
push @{ $self->{values}->{no_index}->{$type} }, @_ if $type;
319
return $self->{values}->{no_index};
324
$self->include_deps( 'YAML::Tiny', 0 );
327
my $data = YAML::Tiny::LoadFile('META.yml');
329
# Call methods explicitly in case user has already set some values.
330
while ( my ( $key, $value ) = each %$data ) {
331
next unless $self->can($key);
332
if ( ref $value eq 'HASH' ) {
333
while ( my ( $module, $version ) = each %$value ) {
334
$self->can($key)->($self, $module => $version );
337
$self->can($key)->($self, $value);
345
return $self unless $self->is_admin;
346
$self->admin->write_meta;
351
require ExtUtils::MM_Unix;
352
my ( $self, $file ) = @_;
353
$self->version( ExtUtils::MM_Unix->parse_version($file) );
357
require ExtUtils::MM_Unix;
358
my ( $self, $file ) = @_;
361
{ DISTNAME => $self->name },
363
)->parse_abstract($file)
367
# Add both distribution and module name
369
my ($self, $file) = @_;
371
Module::Install::_read($file) =~ m/
378
my ($name, $module_name) = ($1, $1);
381
unless ( $self->module_name ) {
382
$self->module_name($module_name);
385
die("Cannot determine name from $file\n");
389
sub perl_version_from {
392
Module::Install::_read($_[0]) =~ m/
400
my $perl_version = $1;
401
$perl_version =~ s{_}{}g;
402
$self->perl_version($perl_version);
404
warn "Cannot determine perl version info from $_[0]\n";
411
my $content = Module::Install::_read($_[0]);
413
=head \d \s+ (?:authors?)\b \s*
416
=head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s*
417
.*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s*
420
my $author = $1 || $2;
421
$author =~ s{E<lt>}{<}g;
422
$author =~ s{E<gt>}{>}g;
423
$self->author($author);
425
warn "Cannot determine author info from $_[0]\n";
432
Module::Install::_read($_[0]) =~ m/
435
(?:licen[cs]e|licensing|copyright|legal)\b
441
my $license_text = $1;
443
'under the same (?:terms|license) as perl itself' => 'perl', 1,
444
'GNU general public license' => 'gpl', 1,
445
'GNU public license' => 'gpl', 1,
446
'GNU lesser general public license' => 'lgpl', 1,
447
'GNU lesser public license' => 'lgpl', 1,
448
'GNU library general public license' => 'lgpl', 1,
449
'GNU library public license' => 'lgpl', 1,
450
'BSD license' => 'bsd', 1,
451
'Artistic license' => 'artistic', 1,
455
'Artistic' => 'artistic', 1,
457
'proprietary' => 'proprietary', 0,
459
while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) {
460
$pattern =~ s{\s+}{\\s+}g;
461
if ( $license_text =~ /\b$pattern\b/i ) {
462
$self->license($license);
468
warn "Cannot determine license info from $_[0]\n";
472
sub _extract_bugtracker {
473
my @links = $_[0] =~ m#L<(\Qhttp://rt.cpan.org/\E[^>]+)>#g;
480
sub bugtracker_from {
482
my $content = Module::Install::_read($_[0]);
483
my @links = _extract_bugtracker($content);
485
warn "Cannot determine bugtracker info from $_[0]\n";
489
warn "Found more than on rt.cpan.org link in $_[0]\n";
494
bugtracker( $links[0] );
500
my $content = Module::Install::_readperl($_[0]);
501
my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+([\d\.]+)/mg;
502
while ( @requires ) {
503
my $module = shift @requires;
504
my $version = shift @requires;
505
$self->requires( $module => $version );
509
# Convert triple-part versions (eg, 5.6.1 or 5.8.9) to
510
# numbers (eg, 5.006001 or 5.008009).
511
# Also, convert double-part versions (eg, 5.8)
514
$v =~ s/^([1-9])\.([1-9]\d?\d?)$/sprintf("%d.%03d",$1,$2)/e;
515
$v =~ s/^([1-9])\.([1-9]\d?\d?)\.(0|[1-9]\d?\d?)$/sprintf("%d.%03d%03d",$1,$2,$3 || 0)/e;
516
$v =~ s/(\.\d\d\d)000$/$1/;
519
$v = $v + 0; # Numify
528
######################################################################
532
die "WriteMyMeta has been deprecated";
538
# If there's no existing META.yml there is nothing we can do
539
return unless -f 'META.yml';
541
# We need YAML::Tiny to write the MYMETA.yml file
542
unless ( eval { require YAML::Tiny; 1; } ) {
546
# Merge the perl version into the dependencies
547
my $val = $self->Meta->{values};
548
my $perl = delete $val->{perl_version};
550
$val->{requires} ||= [];
551
my $requires = $val->{requires};
553
# Canonize to three-dot version after Perl 5.6
554
if ( $perl >= 5.006 ) {
555
$perl =~ s{^(\d+)\.(\d\d\d)(\d*)}{join('.', $1, int($2||0), int($3||0))}e
557
unshift @$requires, [ perl => $perl ];
560
# Load the advisory META.yml file
561
my @yaml = YAML::Tiny::LoadFile('META.yml');
564
# Overwrite the non-configure dependency hashs
565
delete $meta->{requires};
566
delete $meta->{build_requires};
567
delete $meta->{recommends};
568
if ( exists $val->{requires} ) {
569
$meta->{requires} = { map { @$_ } @{ $val->{requires} } };
571
if ( exists $val->{build_requires} ) {
572
$meta->{build_requires} = { map { @$_ } @{ $val->{build_requires} } };
575
# Save as the MYMETA.yml file
576
print "Writing MYMETA.yml\n";
577
YAML::Tiny::DumpFile('MYMETA.yml', $meta);