App-MechaCPAN
view release on metacpan or search on metacpan
lib/App/MechaCPAN/Perl.pm view on Meta::CPAN
'threads!',
'jobs=i',
'skip-tests!',
'skip-local!',
'skip-lib!',
'smart-tests!',
'devel!',
'shared-lib!',
'source-only!',
);
my $perl5_ver_re = qr/v? 5 [.] (\d{1,2}) (?: [.] (\d{1,2}) )?/xms;
my $perl5_re = qr/^ $perl5_ver_re $/xms;
our $JOBS = 2; # The number of jobs to run with make
sub go
{
my $class = shift;
my $opts = shift;
my $src = shift;
my @argv = shift;
if ( $^O eq 'MSWin32' )
{
info 'Cannot build perl on Win32';
return 0;
}
my $orig_dir = &get_project_dir;
my $dest_dir = &dest_dir;
my @dest_dir = File::Spec->splitdir("$dest_dir");
my $dest_len = $#dest_dir;
my $perl_dir = "$dest_dir/perl";
my $pv_ver; # Version in .perl-version file
# source-only currently defaults to true, downloading binaries currently
# will only happen if no-source-only is given
$opts->{'source-only'} //= 0;
# Attempt to find the perl version if none was given
if ( -f '.perl-version' )
{
open my $pvFH, '<', '.perl-version';
$pv_ver = do { local $/; <$pvFH> };
$pv_ver =~ s/\s+//xmsg;
if ( $pv_ver !~ $perl5_re )
{
info "$pv_ver in .perl-version doesn't look like a perl5 version";
undef $pv_ver;
}
}
my ( $src_tz, $version ) = _get_targz( $src // $pv_ver, $opts );
my $bin_tz;
if ( ref $src_tz eq 'ARRAY' )
{
( $bin_tz, $src_tz ) = @$src_tz;
}
# If _get_targz couldn't find a version, guess based on the file
if ( !$version && $src_tz =~ m($perl5_ver_re [^/]* $)xms )
{
my $major = $1;
my $minor = $2;
$version = "5.$major.$minor";
info("Looks like $src_tz is perl $version, assuming that's true");
}
local $JOBS = $opts->{jobs} // $JOBS;
if ( $opts->{'build-reusable'} )
{
return build_reusable( $version, $perl_dir, $src_tz, $opts );
}
if ( -e -x "$perl_dir/bin/perl" )
{
unless ( $opts->{is_restarted_process} )
{
# If it exists, we're probably running it by now.
if ( $version && $^V ne "v$version" )
{
info(
$version,
"perl has already been installed ($^V, not $version)"
);
}
else
{
success( $version, "perl has already been installed" );
}
}
return 0;
}
my $verstr = "perl $version";
info $verstr, "Fetching $verstr";
if ( defined $bin_tz && !$opts->{'source-only'} )
{
my $success = _handle_bin_tz( $bin_tz, $version );
return 0
if $success;
}
my $src_dir = inflate_archive($src_tz);
my @src_dirs = File::Spec->splitdir("$src_dir");
chdir $src_dir;
if ( -e -x File::Spec->catdir( @src_dirs, qw/bin perl/ ) )
{
die "Binary archive provided, but source-only was requested"
if $opts->{'source-only'};
my $success = _install_binary( File::Spec->catdir(@src_dirs), $version );
return $success ? 0 : 1;
}
if ( !-e 'Configure' )
lib/App/MechaCPAN/Perl.pm view on Meta::CPAN
use Fatal qw/copy move/;
chdir $dest_dir;
my $output = eval { run "$src_dir/bin/perl", '-e', 'print $^V' };
chomp $output;
if ( $output ne "v$version" )
{
die qq{Binary versions mismatch expectations: }
. qq{"$output" (found) ne "$version" (expected)};
}
# Attempt to run something more rigorous
local $@;
eval { _check_perl_binary("$src_dir/bin/perl") };
my $error = $@;
if ($error)
{
die "Binary does not appear to be usable: $error";
}
make_path($perl_dir);
move( $src_dir, $perl_dir );
success "Installed binary $version";
return 1;
}
our $source_mirror = 'https://www.cpan.org/src/5.0';
our $binary_mirror = 'https://dnld.mechacpan.us/dist';
sub _dnld_url
{
my $version = shift;
my $minor = shift;
return "$source_mirror/perl-5.$version.$minor.tar.gz";
}
sub _bin_url
{
my $version = shift;
my $minor = shift;
my $opts = shift;
my $fullver = "v5.$version.$minor";
my $slugline = slugline( undef, $fullver, $opts->{threads} );
return "$binary_mirror/$slugline.tar.xz";
}
sub _get_targz
{
my $src = shift;
my $opts = shift;
# If there's no src, find the newest version.
if ( !defined $src )
{
# Do a terrible job of guessing what the current version is
use Time::localtime;
my $year = localtime->year() + 1900;
# 5.12 was released in 2010, and approximatly every May, a new even
# version was released
my $major = ( $year - 2010 ) * 2 + ( localtime->mon < 4 ? 10 : 12 );
# Verify our guess
{
my $dnld = _dnld_url( $major, 0 ) . ".md5.txt";
my $contents = '';
my $where = eval { fetch_file( $dnld => \$contents ) };
if ( !defined $where && $major > 12 )
{
$major -= 2;
redo;
}
}
$src = "5.$major";
}
# file
if ( -e $src )
{
return ( rel_start_to_abs($src), '' );
}
my $url;
# URL
if ( $src =~ url_re )
{
return ( $src, '' );
}
# CPAN
if ( $src =~ $perl5_re )
{
my $version = $1;
my $minor = $2;
# They probably want the latest if minor wasn't given
if ( !defined $minor )
{
# 11 is the highest minor version seen as of this writing
my @possible = ( 0 .. 15 );
while ( @possible > 1 )
{
my $i = int( @possible / 2 );
$minor = $possible[$i];
my $dnld = _dnld_url( $version, $minor ) . ".md5.txt";
my $contents = '';
my $where = eval { fetch_file( $dnld => \$contents ) };
if ( defined $where )
{
# The version exists, which means it's higher still
@possible = @possible[ $i .. $#possible ];
}
else
{
# The version doesn't exit. That means higher versions don't either
@possible = @possible[ 0 .. $i - 1 ];
}
}
$minor = $possible[0];
}
return (
[
_bin_url( $version, $minor, $opts ),
_dnld_url( $version, $minor, $opts ),
],
"5.$version.$minor"
);
}
die "Cannot find $src\n";
}
1;
__END__
=encoding utf-8
=head1 NAME
App::MechaCPAN::Perl - Mechanize the installation of Perl.
=head1 SYNOPSIS
# Install 5.24 into local/
user@host:~$ mechacpan perl 5.24
=head1 DESCRIPTION
The C<perl> command is used to install L<perl> into C<local/>. This removes the package's dependency on the operating system perl. It will do this by either downloading a binary archive or by building from a L<perl> source archive.
=head2 Methods
=head3 go( \%opts, $version )
There is only a single public function that should be called. This will install the version of perl given in C<$version> using the options in C<\%opts>. The options available are listed in the L<arguments|/Arguments> section below.
C<$version> is either 0 or 1 parameter:
=over
=item * If 0 parameters are given and there is a .perl-version file, it will try and use that as the version to install.
=item * Otherwise, if 0 parameters are given, it will attempt to find and install the newest, stable version of perl.
=item * If the parameter is a file, it will try to use that file as an archive to install perl.
=item * If the parameter looks like a URL, it will fetch that URL and try to use it as an archive to install perl.
=item * If the parameter is a major version (5.XX), it will attempt to download and install the newest minor version of that major version.
=item * If the parameter is a minor version (5.XX.X), it will attempt to download and install that exact version.
=back
In the cases where a version is given, and the C<--no-source-only> option is given, C<App::MechaCPAN::Perl> will attempt to download a binary archive prebuilt for the operating system. This guess is made by looking at how the currently executing L<pe...
After an archive is retrieved, it will be checked to see if it is a binary or source package. This is accomplished by checking for an executable C<bin/perl> file in the archive. Basic tests are ran to make sure the binary is usable, notably by runnin...
=head2 Arguments
=head3 source-only
By default a source archive is attempted to be retreived and installed. If you want it to attempt to also retrieve a binary archive, you can use C<--no-source-only>. If you do not want C<App::MechaCPAN::Perl> to even attempt to use a binary archive, ...
=head3 threads
By default, perl is compiled without threads. If you'd like to enable threads, use this argument.
=head3 shared-lib
By default, perl will not generate a libperl.a file. If you need libperl.so, then use this argument.
=head3 jobs
How many make jobs to use when running make. The code will guess if C<make> supports running multiple jobs, and as such, it may not work for all versions of make. Defaults to 2.
=head3 skip-tests
Test for perl are ran by default. If you are sure that the tests will pass and you want to save some time, you can skip the testing phase with this option.
=head3 smart-tests
As an alternative to telling C<App::MechaCPAN::Perl> to use tests or not, C<App::MechaCPAN::Perl> can try to be clever and guess if it needs to run tests. If there is a C<.perl-version> file and it is the same version that is being installed, then te...
C<smart-tests> are off by default, but are enabled by L<App::MechaCPAN::Deploy> when there is a C<cpanfile.snapshot> file. See L<App::MechaCPAN::Install/smart-tests>.
=head3 skip-local
Since perl and modules will be installed by L<App::MechaCPAN> into C<local/>, by default C<local/> will be added to C<@INC>. This means that if you use the C<local/> installed perl you do not need to use L<local::lib> or other C<@INC> tricks. If you ...
=head3 skip-lib
If a C<lib/> directory exists in the same directory as the C<local/> directory, then C<lib/> will also bee added to C<@INC>. This is helpful if you're installing to run an application that includes a C<lib/> directory. If you do not want this to be a...
=head3 devel
By default, perl will not compile a development version without -Dusedevel passed to configure. This adds that flag to the configure step so that perl will install unstable development versions. This is B<NOT> recommended except for testing.
=head1 WIN32 LIMITATION
Building perl from scratch on Win32 is nothing like building it on other platforms. At this point, the C<perl> command does not work on Win32.
=head1 AUTHOR
Jon Gentle E<lt>cpan@atrodo.orgE<gt>
=head1 COPYRIGHT
Copyright 2017- Jon Gentle
=head1 LICENSE
This is free software. You may redistribute copies of it under the terms of the Artistic License 2 as published by The Perl Foundation.
=head1 SEE ALSO
=over
=item L<plenv|https://github.com/tokuhirom/plenv>
=item L<App::perlbrew>
=back
=cut
( run in 2.636 seconds using v1.01-cache-2.11-cpan-fe3c2283af0 )