-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using a Moose Role for FFI #3
base: master
Are you sure you want to change the base?
Conversation
[The MooseX::Role::FFI is provided here to make the review of both easier to do at the same time. It will be released separately if we were to approve this PR.] The MooseX::Role::FFI allows to specify the subroutine data and the library name - as well as the fallback - as subroutines. It will then generate the corresponding callback for each sub, which can be reached via a method. The `after` allows us to have direct access to the FFI object *before* the callbacks are generated. (Which I think is when we need it for the mangler to work, but I'm not sure.) What I like about it: * Metadata, the rest is generated. * Alien support built-in. * We don't need to have class-level variables (though we could change it to it instead of subroutines.) * We don't need to check that it has been instantiated (like we do in _get_version and $HAS_SUBS) What I don't like about it: * We need to make another method call to get the callback, depsite it being a definition of the class, not the instance. * If you have a typo in the callback name, you cannot catch it, because it's a string to retrieve it. I'm not sure the benefits outweigh the drawbacks. I was thinking of possibly providing *another* interface and saying "pick yours."
@@ -3,7 +3,7 @@ use warnings; | |||
use Test::More; | |||
use Audio::Chromaprint; | |||
|
|||
note "version = ", Audio::Chromaprint->get_version; | |||
note "version = ", Audio::Chromaprint->new->get_version; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
or croak('Unable to get raw fingerprint (get_raw_fingerprint)'); | ||
|
||
# not espeically fast, but need a cast with a variable length array | ||
my $fp = FFI::Platypus->new->cast( 'opaque' => "uint32[$size]", $ptr ); | ||
_dealloc($ptr); | ||
my $fp = $self->ffi->cast( 'opaque' => "uint32[$size]", $ptr ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
return _get_version(); | ||
around '_build_ffi' => sub { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can do this with an optional ffi_mangler
?
# ABSTRACT: Easily create interfaces to FFI functions with Moose roles | ||
|
||
use Moose::Role; | ||
use FFI::Platypus 0.89_01; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please bump this to 0.90
.
[The MooseX::Role::FFI is provided here to make the review of both
easier to do at the same time. It will be released separately if
we were to approve this PR.]
The MooseX::Role::FFI allows to specify the subroutine data and the
library name - as well as the fallback - as subroutines.
It will then generate the corresponding callback for each sub, which
can be reached via a method.
The
after
allows us to have direct access to the FFI object beforethe callbacks are generated. (Which I think is when we need it for
the mangler to work, but I'm not sure.)
What I like about it:
it to it instead of subroutines.)
in _get_version and $HAS_SUBS)
What I don't like about it:
it being a definition of the class, not the instance.
because it's a string to retrieve it.
I'm not sure the benefits outweigh the drawbacks. I was thinking of
possibly providing another interface and saying "pick yours."