App-grindperl

 view release on metacpan or  search on metacpan

lib/App/grindperl.pm  view on Meta::CPAN

  my @undefines = $self->opt->get_undefine;
  my %additions = $self->opt->get_additions;
  my @args = qw/-des -Dusedevel -Uversiononly/;
  push @args, "-Dusethreads" if $self->opt->get_threads;
  push @args, "-DDEBUGGING" if $self->opt->get_debugging;
  push @args, "-Accflags=-m32", "-Alddlflags=-m32", "-Aldflags=-m32",
    "-Uuse64bitint", "-Uuse64bitall", "-Uusemorebits"
    if $self->opt->get_32;
  push @args, "-r" if $self->opt->get_cache;
  if ( ! $self->opt->get_man ) {
    push @args, qw/-Dman1dir=none -Dman3dir=none/;
  }
  push @args, map { "-D$_=$defines{$_}" } keys %defines;
  push @args, map { "-U$_" } @undefines;
  push @args, map { "-A$_=$additions{$_}" } keys %additions;
  push @args, "-Dprefix=" . $self->prefix;
  return @args;
}

sub cache_dir {
  my ($self) = @_;
  return dir(File::HomeDir->my_dist_data('App-grindperl', {create=>1}))->stringify;
}

sub cache_file {
  my ($self,$file) = @_;
  croak "No filename given to cache_file()"
    unless defined $file && length $file;
  return file( $self->cache_dir, $file )->stringify;
}

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;

lib/App/grindperl.pm  view on Meta::CPAN

  }
  else {
    $self->vlog("Running 'make test_prep' with $test_jobs jobs");
    $self->do_cmd("make -j $jobs test_prep")
      or croak("make test_prep failed!");
  }

  if ( $self->opt->get_install ) {
    $self->vlog("Running 'make install'");
    $self->do_cmd("make install")
      or croak("make install failed!");
  }

  return 0; # usually passed to exit
}

1;

# ABSTRACT:  Guts of the grindperl tool


# vim: ts=2 sts=2 sw=2 et:

__END__

=pod

=encoding UTF-8

=head1 NAME

App::grindperl - Guts of the grindperl tool

=head1 VERSION

version 0.004

=head1 SYNOPSIS

  use App::grindperl;
  my $app = App::grindperl->new;
  exit $app->run;

=head1 DESCRIPTION

This module contains the guts of the L<grindperl> program.

=for Pod::Coverage new
opt
is_git
logfile
vlog
default_args
prefix
configure_args
cache_dir
cache_file
config_file
read_config_file
do_cmd
verify_dir
configure
run

=head1 SEE ALSO

L<grindperl>

=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan

=head1 SUPPORT

=head2 Bugs / Feature Requests

Please report any bugs or feature requests through the issue tracker
at L<https://github.com/dagolden/App-grindperl/issues>.
You will be notified automatically of any progress on your issue.

=head2 Source Code

This is open source software.  The code repository is available for
public review and contribution under the terms of the license.

L<https://github.com/dagolden/App-grindperl>

  git clone https://github.com/dagolden/App-grindperl.git

=head1 AUTHOR

David Golden <dagolden@cpan.org>

=head1 CONTRIBUTORS

=for stopwords David Golden Sawyer X

=over 4

=item *

David Golden <xdg@xdg.me>

=item *

Sawyer X <xsawyerx@cpan.org>

=back

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2011 by David Golden.

This is free software, licensed under:

  The Apache License, Version 2.0, January 2004

=cut



( run in 0.787 second using v1.01-cache-2.11-cpan-e1769b4cff6 )