Alien-ActiveMQ
view release on metacpan or search on metacpan
script/install-activemq view on Meta::CPAN
# To make it easier to test
method _get($uri) {
return get($uri);
}
method _getstore( $uri, $file ) {
return getstore( $uri, $file );
}
method download_tarball {
eval { return $self->download_current; };
if ($@) {
eval { return $self->download_archive; };
}
die "Could't download version " . $self->version_number . ": $@\n" if $@;
return $self->tarball;
}
method download_current {
$self->output( "Downloading mirror list from ", $self->download_uri );
my $mirror_list = $self->_get( $self->download_uri );
die( "Failed to download mirror location " . $self->download_uri . "\n" )
unless $mirror_list;
my ($file) = $mirror_list =~ /(http:[^"]+-bin\.tar.gz)/;
die( "Failed to extract mirror from " . $self->download_uri . "\n" )
unless $file;
$self->output("Downloading from $file");
my $res = $self->_getstore( $file, $self->tarball . '' );
die( "Failed to download mirrored file " . $file . "\n" )
unless $res == 200;
return $self->tarball;
}
method download_archive {
$self->output( "Downloading archived version from ", $self->archive_uri );
my $res = $self->_getstore( $self->archive_uri, $self->tarball . '' );
die( "Failed to download archive file " . $self->archive_uri . "\n" )
unless $res == 200;
return $self->tarball;
}
method unpack_tarball {
local $Archive::Extract::PREFER_BIN = 1;
my $tar = Archive::Extract->new( archive => $self->tarball . '' );
$tar->extract( to => $self->_temp_dir . '' );
}
method _dircopy( $from, $to ) {
return dircopy( $from, $to );
}
method run {
if ( -d $self->install_dir ) {
if ( $self->force ) {
warn($self->script_name . ": Already installed, but --force - reinstalling\n");
}
else {
warn($self->script_name . ": Already installed, you did not say --force - exiting\n");
exit 0;
}
}
my $tarball = $self->has_tarball ? $self->tarball : $self->download_tarball;
die "Can't read tarball $tarball: $!" unless -r $tarball;
$self->output("Downloaded tarball to: $tarball");
$self->unpack_tarball;
$self->output("Unpacked tarball $tarball");
my $dir = $self->_temp_dir->file( $tarball->basename );
$dir =~ s/\.tar\.gz$//;
$dir =~ s/-bin//;
die("Could not find where tarball unpacked") unless -d $dir;
$self->output( "From " . $dir . " to " . $self->install_dir );
$self->_dircopy( $dir => $self->install_dir );
$self->output( "ActiveMQ installed in " . $self->install_dir . "\n" );
return 1;
}
__PACKAGE__->meta->make_immutable;
__PACKAGE__->new_with_options->run unless caller;
1;
__END__
( run in 0.925 second using v1.01-cache-2.11-cpan-483215c6ad5 )