+ my $module = shift;
+ my $version = shift;
+
+ unless (defined $args{siteinstall}) {
+ require Config;
+ my %uniq;
+ my @order = grep {($_ eq $Config::Config{sitelibexp}
+ or $_ eq $Config::Config{privlibexp})
+ and not $uniq{$_}++} @INC;
+ if ($] < 5.011 and @order == 2
+ and $order[0] eq $Config::Config{sitelibexp}
+ and $order[1] eq $Config::Config{privlibexp}) {
+
+ print "\n";
+ print "Patched perl, with site_perl before core in \@INC, detected.\n";
+ print "Installing dual-life modules into site_perl so they are not\n";
+ print "later overridden by the distribution's package.\n";
+
+ $args{siteinstall} = 1;
+ } else {
+ $args{siteinstall} = 0;
+ }
+ }
+
+ print "\nInstall module $module\n";
+
+ my $ext = $ENV{'RT_FIX_DEPS_CMD'} || $ENV{'PERL_PREFER_CPAN_CLIENT'};
+ unless( $ext ) {
+ my $configured = 1;
+ {
+ local @INC = @INC;
+ if ( $ENV{'HOME'} ) {
+ unshift @INC, "$ENV{'HOME'}/.cpan";
+ }
+ $configured = eval { require CPAN::MyConfig } || eval { require CPAN::Config };
+ }
+ unless ( $configured ) {
+ print <<END;
+You haven't configured the CPAN shell yet.
+Please run `@PERL@ -MCPAN -e shell` to configure it.
+END
+ exit(1);
+ }
+
+ my $installdirs = $CPAN::Config->{makepl_arg} ||= "";
+ $installdirs =~ s/(\bINSTALLDIRS=\S+|$)/ INSTALLDIRS=site/
+ if $args{siteinstall};
+ local $CPAN::Config->{makepl_arg} = $installdirs;
+
+ my $rv = eval { require CPAN; CPAN::Shell->install($module) };
+ return $rv unless $@;
+
+ print <<END;
+Failed to load module CPAN.
+
+-------- Error ---------
+$@
+------------------------
+
+When we tried to start installing RT's perl dependencies,
+we were unable to load the CPAN client. This module is usually distributed
+with Perl. This usually indicates that your vendor has shipped an unconfigured
+or incorrectly configured CPAN client.
+The error above may (or may not) give you a hint about what went wrong
+
+You have several choices about how to install dependencies in
+this situatation:
+
+1) use a different tool to install dependencies by running setting the following
+ shell environment variable and rerunning this tool:
+ RT_FIX_DEPS_CMD='@PERL@ -MCPAN -e"install %s"'
+2) Attempt to configure CPAN by running:
+ `@PERL@ -MCPAN -e shell` program from shell.
+ If this fails, you may have to manually upgrade CPAN (see below)
+3) Try to update the CPAN client. Download it from:
+ http://search.cpan.org/dist/CPAN and try again
+4) Install each dependency manually by downloading them one by one from
+ http://search.cpan.org
+
+END
+ exit(1);
+ }
+
+ if( $ext =~ /\%s/) {
+ $ext =~ s/\%s/$module/g; # sprintf( $ext, $module );
+ } else {
+ $ext .= " $module";
+ }
+ print "\t\tcommand: '$ext'\n";
+ return scalar `$ext 1>&2`;
+}
+
+sub check_perl_version {
+ section("perl");
+ eval {require 5.010_001};
+ if ($@) {
+ print_found("5.10.1", 0, sprintf("RT requires Perl v5.10.1 or newer. Your current Perl is v%vd", $^V));
+ exit(1);
+ } else {
+ print_found( sprintf(">=5.10.1(%vd)", $^V), 1 );
+ }