Permalink
Browse files

Raw.pm: overload &{} (closes #4)

  • Loading branch information...
1 parent 25f69a7 commit 327f1d2c9cb55e2e6296b5b49362bbd2b6fd6c62 @ghedo committed Sep 19, 2012
Showing with 16 additions and 0 deletions.
  1. +1 −0 Changes
  2. +15 −0 lib/FFI/Raw.pm
View
@@ -4,6 +4,7 @@ Revision history for FFI-Raw
- Make types constants inlineable by perl (GH#2) (thanks, DOLMEN!)
- Add a proper Changes file (GH#3)
+ - Overload &{} to make a FFI::Raw object similar to a CODE ref (GH#4)
0.12 2012-08-20 11:34:16 Europe/Rome
View
@@ -6,6 +6,13 @@ use warnings;
require XSLoader;
XSLoader::load('FFI::Raw', $FFI::Raw::VERSION);
+use overload '&{}' => \&_call_deref;
+
+sub _call_deref {
+ my $ffi = shift;
+ return sub { $ffi -> call(@_) };
+}
+
=head1 NAME
FFI::Raw - Perl bindings to the portable FFI library (libffi)
@@ -58,6 +65,14 @@ Execute the C<FFI::Raw> function C<$self>. This function takes also a variable
number of arguments, which are passed to the called function. The argument types
must match the types passed to C<new>.
+Simply dereferencing the C<FFI::Raw> object will work as well:
+
+ $cos -> call(2.0);
+
+is the same as:
+
+ $cos -> (2.0);
+
=head1 SUBROUTINES
=head2 memptr( $number )

0 comments on commit 327f1d2

Please sign in to comment.