Alien-Libarchive

 view release on metacpan or  search on metacpan

inc/Alien/LZO/Installer.pm  view on Meta::CPAN

 while(my($module, $version) = each %$prereqs)
 {
   ...
 }

Returns a hash reference of the build requirements.  The
keys are the module names and the values are the versions.

The requirements may be different depending on your
platform.

=cut

sub build_requires
{
  my %prereqs = (
    'HTTP::Tiny'   => 0,
    'Archive::Tar' => 0,
  );
  
  if($^O eq 'MSWin32')
  {
    $prereqs{'Alien::MSYS'} = '0.07';
    $prereqs{'Archive::Ar'} = '2.00';
  }
  
  \%prereqs;
}

=head2 system_requires

This is like L<build_requires|Alien::LZO::Installer#build_requires>,
except it is used when using the lzo that comes with the operating
system.

=cut

sub system_requires
{
  my %prereqs = ();
  \%prereqs;
}

=head2 system_install

 my $installer = Alien::LZO::Installer->system_install(%options);

B<NOTE:> using this method may require modules returned by the
L<system_requires|Alien::LZO::Installer> method.

B<NOTE:> This form will also use the lzo provided by L<Alien::LZO>
if it is installed.  This makes this method ideal for finding
lzo as an optional dependency.

Options:

=over 4

=item test

Specifies the test type that should be used to verify the integrity
of the system lzo.  Generally this should be
set according to the needs of your module.  Should be one of:

=over 4

=item compile

use L<test_compile_run|Alien::LZO::Installer#test_compile_run> to verify.
This is the default.

=item ffi

use L<test_ffi|Alien::LZO::Installer#test_ffi> to verify

=item both

use both
L<test_compile_run|Alien::LZO::Installer#test_compile_run>
and
L<test_ffi|Alien::LZO::Installer#test_ffi>
to verify

=back

=item alien

If true (the default) then an existing L<Alien::LZO> will be
used if version 0.19 or better is found.  Usually this is what you
want.

=back

=cut

sub system_install
{
  my($class, %options) = @_;

  $options{alien} = 1 unless defined $options{alien};
  $options{test} ||= 'compile';
  die "test must be one of compile, ffi or both"
    unless $options{test} =~ /^(compile|ffi|both)$/;

  if($options{alien} && eval q{ use Alien::LZO 0.01; 1 })
  {
    my $alien = Alien::LZO->new;
    my $build = bless {
      cflags => $alien->cflags,
      libs   => $alien->libs,
    }, $class;
    return $build if $options{test} =~ /^(compile|both)$/ && $build->test_compile_run;
    return $build if $options{test} =~ /^(ffi|both)$/ && $build->test_compile_run;
  }

  my $build = bless {
    cflags => [],
    libs   => ['-llzo2'],
  }, $class;
  
  $build->test_compile_run || die $build->error if $options{test} =~ /^(compile|both)$/;
  $build->test_ffi || die $build->error if $options{test} =~ /^(ffi|both)$/;
  $build;
}

=head2 build_install

 my $installer = Alien::LZO::Installer->build_install( '/usr/local', %options );

B<NOTE:> using this method may (and probably does) require modules
returned by the L<build_requires|Alien::LZO::Installer>
method.

Build and install lzo into the given directory.  If there
is an error an exception will be thrown.  On a successful build, an
instance of L<Alien::LZO::Installer> will be returned.

These options may be passed into build_install:

=over 4

=item tar

Filename where the lzo source tar is located.
If not specified the latest version will be downloaded
from the Internet.

=item dir

Empty directory to be used to extract the lzo
source and to build from.

=item test

Specifies the test type that should be used to verify the integrity
of the build after it has been installed.  Generally this should be
set according to the needs of your module.  Should be one of:

=over 4

=item compile

use L<test_compile_run|Alien::LZO::Installer#test_compile_run> to verify.
This is the default.

=item ffi

use L<test_ffi|Alien::LZO::Installer#test_ffi> to verify

=item both

use both
L<test_compile_run|Alien::LZO::Installer#test_compile_run>
and
L<test_ffi|Alien::LZO::Installer#test_ffi>
to verify

=back

=back

=cut

sub _msys
{
  my($sub) = @_;
  require Config;
  if($^O eq 'MSWin32')
  {
    if($Config::Config{cc} !~ /cl(\.exe)?$/i)
    {
      require Alien::MSYS;
      return Alien::MSYS::msys(sub{ $sub->('make') });
    }
  }
  $sub->($Config::Config{make});
}

sub build_install
{
  my($class, $prefix, %options) = @_;

  require File::Spec;
  
  $options{test} ||= 'compile';
  die "test must be one of compile, ffi or both"
    unless $options{test} =~ /^(compile|ffi|both)$/;
  die "need an install prefix" unless $prefix;
  
  $prefix =~ s{\\}{/}g;
  
  my $dir = $options{dir} || do { require File::Temp; File::Temp::tempdir( CLEANUP => 1 ) };
  
  require Archive::Tar;
  my $tar = Archive::Tar->new;
  $tar->read($options{tar} || $class->fetch);
  
  require Cwd;
  my $save = Cwd::getcwd();
  
  chdir $dir;  
  my $build = eval {
  
    $tar->extract;

    chdir do {
      opendir my $dh, '.';
      my(@list) = grep !/^\./,readdir $dh;
      close $dh;
      die "unable to find source in build root" if @list == 0;
      die "confused by multiple entries in the build root" if @list > 1;
      $list[0];
    };
  
    _msys(sub {
      # TODO this will only work with gcc



( run in 1.052 second using v1.01-cache-2.11-cpan-13bb782fe5a )