Alien-Libarchive
view release on metacpan or search on metacpan
inc/Alien/LZO/Installer.pm view on Meta::CPAN
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
=item version
Version to download
=back
=cut
sub fetch
{
my($class, %options) = @_;
my $dir = $options{dir} || eval { require File::Temp; File::Temp::tempdir( CLEANUP => 1 ) };
require HTTP::Tiny;
my $version = $options{version} || do {
my @versions = $class->versions_available;
die "unable to determine latest version from listing"
unless @versions > 0;
$versions[-1];
};
if(defined $ENV{ALIEN_LZO_INSTALL_MIRROR})
{
my $fn = _catfile($ENV{ALIEN_LZO_INSTALL_MIRROR}, "lzo-$version.tar.gz");
return wantarray ? ($fn, $version) : $fn;
}
my $url = "http://www.oberhumer.com/opensource/lzo/download/lzo-$version.tar.gz";
my $response = HTTP::Tiny->new->get($url);
die sprintf("%s %s %s", $response->{status}, $response->{reason}, $url)
unless $response->{success};
require File::Spec;
my $fn = _catfile($dir, "lzo-$version.tar.gz");
open my $fh, '>', $fn;
binmode $fh;
print $fh $response->{content};
close $fh;
wantarray ? ($fn, $version) : $fn;
}
=head2 build_requires
my $prereqs = Alien::LZO::Installer->build_requires;
while(my($module, $version) = each %$prereqs)
{
inc/Alien/LZO/Installer.pm view on Meta::CPAN
=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') });
}
}
( run in 0.624 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )