File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ my %attr21 = (
12
12
Native => 1,
13
13
Args => 1,
14
14
Returns => 1,
15
+ Symbol => 1,
15
16
);
16
17
17
18
sub _attr_parse {
@@ -42,7 +43,7 @@ sub MODIFY_CODE_ATTRIBUTES {
42
43
}
43
44
}
44
45
my $subname = subname $subref ;
45
- my $sub_base = (split /::/, $subname )[-1];
46
+ my $sub_base = $attr2args { Symbol } -> [0] // (split /::/, $subname )[-1];
46
47
my $ffi = FFI::Platypus-> new;
47
48
my $lib = $attr2args {Native }-> [0] || undef ; # undef means standard library
48
49
$ffi -> lib($lib ? find_lib_or_die lib => $lib : undef );
@@ -79,6 +80,10 @@ NativeCall - Perl 5 interface to foreign functions in Perl code without XS
79
80
80
81
sub fmax :Args(double, double) :Native :Returns(double) {}
81
82
say "fmax(2.0, 3.0) = " . fmax(2.0, 3.0);
83
+
84
+ # avoid Perl built in also called "abs"
85
+ sub myabs :Args(int) :Native :Returns(int) :Symbol(abs) {}
86
+ say "abs(-3) = " . abs(-3);
82
87
83
88
=head1 DESCRIPTION
84
89
@@ -105,6 +110,10 @@ A comma-separated list of L<FFI::Platypus::Type>s.
105
110
106
111
A single L<FFI::Platypus::Type> .
107
112
113
+ =item Symbol
114
+
115
+ The native symbol name, if different from the Perl sub name.
116
+
108
117
=back
109
118
110
119
=head1 INSPIRATION
Original file line number Diff line number Diff line change
1
+ use strict;
2
+ use warnings;
3
+ use Test::More;
4
+ use FFI::Platypus;
5
+
6
+ my %sym ;
7
+
8
+ no warnings ' redefine' ;
9
+ sub FFI ::Platypus::attach {
10
+ my ($self , $name , $args , $ret ) = @_ ;
11
+ $sym {$name -> [1]} = $name -> [0];
12
+ $self ;
13
+ }
14
+
15
+ use parent qw( NativeCall ) ;
16
+
17
+ sub foo1 :Returns(void) :Symbol(bar1) {}
18
+ is $sym {' main::foo1' }, ' bar1' ;
19
+
20
+ sub foo2 :Returns(void) {}
21
+ is $sym {' main::foo2' }, ' foo2' ;
22
+
23
+ done_testing;
You can’t perform that action at this time.
0 commit comments