🌻 📖 Wasm::Wasmtime::Module

NAME

Wasm::Wasmtime::Module - Wasmtime module class

VERSION

version 0.24

SYNOPSIS

 use Wasm::Wasmtime;
 
 my $module = Wasm::Wasmtime::Module->new( wat => '(module)' );

DESCRIPTION

WARNING: WebAssembly and Wasmtime are a moving target and the interface for these modules is under active development. Use with caution.

This class represents a WebAssembly module.

CONSTRUCTORS

new

 my $module = Wasm::Wasmtime::Module->new(
   $engine,       # Wasm::Wasmtime::Engine (optional)
   wat => $wat,   # WebAssembly Text
 );
 my $module = Wasm::Wasmtime::Module->new(
   $engine,       # Wasm::Wasmtime::Engine (optional)
   wasm => $wasm, # WebAssembly binary
 );
 my $module = Wasm::Wasmtime::Module->new(
   $engine,       # Wasm::Wasmtime::Engine (optional)
   file => $path, # Filename containing WebAssembly binary (.wasm) or WebAssembly Text (.wat)
 );

Create a new WebAssembly module object. You must provide either WebAssembly Text (WAT), WebAssembly binary (Wasm), or a filename of a file that contains WebAssembly binary (Wasm) or text (Wat). If the optional Wasm::Wasmtime::Engine object is not provided one will be created for you. A Wasm::Wasmtime::Store may be passed instead of an engine, in which case its engine is used.

deserialize

 my $module = Wasm::Wasmtime::Module->deserialize(
   $engine,       # Wasm::Wasmtime::Engine (optional)
   $serialized,   # serialized module
 );

Build a module from serialized data. The serialized data can be gotten from the serialize method documented below.

METHODS

validate

 my($ok, $message) = Wasm::Wasmtime::Module->validate(
   $engine,       # Wasm::Wasmtime::Engine (optional)
   wat => $wat,   # or wasm => $wasm, or file => $path
 );

Takes the same arguments as new, but validates the module without creating a module object.

exports

 my $exports = $module->exports;

Returns a Wasm::Wasmtime::Module::Exports object that can be used to query the module exports.

imports

 my $imports = $module->imports;

Returns a list of Wasm::Wasmtime::ImportType objects for the objects imported by the WebAssembly module.

serialize

 my $serialized = $module->serialize;

This function serializes compiled module artifacts as blob data. This data can be reconstituted with the deserialize constructor method documented above.

engine

 my $engine = $module->engine;

Returns the Wasm::Wasmtime::Engine object used by this module.

to_string

 my $string = $module->to_string;

Converts the module imports and exports into a string for diagnostics.

SEE ALSO

Wasm
Wasm::Wasmtime

AUTHOR

Graham Ollis <plicease@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2020-2026 by Graham Ollis.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.