NativeCall - Perl 5 interface to foreign functions in Perl code without XS
use parent qw(NativeCall); use feature 'say'; sub cdio_eject_media_drive :Args(string) :Native(cdio) {} sub cdio_close_tray :Args(string, int) :Native(cdio) {} say "Gimme a CD!"; cdio_eject_media_drive undef; sleep 1; say "Ha! Too slow!"; cdio_close_tray undef, 0; sub fmax :Args(double, double) :Native :Returns(double) {} say "fmax(2.0, 3.0) = " . fmax(2.0, 3.0); # avoid Perl built in also called "abs" sub myabs :Args(int) :Native :Returns(int) :Symbol(abs) {} say "abs(-3) = " . abs(-3);
Mimics the NativeCall module and interface from Perl 6. Uses FFI::Platypus, by the mighty Graham Ollis, for the actual hard work. Uses inheritance and attributes.
NativeCall
See examples/troll.pl for the example given above in SYNOPSIS.
If an argument is given, try to load from that library. If none given, use what is already loaded.
A comma-separated list of FFI::Platypus::Types. All types are supported, including closures.
A single FFI::Platypus::Type.
The native symbol name, if different from the Perl sub name.
This module is entirely inspired by the article about Perl 6 NativeCall at http://blogs.perl.org/users/zoffix_znet/2016/05/perl-6-nativecall-look-ma-im-a-c-programmer-1.html. All credit for clear explanation to Zoffix. All brickbats to me.
To install NativeCall, copy and paste the appropriate command in to your terminal.
cpanm
cpanm NativeCall
CPAN shell
perl -MCPAN -e shell install NativeCall
For more information on module installation, please visit the detailed CPAN module installation guide.