Alien-bz2-Installer

 view release on metacpan or  search on metacpan

lib/Alien/bz2/Installer.pm  view on Meta::CPAN

   $system_installer;
      # reasonably assumes that build_install will never download
      # a version older that 1.0.6
 } || Alien::bz2::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::bz2::Installer;
 use FFI::Raw;
 
 eval {
   my($dll) = Alien::bz2::Installer->system_install->dlls;
   FFI::Raw->new($dll, 'BZ2_bzlibVersion', FFI::Raw::str);
 };
 if($@)
 {
   # handle it if bz2 is not available
 }

=head1 DESCRIPTION

If you just want to compress or decompress bzip2 data in Perl you
probably want one of L<Compress::Bzip2>, L<Compress::Raw::Bzip2>
or L<IO::Compress::Bzip2>.

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

Where L<Alien::bz2::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 bz2
if it is available.

=head1 CLASS METHODS

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

=head2 versions_available

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

Returns the list of versions of bzip2 available on the Internet.
Will throw an exception if available versions cannot be determined.

=head2 fetch

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

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

Download the bz2 source from the internet.  By default it will
download the latest version t 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

=head2 build_requires

 my $prereqs = Alien::bz2::Installer->build_requires;
 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.

=head2 system_requires

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

=head2 system_install

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

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

Options:

=over 4

=item test

Specifies the test type that should be used to verify the integrity
of the system bz2.  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::bz2::Installer#test_compile_run> to verify.
This is the default.

=item ffi

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

=item both

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

=back

=item alien

If true (The default) then an existing L<Alien::bz2> will
be used if found.  Usually this is what you want.

=back

=head2 build_install

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

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

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

These options may be passed into build_install:

=over 4

=item tar

Filename where the bz2 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 bz2
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::bz2::Installer#test_compile_run> to verify.
This is the default.

=item ffi

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

=item both

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

=back

=back

=head1 ATTRIBUTES

Attributes of an L<Alien::bz2::Installer> provide the
information needed to use an existing bz2 (which may
either be provided by the system, or have just been built
using L<build_install|Alien::bz2::Installer#build_install>.

=head2 cflags

The compiler flags required to use bz2.

=head2 libs

The linker flags and libraries required to use bz2.



( run in 0.421 second using v1.01-cache-2.11-cpan-385001e3568 )