Apache-Voodoo
view release on metacpan or search on metacpan
lib/Apache/Voodoo/Install/Distribution.pm view on Meta::CPAN
################################################################################
#
# Apache::Voodoo::Install::Updater
#
# This package provides the methods that do pre/post/upgrade commands as specified
# by the various .xml files in an application.
#
################################################################################
package Apache::Voodoo::Install::Distribution;
$VERSION = "3.0200";
use strict;
use warnings;
use base("Apache::Voodoo::Install");
use Apache::Voodoo::Constants;
use File::Spec;
use Config::General;
use ExtUtils::Install;
sub new {
my $class = shift;
my %params = @_;
my $self = {%params};
$self->{'distribution'} = File::Spec->rel2abs($self->{'distribution'});
unless (-e $self->{'distribution'} && -f $self->{'distribution'}) {
die "ERROR: No such file or directory\n";
}
$self->{'app_name'} = $self->{'distribution'};
$self->{'app_name'} =~ s/\.tar\.(bz2|gz)$//i;
$self->{'app_name'} =~ s/-[\d.]*(-beta\d+)?$//;
$self->{'app_name'} =~ s/.*\///;
unless ($self->{'app_name'} =~ /^[a-z][\w-]*$/i) {
die "ERROR: Distribution file names must follow the format: AppName-Version.tar.(gz|bz2)\n";
}
my $ac = Apache::Voodoo::Constants->new();
$self->{'ac'} = $ac;
$self->{'install_path'} = File::Spec->catfile($ac->install_path(),$self->{'app_name'});
$self->{'conf_file'} = File::Spec->catfile($self->{'install_path'},$ac->conf_file());
$self->{'conf_path'} = File::Spec->catfile($self->{'install_path'},$ac->conf_path());
$self->{'updates_path'} = File::Spec->catfile($self->{'install_path'},$ac->updates_path());
$self->{'apache_uid'} = $ac->apache_uid();
$self->{'apache_gid'} = $ac->apache_gid();
bless $self,$class;
return $self;
}
sub app_name {
my $self = shift;
$self->{'app_name'} = $_[0] if $_[0];
return $self->{'app_name'};
}
sub existing {
my $self = shift;
return $self->{'is_existing'};
}
################################################################################
# Handles installer cleanup tasks.
################################################################################
sub DESTROY {
my $self = shift;
if ($self->{'unpack_dir'}) {
system("rm", "-rf", $self->{'unpack_dir'});
}
}
sub do_install {
my $self = shift;
$self->unpack_distribution();
my $new_conf = File::Spec->catfile($self->{'unpack_dir'},$self->{'ac'}->conf_file());
my $pm_dir = $self->{distribution};
$pm_dir =~ s/(\.tar(\.gz|\.bz2)?|\.tgz)$//;
$pm_dir =~ s/^.*\///;
$pm_dir = File::Spec->catfile($self->{'unpack_dir'},$pm_dir);
if (-e $new_conf) {
$self->check_existing();
$self->update_conf_file();
$self->install_files();
}
elsif (-e File::Spec->catfile($pm_dir,'Makefile.PL') ||
-e File::Spec->catfile($pm_dir,'Build.PL')) {
$self->info("This appears to be a standard Perl module. Calling CPAN to install it...\n");
eval {
use CPAN;
CPAN::Shell->install(File::Spec->catfile($pm_dir,"."));
};
exit;
}
else {
print "This distribution doesn't follow a format that I know how to handle. Giving up.\n";
exit;
}
( run in 1.881 second using v1.01-cache-2.11-cpan-5735350b133 )