.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "NativeCall 3pm" .TH NativeCall 3pm "2019-07-23" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" NativeCall \- Perl 5 interface to foreign functions in Perl code without XS .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use parent qw(NativeCall); \& use feature \*(Aqsay\*(Aq; \& \& 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); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mimics the \f(CW\*(C`NativeCall\*(C'\fR module and interface from Perl 6. Uses FFI::Platypus, by the mighty Graham Ollis, for the actual hard work. Uses inheritance and attributes. .PP See \fIexamples/troll.pl\fR for the example given above in \s-1SYNOPSIS.\s0 .SS "\s-1ATTRIBUTES\s0" .IX Subsection "ATTRIBUTES" .IP "Native" 4 .IX Item "Native" If an argument is given, try to load from that library. If none given, use what is already loaded. .IP "Args" 4 .IX Item "Args" A comma-separated list of FFI::Platypus::Types. All types are supported, including closures. .IP "Returns" 4 .IX Item "Returns" A single FFI::Platypus::Type. .IP "Symbol" 4 .IX Item "Symbol" The native symbol name, if different from the Perl sub name. .SH "INSPIRATION" .IX Header "INSPIRATION" This module is entirely inspired by the article about Perl 6 NativeCall at . All credit for clear explanation to Zoffix. All brickbats to me.