Alien-Base
view release on metacpan or search on metacpan
lib/Alien/Base.pm view on Meta::CPAN
logic. Helpers allow you to do this without making your Alien module a
requirement when a build from source code is not necessary.
As a concrete example, consider L<Alien::gmake>, which provides the
helper C<gmake>:
package Alien::gmake;
...
sub alien_helper {
my($class) = @_;
return {
gmake => sub {
# return the executable name for GNU make,
# usually either make or gmake depending on
# the platform and environment
$class->exe;
}
},
}
Now consider L<Alien::nasm>. C<nasm> requires GNU Make to build from
source code, but if the system C<nasm> package is installed we don't
need it. From the L<alienfile> of C<Alien::nasm>:
use alienfile;
plugin 'Probe::CommandLine' => (
command => 'nasm',
args => ['-v'],
match => qr/NASM version/,
);
share {
...
plugin 'Extract' => 'tar.gz';
plugin 'Build::MSYS' => ();
build [
'sh configure --prefix=%{alien.install.prefix}',
'%{gmake}',
'%{gmake} install',
];
};
...
=cut
sub alien_helper {
{};
}
=head2 inline_auto_include
my(@headers) = Alien::MyLibrary->inline_auto_include;
List of header files to automatically include in inline C and C++
code when using L<Inline::C> or L<Inline::CPP>. This is provided
as a public interface primarily so that it can be overidden at run
time. This can also be specified in your C<Build.PL> with
L<Alien::Base::ModuleBuild> using the C<alien_inline_auto_include>
property.
=cut
sub inline_auto_include {
my ($class) = @_;
return [] unless $class->config('inline_auto_include');
$class->config('inline_auto_include')
}
sub Inline {
my ($class, $language) = @_;
return if $language !~ /^(C|CPP)$/;
my $config = {
CCFLAGSEX => $class->cflags,
LIBS => $class->libs,
};
if (@{ $class->inline_auto_include } > 0) {
$config->{AUTO_INCLUDE} = join "\n", map { "#include \"$_\"" } @{ $class->inline_auto_include };
}
$config;
}
=head2 runtime_prop
my $hashref = Alien::MyLibrary->runtime_prop;
Returns a hash reference of the runtime properties computed by L<Alien::Build> during its
install process. If the L<Alien::Base> based L<Alien> was not built using L<Alien::Build>,
then this will return undef.
=cut
{
my %alien_build_config_cache;
sub runtime_prop
{
my($class) = @_;
return $alien_build_config_cache{$class} if
exists $alien_build_config_cache{$class};
$alien_build_config_cache{$class} ||= do {
my $dist = ref $class ? ref $class : $class;
$dist =~ s/::/-/g;
my $dist_dir = eval { File::ShareDir::dist_dir($dist) };
return if $@;
my $alien_json = File::Spec->catfile($dist_dir, '_alien', 'alien.json');
return unless -r $alien_json;
open my $fh, '<', $alien_json;
my $json = do { local $/; <$fh> };
close $fh;
require JSON::PP;
my $config = JSON::PP::decode_json($json);
$config->{distdir} = $dist_dir;
( run in 0.991 second using v1.01-cache-2.11-cpan-9bca49b1385 )