Update Module::Install and Module::Install::RTx
[manu/RT-Extension-WatchedQueues.git] / inc / Module / Install / Metadata.pm
index 7acf8fd..397fb97 100644 (file)
@@ -1,3 +1,4 @@
+#line 1
 package Module::Install::Metadata;
 
 use strict 'vars';
@@ -5,7 +6,7 @@ use Module::Install::Base;
 
 use vars qw{$VERSION $ISCORE @ISA};
 BEGIN {
-       $VERSION = '0.72';
+       $VERSION = '0.77';
        $ISCORE  = 1;
        @ISA     = qw{Module::Install::Base};
 }
@@ -16,9 +17,7 @@ my @scalar_keys = qw{
        abstract
        author
        version
-       license
        distribution_type
-       perl_version
        tests
        installdirs
 };
@@ -29,13 +28,21 @@ my @tuple_keys = qw{
        requires
        recommends
        bundles
+       resources
+};
+
+my @resource_keys = qw{
+       homepage
+       bugtracker
+       repository
 };
 
-sub Meta            { shift        }
-sub Meta_ScalarKeys { @scalar_keys }
-sub Meta_TupleKeys  { @tuple_keys  }
+sub Meta              { shift          }
+sub Meta_ScalarKeys   { @scalar_keys   }
+sub Meta_TupleKeys    { @tuple_keys    }
+sub Meta_ResourceKeys { @resource_keys }
 
