| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package FFI::Platypus::Type::PtrObject; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 270470 | use strict; | 
|  | 1 |  |  |  |  | 11 |  | 
|  | 1 |  |  |  |  | 34 |  | 
| 4 | 1 |  |  | 1 |  | 6 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 35 |  | 
| 5 | 1 |  |  | 1 |  | 6 | use FFI::Platypus 1.11; | 
|  | 1 |  |  |  |  | 27 |  | 
|  | 1 |  |  |  |  | 27 |  | 
| 6 | 1 |  |  | 1 |  | 539 | use Ref::Util qw( is_blessed_hashref ); | 
|  | 1 |  |  |  |  | 1901 |  | 
|  | 1 |  |  |  |  | 95 |  | 
| 7 | 1 |  |  | 1 |  | 11 | use Carp (); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 16 |  | 
| 8 | 1 |  |  | 1 |  | 18 | use 5.008001; | 
|  | 1 |  |  |  |  | 4 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | # ABSTRACT: Platypus custom type for an object wrapped around an opaque pointer | 
| 11 |  |  |  |  |  |  | our $VERSION = '0.03'; # VERSION | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | push @FFI::Platypus::CARP_NOT, __PACKAGE__; | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | sub ffi_custom_type_api_1 | 
| 17 |  |  |  |  |  |  | { | 
| 18 | 3 |  |  | 3 | 0 | 9900 | my(undef, undef, $wrapper_class, $constructor) = @_; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 3 | 100 |  |  |  | 228 | Carp::croak("no class specified") unless defined $wrapper_class; | 
| 21 | 2 | 100 |  |  |  | 218 | Carp::croak("illegal class name: $wrapper_class") unless $wrapper_class =~ /^[A-Z_][0-9A-Z_]*(::[A-Z_][0-9A-Z_]*)*$/i; | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | $constructor ||= sub { | 
| 24 | 2 | 100 |  | 2 |  | 13 | defined $_[0] ? bless { ptr => $_[0] }, $wrapper_class : undef; | 
| 25 | 1 |  | 50 |  |  | 12 | }; | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | return { | 
| 28 |  |  |  |  |  |  | native_type    => 'opaque', | 
| 29 |  |  |  |  |  |  | perl_to_native => sub { | 
| 30 | 8 | 100 | 100 | 8 |  | 6014 | Carp::croak("argument is not a $wrapper_class") unless is_blessed_hashref($_[0]) && $_[0]->isa($wrapper_class); | 
| 31 | 6 |  |  |  |  | 16 | my $ptr = $_[0]->{ptr}; | 
| 32 | 6 | 100 |  |  |  | 172 | Carp::croak("pointer for $wrapper_class went away") unless defined $ptr; | 
| 33 | 5 |  |  |  |  | 41 | $ptr; | 
| 34 |  |  |  |  |  |  | }, | 
| 35 | 1 |  |  |  |  | 10 | native_to_perl => $constructor, | 
| 36 |  |  |  |  |  |  | }; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | 1; | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | __END__ |