Skip to content

Commit 158ec63

Browse files
authored
Merge pull request #1 from plicease/closure
allow closure types
2 parents eb9e9b5 + 27eec78 commit 158ec63

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/MYMETA.*
2+
/Makefile
3+
/blib
4+
/pm_to_blib
5+
/NativeCall-*
6+
*.bak

MANIFEST

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ Makefile.PL
44
examples/troll.pl
55
lib/NativeCall.pm
66
t/basic.t
7+
t/closure.t
78
t/symbol.t

lib/NativeCall.pm

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ sub _attr_parse {
2222
(\w+)
2323
(?:
2424
\(
25-
(.*?)
25+
(.*)
2626
\)
2727
)?
2828
/x);
29-
return ($attribute, [ split /,\s*/, $args//'' ]);
29+
return ($attribute, [ map { s/;/,/gr; } split /,\s*/, ($args//'') =~ s/(\([^)]*\))/$1 =~ s{,}{;}rg /ger ]);
3030
}
3131

3232
sub MODIFY_CODE_ATTRIBUTES {
@@ -105,7 +105,8 @@ use what is already loaded.
105105
106106
=item Args
107107
108-
A comma-separated list of L<FFI::Platypus::Type>s.
108+
A comma-separated list of L<FFI::Platypus::Type>s. All types are supported,
109+
including L<closures|FFI::Platypus::Type#Closures>.
109110
110111
=item Returns
111112

t/closure.t

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use strict;
2+
use warnings;
3+
use Test::More;
4+
use FFI::Platypus;
5+
6+
my %args;
7+
8+
no warnings 'redefine';
9+
sub FFI::Platypus::attach {
10+
my($self, $name, $args, $ret) = @_;
11+
$args{$name->[0]} = $args;
12+
$self;
13+
}
14+
15+
use parent qw( NativeCall );
16+
17+
sub foo1 :Args((int)->int) :Returns(void) {}
18+
is_deeply $args{foo1}, [ '(int)->int' ];
19+
20+
sub foo2 :Args((int)->int,int) :Returns(void) {}
21+
is_deeply $args{foo2}, [ '(int)->int', 'int' ];
22+
23+
sub foo3 :Args((int,int)->int) :Returns(void) {}
24+
is_deeply $args{foo3}, [ '(int,int)->int' ];
25+
26+
sub foo4 :Args((int,int)->int,int,(string,int,int)->int) :Returns(void) {}
27+
is_deeply $args{foo4}, [ '(int,int)->int', 'int', '(string,int,int)->int' ];
28+
29+
done_testing;

0 commit comments

Comments
 (0)