| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Wasm::Wasmtime::ExportType; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 22 |  |  | 22 |  | 231497 | use strict; | 
|  | 22 |  |  |  |  | 66 |  | 
|  | 22 |  |  |  |  | 744 |  | 
| 4 | 22 |  |  | 22 |  | 124 | use warnings; | 
|  | 22 |  |  |  |  | 46 |  | 
|  | 22 |  |  |  |  | 524 |  | 
| 5 | 22 |  |  | 22 |  | 494 | use 5.008004; | 
|  | 22 |  |  |  |  | 95 |  | 
| 6 | 22 |  |  | 22 |  | 169 | use Ref::Util qw( is_blessed_ref ); | 
|  | 22 |  |  |  |  | 43 |  | 
|  | 22 |  |  |  |  | 1285 |  | 
| 7 | 22 |  |  | 22 |  | 632 | use Wasm::Wasmtime::FFI; | 
|  | 22 |  |  |  |  | 57 |  | 
|  | 22 |  |  |  |  | 2637 |  | 
| 8 | 22 |  |  | 22 |  | 680 | use Wasm::Wasmtime::ExternType; | 
|  | 22 |  |  |  |  | 62 |  | 
|  | 22 |  |  |  |  | 10484 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | # ABSTRACT: Wasmtime export type class | 
| 11 |  |  |  |  |  |  | our $VERSION = '0.22'; # VERSION | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | $ffi_prefix = 'wasm_exporttype_'; | 
| 15 |  |  |  |  |  |  | $ffi->load_custom_type('::PtrObject' => 'wasm_exporttype_t' => __PACKAGE__); | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | $ffi->attach( new => ['wasm_byte_vec_t*', 'opaque'] => 'wasm_exporttype_t' => sub { | 
| 19 |  |  |  |  |  |  | my $xsub = shift; | 
| 20 |  |  |  |  |  |  | my $class = shift; | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | # not sure this is actually useful... | 
| 23 |  |  |  |  |  |  | if(defined $_[1] && is_blessed_ref $_[1] && $_[1]->isa('Wasm::Wasmtime::ExternType')) | 
| 24 |  |  |  |  |  |  | { | 
| 25 |  |  |  |  |  |  | my $name = Wasm::Wasmtime::ByteVec->new(shift); | 
| 26 |  |  |  |  |  |  | my $externtype = shift; | 
| 27 |  |  |  |  |  |  | my $self = $xsub->($name, $externtype->{ptr}); | 
| 28 |  |  |  |  |  |  | $name->delete; | 
| 29 |  |  |  |  |  |  | return $self; | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  | else | 
| 32 |  |  |  |  |  |  | { | 
| 33 |  |  |  |  |  |  | my ($ptr,$owner) = @_; | 
| 34 |  |  |  |  |  |  | return bless { | 
| 35 |  |  |  |  |  |  | ptr   => $ptr, | 
| 36 |  |  |  |  |  |  | owner => $owner, | 
| 37 |  |  |  |  |  |  | }, $class; | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  | }); | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | $ffi->attach( name => ['wasm_exporttype_t'] => 'wasm_byte_vec_t*' => sub { | 
| 43 |  |  |  |  |  |  | my($xsub, $self) = @_; | 
| 44 |  |  |  |  |  |  | my $name = $xsub->($self); | 
| 45 |  |  |  |  |  |  | $name->get; | 
| 46 |  |  |  |  |  |  | }); | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | $ffi->attach( type => ['wasm_exporttype_t'] => 'wasm_externtype_t' => sub { | 
| 50 |  |  |  |  |  |  | my($xsub, $self) = @_; | 
| 51 |  |  |  |  |  |  | my $type = $xsub->($self); | 
| 52 |  |  |  |  |  |  | $type->{owner} = $self->{owner} || $self; | 
| 53 |  |  |  |  |  |  | $type; | 
| 54 |  |  |  |  |  |  | }); | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | sub to_string | 
| 58 |  |  |  |  |  |  | { | 
| 59 | 3 |  |  | 3 | 1 | 278 | my($self) = @_; | 
| 60 | 3 |  |  |  |  | 10 | my $kind   = $self->type->kind; | 
| 61 | 3 |  |  |  |  | 10 | $kind =~ s/type$//; | 
| 62 |  |  |  |  |  |  | # TODO: escape strings ? | 
| 63 | 3 |  |  |  |  | 14 | sprintf '(%s (export "%s") %s)', $kind, $self->name, $self->type->to_string; | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | _generate_destroy(); | 
| 67 |  |  |  |  |  |  | _generate_vec_class(); | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | 1; | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | __END__ |