Skip to content
This repository has been archived by the owner on Mar 7, 2019. It is now read-only.

inline support #77

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,3 +6,4 @@ blib/
.DS_Store
/MANIFEST.bak
/Alien-Base-*
/_Inline
11 changes: 7 additions & 4 deletions .travis.yml
Expand Up @@ -8,7 +8,8 @@ install:
- make
- sudo make install
- cd ..
- cpanm --installdeps .
- cpanm -n --installdeps .
- cpanm -n Inline::C Inline::CPP

perl:
- "5.8"
Expand All @@ -23,11 +24,13 @@ perl:
script:
- perl Build.PL
- ./Build
- ./Build test
- prove -bv t
- ./Build install
- cd Alien-Base-Extras/Acme-Alien-DontPanic; cpanm --installdeps . && perl Build.PL && ./Build && ./Build test && ./Build install
- cd Alien-Base-Extras/Acme-Ford-Prefect; cpanm --installdeps . && perl Build.PL && ./Build && ./Build test && ./Build install
- cd ../..
- prove -bv t

env:
- ALIEN_FORCE=1
- ALIEN_FORCE=0
- ALIEN_FORCE=1 LD_LIBRARY_PATH=/usr/local/lib
- ALIEN_FORCE=0 LD_LIBRARY_PATH=/usr/local/lib
1 change: 1 addition & 0 deletions Build.PL
Expand Up @@ -54,4 +54,5 @@ unless (`pkg-config --version` && $? == 0) {
}

my $builder = Module::Build->new(%build_args);
$builder->add_to_cleanup( '_Inline' );
$builder->create_build_script;
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
Revision history for Perl module Alien::Base.

- support for Inline 'with'
- fix prereqs for Text::ParseWords and PkgConfig

0.005 Sep 11, 2014
- improved documentation coverage

Expand Down
2 changes: 2 additions & 0 deletions MANIFEST
Expand Up @@ -40,6 +40,8 @@ t/find_lib/lib/onlypredot.0.so
t/find_lib/lib/prepostdot.0.so.0
t/http.t
t/http_uri.t
t/inline.t
t/inline_cpp.t
t/install_destination.t
t/interpolate.t
t/local_repo.t
Expand Down
3 changes: 3 additions & 0 deletions MANIFEST.SKIP
Expand Up @@ -77,3 +77,6 @@
\b_alien/
\b_share/

# Avoid the temporary directory created by Inline
\b_Inline

18 changes: 18 additions & 0 deletions lib/Alien/Base.pm
Expand Up @@ -82,6 +82,14 @@ Or you can use it from an FFI module:

FFI::Raw->new($dll, 'my_library_function', FFI::Raw::void);

You can even use it with L<Inline> (C and C++ languages are supported):

package MyLibrary::Inline;

use Alien::MyLibrary;
use Inline with => 'Alien::MyLibrary';
...

=head1 DESCRIPTION

L<Alien::Base> comprises base classes to help in the construction of C<Alien::> modules. Modules in the L<Alien> namespace are used to locate and install (if necessary) external libraries needed by other Perl modules.
Expand Down Expand Up @@ -242,6 +250,7 @@ sub _keyword {
my $name = $self->config('name');
my $command = Alien::Base::PkgConfig->pkg_config_command . " --\L$keyword\E $name";

$! = 0;
chomp ( my $pcdata = capture_merged { system( $command ) } );
croak "Could not call pkg-config: $!" if $!;

Expand Down Expand Up @@ -367,6 +376,15 @@ sub dynamic_libs {
grep { ! -l $_ } map { File::Spec->catfile($dir, $_) } @dlls;
}

sub Inline {
my ($class, $language) = @_;
return if $language !~ /^(C|CPP)$/;
return {
CCFLAGSEX => $class->cflags,
LIBS => $class->libs,
};
}

1;

__END__
Expand Down
32 changes: 32 additions & 0 deletions t/inline.t
@@ -0,0 +1,32 @@
use strict;
use warnings;
use Test::More;

BEGIN {
eval { require Inline; require Inline::C; } || plan skip_all => 'test requires Inline and Inline::C';
eval { require Acme::Alien::DontPanic; } || plan skip_all => 'test requires Acme::Alien::DontPanic';
}

use Acme::Alien::DontPanic;
use Inline with => 'Acme::Alien::DontPanic';
use Inline C => 'DATA', ENABLE => 'AUTOWRAP';

is string_answer(), "the answer to life the universe and everything is 42", "indirect call";
is answer(), 42, "direct call";

done_testing;

__DATA__
__C__

#include <libdontpanic.h>
#include <stdio.h>

char *string_answer()
{
static char buffer[1024];
sprintf(buffer, "the answer to life the universe and everything is %d", answer());
return buffer;
}

extern int answer();
35 changes: 35 additions & 0 deletions t/inline_cpp.t
@@ -0,0 +1,35 @@
use strict;
use warnings;
use Test::More;

BEGIN {
eval { require Inline; require Inline::CPP; } || plan skip_all => 'test requires Inline and Inline::CPP';
eval { require Acme::Alien::DontPanic; } || plan skip_all => 'test requires Acme::Alien::DontPanic';
}

use Acme::Alien::DontPanic;
use Inline with => 'Acme::Alien::DontPanic';
use Inline CPP => 'DATA', ENABLE => 'AUTOWRAP';

is Foo->new->string_answer, "the answer to life the universe and everything is 42", 'indirect';
is answer(), 42, "direct";

done_testing;

__DATA__
__CPP__

#include <libdontpanic.h>
#include <stdio.h>

class Foo {
public:
char *string_answer()
{
static char buffer[1024];
sprintf(buffer, "the answer to life the universe and everything is %d", answer());
return buffer;
}
};

extern int answer();