Alien-Libarchive

 view release on metacpan or  search on metacpan

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

 use Alien::LZO::Installer;
 use Module::Build;
 
 my %build_args;
 
 my $installer = eval { Alien::LZO::Installer->system_install };
 if($installer)
 {
   $build_args{extra_compiler_flags} = $installer->cflags,
   $build_args{extra_linker_flags}   = $installer->libs,
 }
 
 my $build = Module::Build->new(%build_args);
 $build->create_build_script;

Build.PL

 # require 2.0
 use Alien::LZO::Installer;
 use Module::Build;
 
 my $installer = eval {
   my $system_installer = Alien::LZO::Installer->system_install;
   die "we require 2.00 or better"
     if $system->version !~ /^([0-9]+)\./ && $1 >= 2;
   $system_installer;
      # reasonably assumes that build_install will never download
      # a version older that 3.0
 } || Alien::LZO::Installer->build_install("dir");
 
 my $build = Module::Build->new(
   extra_compiler_flags => $installer->cflags,
   extra_linker_flags   => $installer->libs,
 );
 $build->create_build_script;

FFI::Raw

 # as an optional dep
 use Alien::LZO::Installer;
 use FFI::Raw;
 
 eval {
   my($dll) = Alien::LZO::Installer->system_install->dlls;
   FFI::Raw->new($dll, 'lzo_version', FFI::Raw::uint);
 };
 if($@)
 {
   # handle it if lzo is not available
 }

=head1 DESCRIPTION

This distribution contains the logic for finding existing lzo
installs, and building new ones.  If you do not care much about the
version of lzo that you use, and lzo is not an optional
requirement, then you are probably more interested in using
L<Alien::LZO>.

Where L<Alien::LZO::Installer> is useful is when you have
specific version requirements (say you require 3.0.x but 2.7.x
will not do), but would still like to use the system lzo
if it is available.

=head1 CLASS METHODS

Class methods can be executed without creating an instance of
L<Alien::LZO::Installer>, and generally used to query
status of lzo availability (either via the system or the
internet).  Methods that discover a system lzo or build
a one from source code on the Internet will generally return
an instance of L<Alien::LZO::Installer> which can be
queried to retrieve the settings needed to interact with 
lzo via XS or L<FFI::Raw>.

=head2 versions_available

 my @versions = Alien::LZO::Installer->versions_available;
 my $latest_version = $versions[-1];

Return the list of versions of lzo available on the Internet.
Will throw an exception if the oberhumer.com website is unreachable.
Versions will be sorted from oldest (smallest) to newest (largest).

=cut

sub versions_available
{
  require HTTP::Tiny;
  my $url = "http://www.oberhumer.com/opensource/lzo/download/";
  my $response = HTTP::Tiny->new->get($url);
  
  die sprintf("%s %s %s", $response->{status}, $response->{reason}, $url)
    unless $response->{success};

  # TODO remove dupes
  my @versions;
  push @versions, [$1,$2] while $response->{content} =~ /lzo-([1-9][0-9]*)\.([0-9]+)\.tar.gz/g;
  @versions = map { join '.', @$_ } sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @versions;
}

=head2 fetch

 my($location, $version) = Alien::LZO::Installer->fetch(%options);
 my $location = Alien::LZO::Installer->fetch(%options);

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

Download lzo source from the internet.  By default it will
download the latest version to a temporary directory which will
be removed when Perl exits.  Will throw an exception on
failure.  Options include:

=over 4

=item dir

Directory to download to



( run in 1.747 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )