App-grindperl
view release on metacpan or search on metacpan
lib/App/grindperl.pm view on Meta::CPAN
sub config_file {
my ($self) = @_;
my $config_dir = dir(File::HomeDir->my_dist_config('App-grindperl', {create=>1}));
return $config_dir->file("grindperl.conf");
}
sub read_config_file {
my ($self) = @_;
open my $fh, "<", $self->config_file;
my @args;
while ( my $line = <$fh> ) {
chomp $line;
push @args, split " ", $line, 2;
}
return @args;
}
sub do_cmd {
my ($self, $cmd, @args) = @_;
my $cmdline = join( q{ }, $cmd, @args);
if ( $self->logfile ) {
$cmdline .= " >" . $self->logfile . " 2>&1";
}
$self->vlog("Running '$cmdline'");
system($cmdline);
return $? == 0;
}
sub verify_dir {
my ($self) = @_;
my $prefix = dir($self->prefix);
return -w $prefix->parent;
}
sub configure {
my ($self) = @_;
croak("Executable Configure program not found") unless -x "Configure";
# used cached files
for my $f ( qw/config.sh Policy.sh/ ) {
next unless -f $self->cache_file($f);
if ( $self->opt->get_cache ) {
copy( $self->cache_file($f), $f );
if ( -f $f ) {
$self->vlog("Copied $f from cache");
}
else {
$self->vlog("Faild to copy $f from cache");
}
}
else {
unlink $self->cache_file($f);
}
}
$self->do_cmd( "./Configure", $self->configure_args )
or croak("Configure failed!");
# save files back into cache if updated
dir( $self->cache_dir )->mkpath;
for my $f ( qw/config.sh Policy.sh/ ) {
copy( $f, $self->cache_file($f) )
if (! -f $self->cache_file($f)) || (-M $f > -M $self->cache_file($f));
}
return 1;
}
sub run {
my ($self) = @_;
if ( $self->opt->get_edit ) {
my $cf_file = $self->config_file;
if ( $ENV{EDITOR} ) {
system( $ENV{EDITOR}, $cf_file )
and die "Error editing config file: $!\n";
}
else {
say "No EDITOR set. Edit $cf_file manually.";
}
exit 0;
}
die "This doesn't look like a perl source directory.\n"
unless -f "perl.c";
my $prefix = $self->prefix;
die "Can't install to $prefix\: parent directory is not writeable\n"
unless -w dir($prefix)->parent;
if ( $self->is_git ) {
$self->do_cmd("git clean -dxf")
}
else {
$self->do_cmd("make distclean") if -f 'Makefile';
}
$self->configure;
exit 0 if $self->opt->get_config; # config only
my $test_jobs = $self->opt->get_testjobs;
my $jobs = $self->opt->get_jobs;
if ( $test_jobs ) {
$ENV{TEST_JOBS} = $test_jobs if $test_jobs > 1;
if ( $self->opt->get_porting ) {
$self->vlog("Running 'make test_porting' with $test_jobs jobs");
$self->do_cmd("make -j $jobs test_porting")
or croak ("make test_porting failed");
}
elsif ( grep { /test_harness/ } do { local(@ARGV,$/) = "Makefile"; <>} ) {
$self->vlog("Running 'make test_harness' with $test_jobs jobs");
$self->do_cmd("make -j $jobs test_harness")
or croak ("make test_harness failed");
}
else {
$self->vlog("Running 'make test' with $test_jobs jobs");
( run in 0.723 second using v1.01-cache-2.11-cpan-59e3e3084b8 )