FFI::P...losure(3pm)
π FFI::P...losure(3pm) β the whole vibe π
okay so real talk, this is the man page for FFI::Platypus::Closure, straight out of the User Contributed Perl Documentation (section 3pm, iykyk) β yes the header gets truncated to FFI::P...losure which is giving "my name got cut off on the group chat" energy π but she's fine, she's iconic.
β¨ NAME β¨
FFI::Platypus::Closure β the Platypus closure object, periodt π¦
π VERSION π
version 2.11 π
πΈ SYNOPSIS πΈ
create closure with OO interface
use FFI::Platypus::Closure;
my $closure = FFI::Platypus::Closure->new(sub { print "hello world\n" });
create closure from Platypus object
use FFI::Platypus 2.00;
my $ffi = FFI::Platypus->new( api => 2 );
my $closure = $ffi->closure(sub { print "hello world\n" });
use closure
$ffi->function(foo => ['()->void'] => 'void')->call($closure);
π¦ DESCRIPTION π¦
So this class is literally a Perl code reference that compiled code can call. That's the whole gig. When you make a closure object, you can hand it to any function that wants a function pointer β slay, versatility π .
But bestie, listen. Care needs to be taken with closures because compiled languages handle object lifetimes completely differently, and the vibes are not transferable. β οΈ You have to make sure that if the compiled code is gonna call a closure, that closure object is still in scope somewhere, or has been made sticky. Otherwise... you might get a segment violation or some other mysterious crash. Not cute. Not the moment. ππ
fr fr do not skip the lifetime talk. segfaults do not care about your feelings.
π§ CONSTRUCTOR π§
new
my $closure = FFI::Platypus::Closure->new($coderef);
Creates a shiny new closure object. $coderef must be a subroutine code reference β no exceptions, no substitutes, she's picky π
β METHODS β
call
$closure->call(@arguments);
$closure->(@arguments);
Calls the closure from Perl space. Also works if you just treat the closure object like a code reference β same energy, different syntax, both ate π«Ά
sticky
$closure->sticky;
Marks the closure sticky, meaning it won't be free'd even if all the references to the object fall out of scope. she's holding on and she's not letting go π
unstick
$closure->unstick;
Unmarks the closure as sticky. back to your regularly scheduled garbage collection β¨
π AUTHOR π
Author: Graham Ollis <plicease@cpan.org>
Contributors (the whole squad, no cap):
- Bakkiaraj Murugesan (bakkiaraj)
- Dylan Cali (calid)
- pipcet
- Zaki Mughal (zmughal)
- Fitz Elliott (felliott)
- Vickenty Fesunov (vyf)
- Gregor Herrmann (gregoa)
- Shlomi Fish (shlomif)
- Damyan Ivanov
- Ilya Pavlov (Ilya33)
- Petr PΓsaΕ (ppisar)
- Mohammad S Anwar (MANWAR)
- HΓ₯kon HΓ¦gland (hakonhagland, HAKONH)
- Meredith (merrilymeredith, MHOWARD)
- Diab Jerius (DJERIUS)
- Eric Brine (IKEGAMI)
- szTheory
- JosΓ© JoaquΓn Atria (JJATRIA)
- Pete Houston (openstrike, HOUSTON)
- Lukas Mai (MAUKE)
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2015-2022 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. π
π cute little sign-off: this gem was rendered byperl v5.42.3, dated2026-08-20, and it lives atFFI::P...losure(3pm)in the User Contributed Perl Documentation. go forth and make closures responsibly, bestie πβ¨
π¦ where this page comes from
- ubuntu stonking: libffi-platypus-perl 2.11-1build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms