| 1 | package FFI::Platypus::Constant; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use 5.008004; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use constant 1.32 (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use FFI::Platypus; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | # ABSTRACT: Define constants in C space for Perl | ||||||||||
| 10 | 1 | our $VERSION = '2.12'; # VERSION | |||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | { | ||||||||||
| 14 | 1 | my $ffi = FFI::Platypus->new( api => 2 ); | |||||||||
| 15 | 1 | $ffi->bundle; | |||||||||
| 16 | |||||||||||
| 17 | 1 | $ffi->type( 'opaque' => 'ffi_platypus_constant_t' ); | |||||||||
| 18 | 1 | $ffi->type( '(string,string)->void' => 'set_str_t' ); | |||||||||
| 19 | 1 | $ffi->type( '(string,sint64)->void' => 'set_sint_t' ); | |||||||||
| 20 | 1 | $ffi->type( '(string,uint64)->void' => 'set_uint_t' ); | |||||||||
| 21 | 1 | $ffi->type( '(string,double)->void' => 'set_double_t' ); | |||||||||
| 22 | |||||||||||
| 23 | 2 | ▶ | $ffi->mangler(sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 2 | my($name) = @_; | |||||||||
| 25 | 2 | $name =~ s/^/ffi_platypus_constant__/; | |||||||||
| 26 | 2 | $name; | |||||||||
| 27 | 1 | }); | |||||||||
| 28 | |||||||||||
| 29 | 2 | ▶ | $ffi->attach( new => [ 'set_str_t', 'set_sint_t', 'set_uint_t', 'set_double_t' ] => 'ffi_platypus_constant_t' => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 2 | my($xsub, $class, $default_package) = @_; | |||||||||
| 31 | 6 | ▶ | my $f = $ffi->closure(sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 32 | 6 | my($name, $value) = @_; | |||||||||
| 33 | 6 | ▶ | if($name !~ /::/) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | { | ||||||||||
| 35 | 5 | $name = join('::', $default_package, $name); | |||||||||
| 36 | } | ||||||||||
| 37 | 6 | constant->import($name, $value); | |||||||||
| 38 | 2 | }); | |||||||||
| 39 | |||||||||||
| 40 | 2 | bless { | |||||||||
| 41 | ptr => $xsub->($f, $f, $f, $f), | ||||||||||
| 42 | f => $f, | ||||||||||
| 43 | }, $class; | ||||||||||
| 44 | 1 | }); | |||||||||
| 45 | |||||||||||
| 46 | 2 | ▶ | $ffi->attach( DESTROY => ['ffi_platypus_constant_t'] => 'void' => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 47 | 2 | my($xsub, $self) = @_; | |||||||||
| 48 | 2 | $xsub->($self->ptr); | |||||||||
| 49 | 1 | }); | |||||||||
| 50 | |||||||||||
| 51 | 3 | ▶ | sub ptr { shift->{ptr} } | ||||||||
|
Subroutine
ptr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 52 | |||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 1 | 1; | |||||||||
| 56 | |||||||||||
| 57 | __END__ | ||||||||||