Alien-Thrust
view release on metacpan or search on metacpan
ThrustModuleBuild.pm view on Meta::CPAN
package ThrustModuleBuild;
use strict;
use File::Spec::Functions qw(splitpath);
use IO::File;
use IO::Uncompress::Unzip qw($UnzipError);
use File::Path qw(mkpath);
use parent 'Module::Build';
my $thrust_version = '0.7.6';
my $thrust_archive = 'thrust.zip';
sub ACTION_build {
my $self = shift;
$self->download_zip_file();
$self->extract_zip_file();
$self->SUPER::ACTION_build;
}
sub ACTION_install {
my $self = shift;
if ($^O =~ /darwin/i) {
## ExtUtils::Install appears to break ThrustShell.App - maybe doesn't copy some meta-data or something?
$self->depends_on('build'); ## So that the parent class ACTION_install won't invoke it again
print "WARNING: Due to Mac OS X lameness, we are removing the thrust shell binaries from the blib directory before install. You will have to to re-build if you want to use this local blib.\n";
system("rm -rf blib/lib/auto/share/dist/Alien-Thrust/");
$self->SUPER::ACTION_install;
my $share_install_dir = $self->install_map->{'blib/lib'} . "/auto/share/dist/Alien-Thrust/";
system('mkdir', '-p', $share_install_dir);
system('unzip', '-oqq', $thrust_archive, '-d', $share_install_dir);
} else {
$self->SUPER::ACTION_install;
}
}
sub download_zip_file {
my $self = shift;
my ($os, $arch);
if ($^O =~ /linux/i) {
$os = 'linux';
$arch = length(pack("P", 0)) == 8 ? 'x64' : 'ia32';
if ($arch eq 'ia32') {
die "32bit linux is not supported";
}
} elsif ($^O =~ /darwin/i) {
$os = 'darwin';
$arch = 'x64';
} elsif ($^O =~ /mswin/i) {
$os = 'win32';
$arch = 'ia32';
die "windows is not yet supported, see https://github.com/hoytech/Thrust/issues/1 (but we think we're close)";
} else {
die "Your platform is currently not supported by Thrust";
}
my $thrust_zipfile_url = "https://github.com/breach/thrust/releases/download/v$thrust_version/thrust-v$thrust_version-$os-$arch.zip";
if (-e $thrust_archive) {
print "$thrust_archive already exists, skipping download\n";
} else {
print "Downloading $thrust_zipfile_url (be patient)\n";
if (system(qw/wget -c -O/, "$thrust_archive.partial", $thrust_zipfile_url)) {
if (-e "$thrust_archive.partial") {
## wget started the download but probably user hit control-c
die "download failed, aborting";
}
print "unable to run wget, trying LWP::UserAgent\n";
unlink("$thrust_archive.partial");
require LWP::UserAgent;
( run in 0.778 second using v1.01-cache-2.11-cpan-fa01517f264 )