2
package Module::Install::Metadata;
5
use Module::Install::Base ();
7
use vars qw{$VERSION @ISA $ISCORE};
10
@ISA = 'Module::Install::Base';
14
my @boolean_keys = qw{
37
my @resource_keys = qw{
51
sub Meta_BooleanKeys { @boolean_keys }
52
sub Meta_ScalarKeys { @scalar_keys }
53
sub Meta_TupleKeys { @tuple_keys }
54
sub Meta_ResourceKeys { @resource_keys }
55
sub Meta_ArrayKeys { @array_keys }
57
foreach my $key ( @boolean_keys ) {
60
if ( defined wantarray and not @_ ) {
61
return $self->{values}->{$key};
63
$self->{values}->{$key} = ( @_ ? $_[0] : 1 );
68
foreach my $key ( @scalar_keys ) {
71
return $self->{values}->{$key} if defined wantarray and !@_;
72
$self->{values}->{$key} = shift;
77
foreach my $key ( @array_keys ) {
80
return $self->{values}->{$key} if defined wantarray and !@_;
81
$self->{values}->{$key} ||= [];
82
push @{$self->{values}->{$key}}, @_;
87
foreach my $key ( @resource_keys ) {
91
return () unless $self->{values}->{resources};
92
return map { $_->[1] }
93
grep { $_->[0] eq $key }
94
@{ $self->{values}->{resources} };
96
return $self->{values}->{resources}->{$key} unless @_;
97
my $uri = shift or die(
98
"Did not provide a value to $key()"
100
$self->resources( $key => $uri );
105
foreach my $key ( grep { $_ ne "resources" } @tuple_keys) {
108
return $self->{values}->{$key} unless @_;
111
my $module = shift or last;
112
my $version = shift || 0;
113
push @added, [ $module, $version ];
115
push @{ $self->{values}->{$key} }, @added;
116
return map {@$_} @added;
121
my %lc_resource = map { $_ => 1 } qw{
131
my $name = shift or last;
132
my $value = shift or next;
133
if ( $name eq lc $name and ! $lc_resource{$name} ) {
134
die("Unsupported reserved lowercase resource '$name'");
136
$self->{values}->{resources} ||= [];
137
push @{ $self->{values}->{resources} }, [ $name, $value ];
139
$self->{values}->{resources};
142
# Aliases for build_requires that will have alternative
143
# meanings in some future version of META.yml.
144
sub test_requires { shift->build_requires(@_) }
145
sub install_requires { shift->build_requires(@_) }
147
# Aliases for installdirs options
148
sub install_as_core { $_[0]->installdirs('perl') }
149
sub install_as_cpan { $_[0]->installdirs('site') }
150
sub install_as_site { $_[0]->installdirs('site') }
151
sub install_as_vendor { $_[0]->installdirs('vendor') }
155
my $value = @_ ? shift : 1;
156
if ( $self->{values}->{dynamic_config} ) {
157
# Once dynamic we never change to static, for safety
160
$self->{values}->{dynamic_config} = $value ? 1 : 0;
164
# Convenience command
166
shift->dynamic_config(0);
171
return $self->{values}->{perl_version} unless @_;
172
my $version = shift or die(
173
"Did not provide a value to perl_version()"
176
# Normalize the version
177
$version = $self->_perl_version($version);
179
# We don't support the really old versions
180
unless ( $version >= 5.005 ) {
181
die "Module::Install only supports 5.005 or newer (use ExtUtils::MakeMaker)\n";
184
$self->{values}->{perl_version} = $version;
188
my ( $self, $file ) = @_;
190
unless ( defined($file) ) {
191
my $name = $self->name or die(
192
"all_from called with no args without setting name() first"
194
$file = join('/', 'lib', split(/-/, $name)) . '.pm';
195
$file =~ s{.*/}{} unless -e $file;
196
unless ( -e $file ) {
197
die("all_from cannot find $file from $name");
200
unless ( -f $file ) {
201
die("The path '$file' does not exist, or is not a file");
204
$self->{values}{all_from} = $file;
206
# Some methods pull from POD instead of code.
207
# If there is a matching .pod, use that instead
209
$pod =~ s/\.pm$/.pod/i;
210
$pod = $file unless -e $pod;
212
# Pull the different values
213
$self->name_from($file) unless $self->name;
214
$self->version_from($file) unless $self->version;
215
$self->perl_version_from($file) unless $self->perl_version;
216
$self->author_from($pod) unless @{$self->author || []};
217
$self->license_from($pod) unless $self->license;
218
$self->abstract_from($pod) unless $self->abstract;
225
my $provides = ( $self->{values}->{provides} ||= {} );
226
%$provides = (%$provides, @_) if @_;
232
return $self unless $self->is_admin;
233
unless (-e 'MANIFEST') {
234
warn "Cannot deduce auto_provides without a MANIFEST, skipping\n";
237
# Avoid spurious warnings as we are not checking manifest here.
238
local $SIG{__WARN__} = sub {1};
239
require ExtUtils::Manifest;
240
local *ExtUtils::Manifest::manicheck = sub { return };
242
require Module::Build;
243
my $build = Module::Build->new(
244
dist_name => $self->name,
245
dist_version => $self->version,
246
license => $self->license,
248
$self->provides( %{ $build->find_dist_packages || {} } );
254
my $features = ( $self->{values}->{features} ||= [] );
257
if ( @_ == 1 and ref( $_[0] ) ) {
258
# The user used ->feature like ->features by passing in the second
259
# argument as a reference. Accomodate for that.
269
ref($_) ? ( ref($_) eq 'HASH' ) ? %$_ : @$_ : $_
279
while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) {
280
$self->feature( $name, @$mods );
282
return $self->{values}->{features}
283
? @{ $self->{values}->{features} }
290
push @{ $self->{values}->{no_index}->{$type} }, @_ if $type;
291
return $self->{values}->{no_index};
296
$self->include_deps( 'YAML::Tiny', 0 );
299
my $data = YAML::Tiny::LoadFile('META.yml');
301
# Call methods explicitly in case user has already set some values.
302
while ( my ( $key, $value ) = each %$data ) {
303
next unless $self->can($key);
304
if ( ref $value eq 'HASH' ) {
305
while ( my ( $module, $version ) = each %$value ) {
306
$self->can($key)->($self, $module => $version );
309
$self->can($key)->($self, $value);
317
return $self unless $self->is_admin;
318
$self->admin->write_meta;
323
require ExtUtils::MM_Unix;
324
my ( $self, $file ) = @_;
325
$self->version( ExtUtils::MM_Unix->parse_version($file) );
327
# for version integrity check
328
$self->makemaker_args( VERSION_FROM => $file );
332
require ExtUtils::MM_Unix;
333
my ( $self, $file ) = @_;
336
{ DISTNAME => $self->name },
338
)->parse_abstract($file)
342
# Add both distribution and module name
344
my ($self, $file) = @_;
346
Module::Install::_read($file) =~ m/
353
my ($name, $module_name) = ($1, $1);
356
unless ( $self->module_name ) {
357
$self->module_name($module_name);
360
die("Cannot determine name from $file\n");
364
sub _extract_perl_version {
374
my $perl_version = $1;
375
$perl_version =~ s{_}{}g;
376
return $perl_version;
382
sub perl_version_from {
384
my $perl_version=_extract_perl_version(Module::Install::_read($_[0]));
386
$self->perl_version($perl_version);
388
warn "Cannot determine perl version info from $_[0]\n";
395
my $content = Module::Install::_read($_[0]);
397
=head \d \s+ (?:authors?)\b \s*
400
=head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s*
401
.*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s*
404
my $author = $1 || $2;
406
# XXX: ugly but should work anyway...
407
if (eval "require Pod::Escapes; 1") {
408
# Pod::Escapes has a mapping table.
409
# It's in core of perl >= 5.9.3, and should be installed
410
# as one of the Pod::Simple's prereqs, which is a prereq
411
# of Pod::Text 3.x (see also below).
412
$author =~ s{ E<( (\d+) | ([A-Za-z]+) )> }
416
: defined $Pod::Escapes::Name2character_number{$1}
417
? chr($Pod::Escapes::Name2character_number{$1})
419
warn "Unknown escape: E<$1>";
424
elsif (eval "require Pod::Text; 1" && $Pod::Text::VERSION < 3) {
425
# Pod::Text < 3.0 has yet another mapping table,
426
# though the table name of 2.x and 1.x are different.
427
# (1.x is in core of Perl < 5.6, 2.x is in core of
429
my $mapping = ($Pod::Text::VERSION < 2)
430
? \%Pod::Text::HTML_Escapes
431
: \%Pod::Text::ESCAPES;
432
$author =~ s{ E<( (\d+) | ([A-Za-z]+) )> }
436
: defined $mapping->{$1}
439
warn "Unknown escape: E<$1>";
445
$author =~ s{E<lt>}{<}g;
446
$author =~ s{E<gt>}{>}g;
448
$self->author($author);
450
warn "Cannot determine author info from $_[0]\n";
456
perl => 'http://dev.perl.org/licenses/',
457
apache => 'http://apache.org/licenses/LICENSE-2.0',
458
apache_1_1 => 'http://apache.org/licenses/LICENSE-1.1',
459
artistic => 'http://opensource.org/licenses/artistic-license.php',
460
artistic_2 => 'http://opensource.org/licenses/artistic-license-2.0.php',
461
lgpl => 'http://opensource.org/licenses/lgpl-license.php',
462
lgpl2 => 'http://opensource.org/licenses/lgpl-2.1.php',
463
lgpl3 => 'http://opensource.org/licenses/lgpl-3.0.html',
464
bsd => 'http://opensource.org/licenses/bsd-license.php',
465
gpl => 'http://opensource.org/licenses/gpl-license.php',
466
gpl2 => 'http://opensource.org/licenses/gpl-2.0.php',
467
gpl3 => 'http://opensource.org/licenses/gpl-3.0.html',
468
mit => 'http://opensource.org/licenses/mit-license.php',
469
mozilla => 'http://opensource.org/licenses/mozilla1.1.php',
470
open_source => undef,
471
unrestricted => undef,
472
restrictive => undef,
478
return $self->{values}->{license} unless @_;
479
my $license = shift or die(
480
'Did not provide a value to license()'
482
$license = __extract_license($license) || lc $license;
483
$self->{values}->{license} = $license;
485
# Automatically fill in license URLs
486
if ( $license_urls{$license} ) {
487
$self->resources( license => $license_urls{$license} );
493
sub _extract_license {
496
return __extract_license(
497
($matched) = $pod =~ m/
498
(=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?)
499
(=head \d.*|=cut.*|)\z
501
) || __extract_license(
502
($matched) = $pod =~ m/
503
(=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?)
504
(=head \d.*|=cut.*|)\z
509
sub __extract_license {
510
my $license_text = shift or return;
512
'(?:under )?the same (?:terms|license) as (?:perl|the perl (?:\d )?programming language)' => 'perl', 1,
513
'(?:under )?the terms of (?:perl|the perl programming language) itself' => 'perl', 1,
514
'Artistic and GPL' => 'perl', 1,
515
'GNU general public license' => 'gpl', 1,
516
'GNU public license' => 'gpl', 1,
517
'GNU lesser general public license' => 'lgpl', 1,
518
'GNU lesser public license' => 'lgpl', 1,
519
'GNU library general public license' => 'lgpl', 1,
520
'GNU library public license' => 'lgpl', 1,
521
'GNU Free Documentation license' => 'unrestricted', 1,
522
'GNU Affero General Public License' => 'open_source', 1,
523
'(?:Free)?BSD license' => 'bsd', 1,
524
'Artistic license 2\.0' => 'artistic_2', 1,
525
'Artistic license' => 'artistic', 1,
526
'Apache (?:Software )?license' => 'apache', 1,
530
'Artistic' => 'artistic', 1,
532
'Mozilla Public License' => 'mozilla', 1,
533
'Q Public License' => 'open_source', 1,
534
'OpenSSL License' => 'unrestricted', 1,
535
'SSLeay License' => 'unrestricted', 1,
536
'zlib License' => 'open_source', 1,
537
'proprietary' => 'proprietary', 0,
539
while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) {
540
$pattern =~ s#\s+#\\s+#gs;
541
if ( $license_text =~ /\b$pattern\b/i ) {
550
if (my $license=_extract_license(Module::Install::_read($_[0]))) {
551
$self->license($license);
553
warn "Cannot determine license info from $_[0]\n";
558
sub _extract_bugtracker {
559
my @links = $_[0] =~ m#L<(
560
https?\Q://rt.cpan.org/\E[^>]+|
561
https?\Q://github.com/\E[\w_]+/[\w_]+/issues|
562
https?\Q://code.google.com/p/\E[\w_\-]+/issues/list
570
sub bugtracker_from {
572
my $content = Module::Install::_read($_[0]);
573
my @links = _extract_bugtracker($content);
575
warn "Cannot determine bugtracker info from $_[0]\n";
579
warn "Found more than one bugtracker link in $_[0]\n";
584
bugtracker( $links[0] );
590
my $content = Module::Install::_readperl($_[0]);
591
my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+(v?[\d\.]+)/mg;
592
while ( @requires ) {
593
my $module = shift @requires;
594
my $version = shift @requires;
595
$self->requires( $module => $version );
599
sub test_requires_from {
601
my $content = Module::Install::_readperl($_[0]);
602
my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+([\d\.]+)/mg;
603
while ( @requires ) {
604
my $module = shift @requires;
605
my $version = shift @requires;
606
$self->test_requires( $module => $version );
610
# Convert triple-part versions (eg, 5.6.1 or 5.8.9) to
611
# numbers (eg, 5.006001 or 5.008009).
612
# Also, convert double-part versions (eg, 5.8)
615
$v =~ s/^([1-9])\.([1-9]\d?\d?)$/sprintf("%d.%03d",$1,$2)/e;
616
$v =~ s/^([1-9])\.([1-9]\d?\d?)\.(0|[1-9]\d?\d?)$/sprintf("%d.%03d%03d",$1,$2,$3 || 0)/e;
617
$v =~ s/(\.\d\d\d)000$/$1/;
629
for my $key (keys %hash) {
630
warn "add_metadata: $key is not prefixed with 'x_'.\n" .
631
"Use appopriate function to add non-private metadata.\n" unless $key =~ /^x_/;
632
$self->{values}->{$key} = $hash{$key};
637
######################################################################
641
die "WriteMyMeta has been deprecated";
644
sub write_mymeta_yaml {
647
# We need YAML::Tiny to write the MYMETA.yml file
648
unless ( eval { require YAML::Tiny; 1; } ) {
653
my $meta = $self->_write_mymeta_data or return 1;
655
# Save as the MYMETA.yml file
656
print "Writing MYMETA.yml\n";
657
YAML::Tiny::DumpFile('MYMETA.yml', $meta);
660
sub write_mymeta_json {
663
# We need JSON to write the MYMETA.json file
664
unless ( eval { require JSON; 1; } ) {
669
my $meta = $self->_write_mymeta_data or return 1;
671
# Save as the MYMETA.yml file
672
print "Writing MYMETA.json\n";
673
Module::Install::_write(
675
JSON->new->pretty(1)->canonical->encode($meta),
679
sub _write_mymeta_data {
682
# If there's no existing META.yml there is nothing we can do
683
return undef unless -f 'META.yml';
685
# We need Parse::CPAN::Meta to load the file
686
unless ( eval { require Parse::CPAN::Meta; 1; } ) {
690
# Merge the perl version into the dependencies
691
my $val = $self->Meta->{values};
692
my $perl = delete $val->{perl_version};
694
$val->{requires} ||= [];
695
my $requires = $val->{requires};
697
# Canonize to three-dot version after Perl 5.6
698
if ( $perl >= 5.006 ) {
699
$perl =~ s{^(\d+)\.(\d\d\d)(\d*)}{join('.', $1, int($2||0), int($3||0))}e
701
unshift @$requires, [ perl => $perl ];
704
# Load the advisory META.yml file
705
my @yaml = Parse::CPAN::Meta::LoadFile('META.yml');
708
# Overwrite the non-configure dependency hashs
709
delete $meta->{requires};
710
delete $meta->{build_requires};
711
delete $meta->{recommends};
712
if ( exists $val->{requires} ) {
713
$meta->{requires} = { map { @$_ } @{ $val->{requires} } };
715
if ( exists $val->{build_requires} ) {
716
$meta->{build_requires} = { map { @$_ } @{ $val->{build_requires} } };