-foreach my $key (@scalar_keys) {
+foreach my $key ( @scalar_keys ) {
        *$key = sub {
                my $self = shift;
                return $self->{values}{$key} if defined wantarray and !@_;
@@ -44,12 +51,30 @@ foreach my $key (@scalar_keys) {
        };
 }
 
+foreach my $key ( @resource_keys ) {
+       *$key = sub {
+               my $self = shift;
+               unless ( @_ ) {
+                       return () unless $self->{values}{resources};
+                       return map  { $_->[1] }
+                              grep { $_->[0] eq $key }
+                              @{ $self->{values}{resources} };
+               }
+               return $self->{values}{resources}{$key} unless @_;
+               my $uri = shift or die(
+                       "Did not provide a value to $key()"
+               );
+               $self->resources( $key => $uri );
+               return 1;
+       };
+}
+
 sub requires {
        my $self = shift;
        while ( @_ ) {
                my $module  = shift or last;
                my $version = shift || 0;
-               push @{ $self->{values}->{requires} }, [ $module, $version ];
+               push @{ $self->{values}{requires} }, [ $module, $version ];
        }
        $self->{values}{requires};
 }
@@ -59,7 +84,7 @@ sub build_requires {
        while ( @_ ) {
                my $module  = shift or last;
                my $version = shift || 0;
-               push @{ $self->{values}->{build_requires} }, [ $module, $version ];
+               push @{ $self->{values}{build_requires} }, [ $module, $version ];
        }
        $self->{values}{build_requires};
 }
@@ -69,7 +94,7 @@ sub configure_requires {
        while ( @_ ) {
                my $module  = shift or last;
                my $version = shift || 0;
-               push @{ $self->{values}->{configure_requires} }, [ $module, $version ];
+               push @{ $self->{values}{configure_requires} }, [ $module, $version ];
        }
        $self->{values}{configure_requires};
 }
@@ -79,7 +104,7 @@ sub recommends {
        while ( @_ ) {
                my $module  = shift or last;
                my $version = shift || 0;
-               push @{ $self->{values}->{recommends} }, [ $module, $version ];
+               push @{ $self->{values}{recommends} }, [ $module, $version ];
        }
        $self->{values}{recommends};
 }
@@ -89,11 +114,33 @@ sub bundles {
        while ( @_ ) {
                my $module  = shift or last;
                my $version = shift || 0;
-               push @{ $self->{values}->{bundles} }, [ $module, $version ];
+               push @{ $self->{values}{bundles} }, [ $module, $version ];
        }
        $self->{values}{bundles};
 }
 
+# Resource handling
+my %lc_resource = map { $_ => 1 } qw{
+       homepage
+       license
+       bugtracker
+       repository
+};
+
+sub resources {
+       my $self = shift;
+       while ( @_ ) {
+               my $name  = shift or last;
+               my $value = shift or next;
+               if ( $name eq lc $name and ! $lc_resource{$name} ) {
+                       die("Unsupported reserved lowercase resource '$name'");
+               }
+               $self->{values}{resources} ||= [];
+               push @{ $self->{values}{resources} }, [ $name, $value ];
+       }
+       $self->{values}{resources};
+}
+
 # Aliases for build_requires that will have alternative
 # meanings in some future version of META.yml.
 sub test_requires      { shift->build_requires(@_) }
@@ -107,30 +154,73 @@ sub install_as_vendor  { $_[0]->installdirs('vendor') }
 
 sub sign {
        my $self = shift;
-       return $self->{'values'}{'sign'} if defined wantarray and ! @_;
-       $self->{'values'}{'sign'} = ( @_ ? $_[0] : 1 );
+       return $self->{values}{sign} if defined wantarray and ! @_;
+       $self->{values}{sign} = ( @_ ? $_[0] : 1 );
        return $self;
 }
 
 sub dynamic_config {
        my $self = shift;
        unless ( @_ ) {
-               warn "You MUST provide an explicit true/false value to dynamic_config, skipping\n";
+               warn "You MUST provide an explicit true/false value to dynamic_config\n";
                return $self;
        }
        $self->{values}{dynamic_config} = $_[0] ? 1 : 0;
-       return $self;
+       return 1;
+}
+
+sub perl_version {
+       my $self = shift;
+       return $self->{values}{perl_version} unless @_;
+       my $version = shift or die(
+               "Did not provide a value to perl_version()"
+       );
+
+       # Convert triple-part versions (eg, 5.6.1 or 5.8.9) to
+       # numbers (eg, 5.006001 or 5.008009).
+
+       $version =~ s/^(\d+)\.(\d+)\.(\d+)$/sprintf("%d.%03d%03d",$1,$2,$3)/e;
+
+       $version =~ s/_.+$//;
+       $version = $version + 0; # Numify
+       unless ( $version >= 5.005 ) {
+               die "Module::Install only supports 5.005 or newer (use ExtUtils::MakeMaker)\n";
+       }
+       $self->{values}{perl_version} = $version;
+       return 1;
+}
+
+sub license {
+       my $self = shift;
+       return $self->{values}{license} unless @_;
+       my $license = shift or die(
+               'Did not provide a value to license()'
+       );
+       $self->{values}{license} = $license;
+
+       # Automatically fill in license URLs
+       if ( $license eq 'perl' ) {
+               $self->resources( license => 'http://dev.perl.org/licenses/' );
+       }
+
+       return 1;
 }
 
 sub all_from {
        my ( $self, $file ) = @_;
 
        unless ( defined($file) ) {
-               my $name = $self->name
-                       or die "all_from called with no args without setting name() first";
+               my $name = $self->name or die(
+                       "all_from called with no args without setting name() first"
+               );
                $file = join('/', 'lib', split(/-/, $name)) . '.pm';
                $file =~ s{.*/}{} unless -e $file;
-               die "all_from: cannot find $file from $name" unless -e $file;
+               unless ( -e $file ) {
+                       die("all_from cannot find $file from $name");
+               }
+       }
+       unless ( -f $file ) {
+               die("The path '$file' does not exist, or is not a file");
        }
 
        # Some methods pull from POD instead of code.
@@ -209,8 +299,8 @@ sub features {
        while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) {
                $self->feature( $name, @$mods );
        }
-       return $self->{values}->{features}
-               ? @{ $self->{values}->{features} }
+       return $self->{values}{features}
+               ? @{ $self->{values}{features} }
                : ();
 }
 
@@ -266,22 +356,25 @@ sub abstract_from {
         );
 }
 
+# Add both distribution and module name
 sub name_from {
-       my $self = shift;
+       my ($self, $file) = @_;
        if (
-               Module::Install::_read($_[0]) =~ m/
+               Module::Install::_read($file) =~ m/
                ^ \s*
                package \s*
                ([\w:]+)
                \s* ;
                /ixms
        ) {
-               my $name = $1;
+               my ($name, $module_name) = ($1, $1);
                $name =~ s{::}{-}g;
                $self->name($name);
+               unless ( $self->module_name ) {
+                       $self->module_name($module_name);
+               }
        } else {
-               die "Cannot determine name from $_[0]\n";
-               return;
+               die("Cannot determine name from $file\n");
        }
 }
 
@@ -290,7 +383,7 @@ sub perl_version_from {
        if (
                Module::Install::_read($_[0]) =~ m/
                ^
-               use \s*
+               (?:use|require) \s*
                v?
                ([\d_\.]+)
                \s* ;
@@ -340,8 +433,12 @@ sub license_from {
                my $license_text = $1;
                my @phrases      = (
                        'under the same (?:terms|license) as perl itself' => 'perl',        1,
+                       'GNU general public license'                      => 'gpl',         1,
                        'GNU public license'                              => 'gpl',         1,
+                       'GNU lesser general public license'               => 'lgpl',        1,
                        'GNU lesser public license'                       => 'lgpl',        1,
+                       'GNU library general public license'              => 'lgpl',        1,
+                       'GNU library public license'                      => 'lgpl',        1,
                        'BSD license'                                     => 'bsd',         1,
                        'Artistic license'                                => 'artistic',    1,
                        'GPL'                                             => 'gpl',         1,
@@ -355,7 +452,7 @@ sub license_from {
                        $pattern =~ s{\s+}{\\s+}g;
                        if ( $license_text =~ /\b$pattern\b/i ) {
                                if ( $osi and $license_text =~ /All rights reserved/i ) {
-                                       warn "LEGAL WARNING: 'All rights reserved' may invalidate Open Source licenses. Consider removing it.";
+                                       print "WARNING: 'All rights reserved' in copyright may invalidate Open Source license.\n";
                                }
                                $self->license($license);
                                return 1;
@@ -367,6 +464,24 @@ sub license_from {
        return 'unknown';
 }
 
+sub bugtracker_from {
+       my $self    = shift;
+       my $content = Module::Install::_read($_[0]);
+       my @links   = $content =~ m/L\<(http\:\/\/rt\.cpan\.org\/[^>]+)\>/g;
+       unless ( @links ) {
+               warn "Cannot determine bugtracker info from $_[0]\n";
+               return 0;
+       }
+       if ( @links > 1 ) {
+               warn "Found more than on rt.cpan.org link in $_[0]\n";
+               return 0;
+       }
+
+       # Set the bugtracker
+       bugtracker( $links[0] );
+       return 1;
+}
+
 sub install_script {
        my $self = shift;
        my $args = $self->makemaker_args;
@@ -377,7 +492,7 @@ sub install_script {
                } elsif ( -d 'script' and -f "script/$_" ) {
                        push @$exe, "script/$_";
                } else {
-                       die "Cannot find script '$_'";
+                       die("Cannot find script '$_'");
                }
        }
 }